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

Fill _kwargs attribute #6

Closed
Strady opened this issue Dec 8, 2024 · 2 comments
Closed

Fill _kwargs attribute #6

Strady opened this issue Dec 8, 2024 · 2 comments

Comments

@Strady
Copy link

Strady commented Dec 8, 2024

Problem description

When the labels method is called a new instance of Summary is created inside and this new instance uses default values for invariants, max_age_seconds and age_buckets instead of those were passed for the "parent" Summary instance initialization.

Here is a snippet from the labels method where new Summary instance is created. self._kwargs here is empty, so no invariants, max_age_seconds and age_buckets are passed to __init__:

if labelvalues not in self._metrics:
    self._metrics[labelvalues] = self.__class__(
        self._name,
        documentation=self._documentation,
        labelnames=self._labelnames,
        unit=self._unit,
        _labelvalues=labelvalues,
        **self._kwargs
    )

Example

s = Summary(
    "request_latency_seconds", 
    "Description of summary",
    invariants=((0.95, 0.005), (0.99, 0.001))
)
s.labels(method="GET", endpoint="/profile").observe(1.2)
s.labels(method="POST", endpoint="/login").observe(3.4)

In this example both observations are done with the DEFAULT_INVARIANTS.

Solution

The way it's handled for example in the Histogram class is just to put buckets in self._kwargs after the super class initialization. Apparently for the Summary the same should be done for the invariants, max_age_seconds and age_buckets:

def __init__(
    ...
) -> None:
    self._invariants = invariants
    self._max_age_seconds = max_age_seconds
    self._age_buckets = age_buckets
    self._lock = Lock()
    super().__init__(
        name,
        documentation,
        labelnames=labelnames,
        namespace=namespace,
        subsystem=subsystem,
        unit=unit,
        registry=registry,
        _labelvalues=_labelvalues,
    )
    self._kwargs['invariants'] = invariants
    self._kwargs['max_age_seconds'] = max_age_seconds
    self._kwargs['age_buckets'] = age_buckets
@Strady Strady mentioned this issue Dec 8, 2024
@antonmyronyuk
Copy link
Collaborator

Thank you for contribution!

Released: https://pypi.org/project/prometheus-summary/0.1.3/

@Strady
Copy link
Author

Strady commented Dec 8, 2024

Thank you for contribution!

Released: https://pypi.org/project/prometheus-summary/0.1.3/

Awesome! Thanks for the fast merge

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

No branches or pull requests

2 participants