client_golang icon indicating copy to clipboard operation
client_golang copied to clipboard

was collected before with the same name and label values Error when using 'NewMetricWithTimestamp'

Open machadovilaca opened this issue 3 years ago • 0 comments

This might not even be considered a bug, but I think this is a very annoying behavior.

When using NewMetricWithTimestamp in a Collector as in:

// {
//     Name: "metric_test_1", Description: "metric_test_1 description",
//     Values: [ { value: 1,  timestamp: 1663713926158 }, { value: 2,  timestamp: 1663713937491 } ] 
// } 

desc := prometheus.NewDesc(m.Name, m.Description, nil, nil)

for _, value := range m.Values {
  ch <- prometheus.NewMetricWithTimestamp(
    value.timestamp,
    prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, value.value),
  )
}

The client is running checkMetricConsistency for each of the pushed metrics which is throwing the following error

...
* collected metric "metric_test_1" { gauge:<value:2 > timestamp_ms:1663713937491 } was collected before with the same name and label values
...

I think the validation should be aware of the metrics timestamps and not throw an error in this case because the metrics belong to different point in times, and there are use cases where it makes sense to allow multiple ones to be pushed in the same scrape call.

machadovilaca avatar Sep 20 '22 22:09 machadovilaca