Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/prometheus-receiver-fix-stalenss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
component: receiver/prometheus

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix missing staleness tracking leading to missing no recorded value data points.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [43893]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
2 changes: 1 addition & 1 deletion exporter/prometheusexporter/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestEndToEndSummarySupport(t *testing.T) {
`test_scrape_samples_scraped.instance="127.0.0.1:.*",job="otel-collector",otel_scope_name=\"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver\",otel_scope_schema_url=\"\",otel_scope_version=\"latest\". 13 .*`,
`. HELP test_scrape_series_added The approximate number of new series in this scrape`,
`. TYPE test_scrape_series_added gauge`,
`test_scrape_series_added.instance="127.0.0.1:.*",job="otel-collector",otel_scope_name=\"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver\",otel_scope_schema_url=\"\",otel_scope_version=\"latest\". 13 .*`,
`test_scrape_series_added.instance="127.0.0.1:.*",job="otel-collector",otel_scope_name=\"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver\",otel_scope_schema_url=\"\",otel_scope_version=\"latest\". (0|13) .*`,

@krajorama krajorama Oct 31, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: now we correctly tracking what series were added to "storage", i.e. successfully processed by the receiver. Which means that the number of series added is only 13 on the first scrape. Debug printf:

Running tool: /home/krajo/opt/go/bin/go test -timeout 30s -tags requires_docker,stringlabels -run ^TestEndToEndSummarySupport$ github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter -timeout=5m

number of series added: 13
number of series added: 0
number of series added: 0
number of series added: 0
number of series added: 0
number of series added: 0
number of series added: 0
number of series added: 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh

`. HELP test_up The scraping was successful`,
`. TYPE test_up gauge`,
`test_up.instance="127.0.0.1:.*",job="otel-collector",otel_scope_name=\"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver\",otel_scope_schema_url=\"\",otel_scope_version=\"latest\". 1 .*`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
// Prometheus remotewrite exporter that staleness markers are emitted per timeseries.
// See https://github.com/open-telemetry/opentelemetry-collector/issues/3413
func TestStalenessMarkersEndToEnd(t *testing.T) {
t.Skip("Skipping test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/43893 is resolved")
if testing.Short() {
t.Skip("This test can take a long time")
}
Expand Down
14 changes: 12 additions & 2 deletions receiver/prometheusreceiver/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,14 @@ func (t *transaction) Append(_ storage.SeriesRef, ls labels.Labels, atMs int64,
err = curMF.addSeries(seriesRef, metricName, ls, atMs, val)
if err != nil {
t.logger.Warn("failed to add datapoint", zap.Error(err), zap.String("metric_name", metricName), zap.Any("labels", ls))
// never return errors, as that fails the while scrape
// return ref==0 indicating that the series was not added
return 0, nil
}

return 0, nil // never return errors, as that fails the whole scrape
// never return errors, as that fails the whole scrape
// return ref==1 indicating that the series was added and needs staleness tracking
return 1, nil
}

// detectAndStoreNativeHistogramStaleness returns true if it detects
Expand Down Expand Up @@ -350,9 +355,14 @@ func (t *transaction) AppendHistogram(_ storage.SeriesRef, ls labels.Labels, atM
}
if err != nil {
t.logger.Warn("failed to add histogram datapoint", zap.Error(err), zap.String("metric_name", metricName), zap.Any("labels", ls))
// never return errors, as that fails the while scrape
// return ref==0 indicating that the series was not added
return 0, nil
}

return 0, nil // never return errors, as that fails the whole scrape
// never return errors, as that fails the whole scrape
// return ref==1 indicating that the series was added and needs staleness tracking
return 1, nil
}

func (t *transaction) AppendCTZeroSample(_ storage.SeriesRef, ls labels.Labels, atMs, ctMs int64) (storage.SeriesRef, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ var totalScrapes = 10

// TestStaleNaNs validates that staleness marker gets generated when the timeseries is no longer present
func TestStaleNaNs(t *testing.T) {
t.Skip("Skipping test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/43893 is resolved")
var mockResponses []mockPrometheusResponse
for i := range totalScrapes {
if i%2 == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ func TestNativeVsClassicHistogramScrapeViaProtobuf(t *testing.T) {
}

func TestStaleExponentialHistogram(t *testing.T) {
t.Skip("Skipping test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/43893 is resolved")
mf := &dto.MetricFamily{
Name: "test_counter",
Type: dto.MetricType_COUNTER,
Expand Down