Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/metrics_tags.py: 100.00%
12 statements
« prev ^ index » next coverage.py v7.4.1, created at 2025-07-10 13:10 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2025-07-10 13:10 +0000
1# Copyright (C) 2024 Bloomberg LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# <http://www.apache.org/licenses/LICENSE-2.0>
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
16def tag_blob_age(age: float) -> str:
17 # Range mapping ms to a range of minutes
18 age_range_upper_limit = [
19 (3600000, "0_TO_60"),
20 (21600000, "60_TO_360"),
21 (86400000, "360_TO_1440"),
22 (172800000, "1440_TO_2880"),
23 (604800000, "2880_TO_10080"),
24 (1209600000, "10080_TO_20160"),
25 (2592000000, "20160_TO_43200"),
26 ]
27 for limit, age_range in age_range_upper_limit:
28 if age < limit:
29 return age_range
30 return "43200_AND_ABOVE"
33def tag_blob_size(size: float) -> str:
34 # Range in bytes
35 size_range_upper_limit = [
36 (2000, "0_TO_2000"),
37 (4000, "2000_TO_4000"),
38 (10000, "4000_TO_10000"),
39 (100000, "10000_TO_100000"),
40 (1000000, "100000_TO_1000000"),
41 (10000000, "1000000_TO_10000000"),
42 (100000000, "10000000_TO_100000000"),
43 (1000000000, "100000000_TO_1000000000"),
44 (2000000000, "1000000000_TO_2000000000"),
45 ]
46 for limit, size_range in size_range_upper_limit:
47 if size < limit:
48 return size_range
49 return "2000000000_AND_ABOVE"