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

INVESTIGATE: Setting build info with init can cause duplicate build_info gauges that break autometrics queries #88

Open
brettimus opened this issue Sep 11, 2023 · 1 comment

Comments

@brettimus
Copy link
Collaborator

When you set, e.g., a version via init, then I'm pretty sure we end up adding two gauges, one with a version label and one without a version label. These will both be set within a short period of time.

The result is that our group left query that joins build info to function metrics will cause a 422 from prometheus, with an error like:

Error executing query: 
found duplicate series for the match group {instance="localhost:8082", job="am_0"} on the right hand-side of the operation: 

[
  {__name__="build_info", instance="localhost:8082", job="am_0", service_name="autometrics", version="0.0.1"},
  {__name__="build_info", instance="localhost:8082", job="am_0", service_name="autometrics"}
];

many-to-many matching not allowed: matching labels must be unique on one side

The culprit is likely:

def default_tracker():
    """Setup the default tracker."""
    preferred_tracker = get_tracker_type()
    return init_tracker(preferred_tracker)


tracker: TrackMetrics = default_tracker()

We initialize a tracker out of the box. When a user calls init, they effectively "re-initialize" the tracker with new build information, which sets a new build info gauge.

Need to confirm though.

@brettimus
Copy link
Collaborator Author

So this might end up being pretty edge-case-y.

The original scenario that reproduced this for me was:

  • Setting the AUTOMETRICS_TRACKER=prometheus enviornment variable
  • Calling init with the build information

My working theory is that this issue will only occur if you call init with a version, without also changing the tracker.

In such a case, the tracker would be recording two separate build_info metrics within a short period of time (less than the interval we use in our queries)

It begs the question: Could we use a concept of a "clearmode" internally on the build_info gauge?

Basically, last-in-wins for build information. If you record a build_info metric, it will remove any other previously recorded build_info metrics that your app is exporting.

This could pose other issues (I haven't fully thought this through yet), but it would make a stronger guard at the library level that against corrupting our build info queries.

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

1 participant