diff --git a/CHANGELOG.md b/CHANGELOG.md index 263a66310853..b937433b83d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - `nginxreceiver`: Include nginxreceiver in components (#9572) - `pkg/translator/prometheusremotewrite`: Fix data race when used with other exporters (#9736) - `examples/demo`: fix baggage not work in trace demo app. (#9418) +- `prometheusreceiver`: Handle the condition where `up` metric value is NaN (#9253) ## v0.50.0 diff --git a/receiver/prometheusreceiver/internal/otlp_metricsbuilder.go b/receiver/prometheusreceiver/internal/otlp_metricsbuilder.go index 346173f34611..06d699d855f1 100644 --- a/receiver/prometheusreceiver/internal/otlp_metricsbuilder.go +++ b/receiver/prometheusreceiver/internal/otlp_metricsbuilder.go @@ -23,6 +23,7 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/textparse" + "github.com/prometheus/prometheus/model/value" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" ) @@ -154,7 +155,8 @@ func (b *metricBuilderPdata) AddDataPoint(ls labels.Labels, t int64, v float64) lm := ls.Map() // See https://www.prometheus.io/docs/concepts/jobs_instances/#automatically-generated-labels-and-time-series // up: 1 if the instance is healthy, i.e. reachable, or 0 if the scrape failed. - if metricName == scrapeUpMetricName && v != 1.0 { + // But it can also be a staleNaN, which is inserted when the target goes away. + if metricName == scrapeUpMetricName && v != 1.0 && !value.IsStaleNaN(v) { if v == 0.0 { b.logger.Warn("Failed to scrape Prometheus endpoint", zap.Int64("scrape_timestamp", t),