Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ability to add labels with constant values #339

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

DanArmor
Copy link
Contributor

@DanArmor DanArmor commented Dec 5, 2024

Example: we have application with different environments, each having its own exporter. We want to distinguish metrics by environment by label, not by metric prefix. So we need to provide exporter with an ability to attach custom labels to metrics.

Implemented as cli arg --static-label, that can be provided multiple times in format --static-label key=value

Example: python cli.py --broker-url=redis://127.0.0.1:6379 --static-label application=my-application-name --static-label environment=staging

Here is the result:
image_2024-12-05_13-28-19

Code changes:

  • New cli arg
  • In the code where metrics are defined, there are *self.static_label_keys at the end to unpack provided static labels names
  • In the code where we provide labels for metrics now there are **self.static_label, which unpack static labels and their values.

@danihodovic
Copy link
Owner

mildly related #323

@danihodovic
Copy link
Owner

Can you add tests?

@DanArmor
Copy link
Contributor Author

DanArmor commented Dec 5, 2024

Can you add tests?

Yes, I will add them soon and mention you when I'm done

@DanArmor
Copy link
Contributor Author

DanArmor commented Dec 6, 2024

@danihodovic I've added tests

  • To test static labels we need to create new exporter instance with static labels provided at creation (to not pollute already existing tests by providing static labels to existing exporter, used in all other tests)
  • Common exporter configuration separated into exporter_cfg_defaults fixture, used in exporter_instance and exporter_instance_static_labels fixtures
  • To test static lables I've made test_integration_static_labels by duplicating of test_integration with changes to labels checks to test static labels
  • Disabled too-many-statements check for test_integration_static_labels, because it's complaining about overstepping statement limit by 1 statement (51/50)

@danihodovic danihodovic merged commit 5e52531 into danihodovic:master Dec 9, 2024
6 checks passed
@danihodovic
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants