8000 OTLP receiver: Generate `target_info` samples between the earliest and latest samples per resource by aknuds1 · Pull Request #16737 · prometheus/prometheus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

OTLP receiver: Generate target_info samples between the earliest and latest samples per resource #16737

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aknuds1
Copy link
Contributor
@aknuds1 aknuds1 commented Jun 17, 2025

Modify the OTLP receiver to generate target_info samples starting at the earliest and ending at the latest samples per resource, instead of only one for the latest timestamp. Between those samples, one sample is generated every lookback delta/2 timestamps. The idea behind generating target_info samples spaced lookback delta/2 apart is to ensure that target_info is found for every connected time series sample generated from the same request.

The motivation behind this fix is that I realized when debugging strange info PromQL function behaviour that the reason was that target_info started one minute later than the time series it was being joined with (by info). See Grafana Mimir issue for reference.

@aknuds1 aknuds1 changed the title OTLP receiver: Generate target_info samples between the earliest and latest samples per resource OTLP receiver: Generate target_info samples between the earliest and latest samples per resource Jun 17, 2025
@aknuds1 aknuds1 force-pushed the arve/generate-target-info branch from a9795be to 3d4a41a Compare June 17, 2025 10:52
@aknuds1 aknuds1 requested a review from beorn7 June 17, 2025 10:59
@aknuds1 aknuds1 force-pushed the arve/generate-target-info branch 7 times, most recently from 1bc16ac to 13d83d2 Compare June 20, 2025 10:06
@aknuds1 aknuds1 marked this pull request as ready for review June 20, 2025 10:07
@aknuds1 aknuds1 requested review from Copilot and removed request for tomwilkie and cstyan June 20, 2025 10:08
Copilot

This comment was marked as outdated.

@aknuds1 aknuds1 force-pushed the arve/generate-target-info branch from 13d83d2 to 26e5dcb Compare June 20, 2025 10:34
@aknuds1 aknuds1 requested a review from Copilot June 20, 2025 10:34
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for generating multiple target_info samples between the earliest and latest OTLP metric samples for each resource, spaced at half the lookback delta.

  • Introduce LookbackDelta configuration throughout handlers and API.
  • Track earliest and latest timestamps per resource in the OTLP-to-remote-write converter.
  • Generate a target_info time series sample at every lookbackDelta/2 interval plus the final timestamp.
  • Update tests to cover the multi-sample target_info behavior and bump changelog.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
web/web.go Pass LookbackDelta into NewAPI
web/api/v1/errors_test.go Add lookbackDelta parameter to test helper invocation
web/api/v1/api.go Wire lookbackDelta through to OTLP write handler
storage/remote/write_handler.go Extend OTLPOptions and exporter to carry lookbackDelta
storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go Add earliest/latest timestamp tracking in converter
storage/remote/otlptranslator/prometheusremotewrite/helper.go Implement multi-sample logic in addResourceTargetInfo
storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw_test.go New test for spaced target_info samples
CHANGELOG.md Document the bugfix
Comments suppressed due to low confidence (3)

storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go:55

  • [nitpick] Comment should start with the field name LookbackDelta to follow Go doc conventions, e.g. // LookbackDelta is the PromQL engine lookback delta used for target_info spacing.
	// Lookback delta is the PromQL engine lookback delta.

storage/remote/otlptranslator/prometheusremotewrite/helper.go:658

  • [nitpick] The variable name ts is ambiguous (could be confused with timestamp). Consider renaming to series or targetSeries for clarity.
	ts, _ := converter.getOrCreateTimeSeries(labels)

storage/remote/otlptranslator/prometheusremotewrite/helper.go:438

  • The calls to min and max rely on helper functions that aren’t shown here. Ensure that min(a,b) and max(a,b) are defined for pcommon.Timestamp, otherwise these will fail to compile.
			minTimestamp = min(minTimestamp, ts)

@aknuds1 aknuds1 force-pushed the arve/generate-target-info branch 2 times, most recently from e19cbd6 to 4567c6d Compare June 20, 2025 12:16
…latest samples per resource

Modify the OTLP receiver to generate target_info samples between the earliest
and latest samples per resource instead of only one for the latest timestamp.
The samples are spaced lookback delta/2 apart.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1 aknuds1 force-pushed the arve/generate-target-info branch from 4567c6d to d5761d7 Compare June 20, 2025 13:10
Copy link
Member
@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Why do we need a sample coinciding with the latest timestamp?

Having one at the earliest timestamp and then one at half the lookback delta until we reach or exceed the latest timestamp should be enough, shouldn't it?

@aknuds1
Copy link
Contributor Author
aknuds1 commented Jun 25, 2025

Why do we need a sample coinciding with the latest timestamp?

Having one at the earliest timestamp and then one at half the lookback delta until we reach or exceed the latest timestamp should be enough, shouldn't it?

@beorn7 My algorithm doesn't exceed the latest timestamp, it ends exactly at the latest timestamp. Is there any benefit to modify it, so it instead potentially exceeds the latest timestamp? I don't see it at least.

@aknuds1 aknuds1 requested a review from beorn7 June 25, 2025 13:19
@beorn7
Copy link
Member
beorn7 commented Jun 25, 2025

What I mean is to not add a sample that exceed the latest timestamp, but also don't add any sample that doesn't match the lookbackdelta/2 repeating pattern.

Just add one at the beginning of the range, and then every lookbackdelta/2 duration, until you have added the last sample before the end of the range.

@aknuds1
Copy link
Contributor Author
aknuds1 commented Jun 25, 2025

What I mean is to not add a sample that exceed the latest timestamp, but also don't add any sample that doesn't match the lookbackdelta/2 repeating pattern.

@beorn7 Isn't the problem with this approach that you can miss the latest target_info sample when doing a join or info function query, if you have to look back more than lookback delta/2 for the latest corresponding non-inf 8000 o sample?

@beorn7
Copy link
Member
beorn7 commented Jun 25, 2025

Oh yes, you are right. Now I got it.

(Maybe it should be explained in a way so that even people like me will understand it. :)

So this looks plausible to me, then. I'll leave the codelevel review to the OTLP receiver experts.

@aknuds1
Copy link
Contributor Author
aknuds1 commented Jun 25, 2025

(Maybe it should be explained in a way so that even people like me will understand it. :)

@beorn7 Hahahaha! :) I can update the PR description to be explicit about this, thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0