pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/DataDog/datadogpy/pull/916

ets/global-a469e846088cc1bf.css" /> fix: pass missing parameter in `MaxSampleMetricContexts` by KowalskiThomas · Pull Request #916 · DataDog/datadogpy · GitHub
Skip to content

fix: pass missing parameter in MaxSampleMetricContexts#916

Open
KowalskiThomas wants to merge 2 commits intomasterfrom
kowalski/fix-pass-missing-parameter-in-maxsamplemetriccontexts
Open

fix: pass missing parameter in MaxSampleMetricContexts#916
KowalskiThomas wants to merge 2 commits intomasterfrom
kowalski/fix-pass-missing-parameter-in-maxsamplemetriccontexts

Conversation

@KowalskiThomas
Copy link
Contributor

@KowalskiThomas KowalskiThomas commented Mar 6, 2026

What does this PR do?

When creating a new metric context, the rate parameter is currently not passed to the metric constructor. I believe that means sampling rates for histogram/distribution/timing metrics are ignored. It also means that the parameters we did pass to the constructor were shifted by one position, making them do not what we wanted.

Description of the Change

This adds forwarding of the rate parameter to the constructor we call, and adds a unit test to ensure forwarding is done properly.

Possible Drawbacks

I don't see any.

Reproducer

This is as simple as I could make it -- if we pass parameters properly, the "max samples per context" limiting should work.

from unittest.mock import patch
from datadog.dogstatsd.max_sample_metric import HistogramMetric
from datadog.dogstatsd.max_sample_metric_context import MaxSampleMetricContexts

MAX_SAMPLES = 10

with patch("datadog.dogstatsd.max_sample_metric_context.random.random", return_value=0.0):
    ctx = MaxSampleMetricContexts(HistogramMetric)
    for _ in range(1000):
        ctx.sample("m", 1.0, ["t:v"], 0.5, "key", max_samples_per_context=MAX_SAMPLES)

metric = ctx.values["key"]
print(f"buffer size: {len(metric.data)} (expected: {MAX_SAMPLES})")
assert len(metric.data) == MAX_SAMPLES, f"BUG: buffer grew to {len(metric.data)}"

Additional Notes

❓ I think this problem is one that would typically be detected and prevented by even basic static typing / static correctness checking. Has anyone ever looked into this, and would you be opposed to (me) adding some? Not necessarily a full blown typing of everything, but at least some basics.

@KowalskiThomas KowalskiThomas added kind/bug Bug related issue changelog/Fixed Fixed features results into a bug fix version bump labels Mar 6, 2026
@KowalskiThomas KowalskiThomas changed the title fix: pass missing parameter in MaxSampleMetricContexts fix: pass missing parameter in MaxSampleMetricContexts Mar 6, 2026
@KowalskiThomas KowalskiThomas force-pushed the kowalski/fix-pass-missing-parameter-in-maxsamplemetriccontexts branch from f5106c8 to 314ba32 Compare March 9, 2026 15:04
@KowalskiThomas KowalskiThomas marked this pull request as ready for review March 10, 2026 09:06
@KowalskiThomas KowalskiThomas requested review from a team as code owners March 10, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Fixed Fixed features results into a bug fix version bump kind/bug Bug related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy