Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

collected metric ... was collected before with the same name and label values #636

Open

Description

@MrRothstein

I'm saw this error with rc48. It went away after restart, and when I looked at the source of the metric in question (from /json), I see two sources from the same program (lines 1 and 11). The program is 9 lines long... Is it possible reloading mtail using "kill -SIGHUP $(pidofproc $PROGNAME)" caused it to load the program twice somehow?

Activity

  1. jaqx0r commented on Apr 14, 2022

    @jaqx0r
    Contributor
  2. MrRothstein commented on Apr 14, 2022

    @MrRothstein
    Author

    I think I see what happened. The previous version of the program did declare the same variable on line 11. So, the following appears to have happened:

    1. A program declares a counter on line 11
    2. Metrics are generated with the counter
    3. A program is updated with a version where the counter is declared on line 1
    4. Mtail is reloaded, but metrics still include the counter sourced from line 11
    5. Metrics are generated with the counter on line 1
    6. Prometheus receives 500 response trying to scrape "metric ... was collected before with the same name and label values"

    Not sure if this is correct or the expected behavior

  3. jaqx0r commented on Apr 14, 2022

    @jaqx0r
    Contributor
  4. MrRothstein commented on Apr 15, 2022

    @MrRothstein
    Author

    This fails (adds two metrics):

    func TestSameMetricWithDifferentSourcePositions(t *testing.T) {
     expectedMetrics := 1
     s := NewStore()
     firstPositionMetric := NewMetric("foo", "prog", Counter, Int)
     firstPositionMetric.SetSource("some_source.mtail:1:9-50")
     _ = s.Add(firstPositionMetric)
    
     secondPositionMetric := NewMetric("foo", "prog", Counter, Int)
     secondPositionMetric.SetSource("some_source.mtail:2:9-50")
     _ = s.Add(secondPositionMetric)
     glog.Infof("Store: %v", s)
     if len(s.Metrics["foo"]) != expectedMetrics {
         t.Fatalf("should not add metric with different source position: %v", s)
     }
    }
    

    It looks like the dupe check is skipped for metrics where the sources are different, but the check does not differentiate between the program being different or only the position:

    if v.Source != m.Source {

    I don't see a "FromString" type function available for Position and I'm not completely sure if the source and position represent the same thing. If this is the issue, would it make sense to convert Source in Metric from string to Position and compare only the file name during the dupe check?

  5. added
    bug
    mtail-Language/VM
    on Jan 1, 2023
  6. added a commit that references this issue on May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmtail-Language/VM

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions