Coverage for aiopromql/utils.py: 100%

1 def make_label_string(negate_keys=None, **labels) -> str:

2 """

3 Return PromQL label selector string from provided labels.

4

5 negate_keys: iterable of keys whose match should be negated (using !=).

6 labels: key=value pairs for labels.

7 """

8 negate_keys = set(negate_keys or [])

9 # Filter out None values

10 filtered = {k: v for k, v in labels.items() if v is not None}

11 if not filtered:

12 return ""

13 parts = []

14 for k, v in filtered.items():

15 op = "!=" if k in negate_keys else "="

16 parts.append(f'{k}{op}"{v}"')

17 return "{" + ",".join(parts) + "}"