Skip to content

Conversation

aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Aug 29, 2024

Modify the OTLP receiver to, if the --created-timestamp-zero-ingestion feature flag is true, convert data point start timestamps to Prometheus zero samples 1 millisecond before the sample itself, iff the following is true: The OTel start timestamp is greater than zero and equal to the data point timestamp.

I'm also adding tests, copied from https://github.com/open-telemetry/opentelemetry-collector-contrib, with attribution.

Fixes #14600.

Copy link
Member

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

Code looks very reasonable; couple of nits on style.

return
}
if value != 0 && startTs > 0 && startTs == ts {
// NB: We currently handle only start timestamps which are the same as the data point timestamp.
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this phrasing; I would say we handle all start timestamps, as long as we see the first point.
Suggest linking to the umbrella issue for people wanting more explanation, and leave it out of the code.

Copy link
Contributor Author

@aknuds1 aknuds1 Aug 29, 2024

Choose a reason for hiding this comment

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

@bboreham are you suggesting to make the comment only link to the umbrella issue instead? Uncertain if you mean to put the umbrella issue in the comment or in the PR description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put the issue link in the comment, please let me know if you had something else in mind.

ts := c.addSample(infBucket, infLabels)

bucketBounds = append(bucketBounds, bucketBoundsData{ts: ts, bound: math.Inf(1)})
c.addExemplars(pt, bucketBounds)

startTimestamp := pt.StartTimestamp()
if settings.ExportCreatedMetric && startTimestamp != 0 {
otelStart := pt.StartTimestamp()
Copy link
Member

Choose a reason for hiding this comment

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

Not in love with this name; everything around here is Otel.
AFAICS the difference is that this one is in nanoseconds while startTimestamp is in milliseconds; perhaps that could be used in the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed startTimestamp to startTimestampMs and otelStart to startTimestampNs. PTAL.

@aknuds1 aknuds1 force-pushed the arve/otlp-starttime branch from 5c6da56 to cbbaf41 Compare August 29, 2024 11:12
@aknuds1 aknuds1 requested a review from bboreham August 29, 2024 11:39
@@ -540,6 +549,18 @@ func (c *PrometheusConverter) addTimeSeriesIfNeeded(lbls []prompb.Label, startTi
}
}

// handleStartTime adds a zero sample 1 millisecond before ts iff startTs == ts.
Copy link
Member

Choose a reason for hiding this comment

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

It might be worth mentioning that we're doing this because PRWv1 doesn't support Created Timestamps.

Once we migrate the translation layer to the PRWv2 Protocol, this won't be needed and we'll just let the PRWv2 handler take care of StartTimeUnixNano

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the doc comment, PTAL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed the commit altering the doc comment, had somehow omitted to push it earlier 🤦

@aknuds1 aknuds1 requested a review from ArthurSens August 29, 2024 13:07
Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

@bwplotka do you mind giving a review here as well? It would be nice to get some eyes from someone outside Grafana

@aknuds1 aknuds1 force-pushed the arve/otlp-starttime branch from c6656a6 to 79b16d9 Compare August 29, 2024 14:18
@aknuds1 aknuds1 marked this pull request as ready for review August 29, 2024 14:19
@aknuds1 aknuds1 changed the title WIP: OTLP receiver: Convert start timestamps to Prometheus zero samples OTLP receiver: Convert start timestamps to Prometheus zero samples Aug 29, 2024
@aknuds1 aknuds1 requested a review from ArthurSens August 29, 2024 14:19
@aknuds1
Copy link
Contributor Author

aknuds1 commented Aug 29, 2024

If reviewers prefer, I can factor out the added tests into another PR (dependency of this one).

@aknuds1 aknuds1 marked this pull request as draft August 29, 2024 15:47
Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

LGTM, I just feel like we need to document our approach of subtracting 1 milisecond somewhere. It's an important detail to reason when deciding to use Pull or Push

Comment on lines +553 to +576
// The reason for doing this is that PRW v1 doesn't support Created Timestamps. After switching to PRW v2's direct CT support,
// make use of its direct support fort Created Timestamps instead.
Copy link
Member

@ArthurSens ArthurSens Aug 29, 2024

Choose a reason for hiding this comment

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

Suggested change
// The reason for doing this is that PRW v1 doesn't support Created Timestamps. After switching to PRW v2's direct CT support,
// make use of its direct support fort Created Timestamps instead.
// We append `StartTimeUnixNano` as an extra zero sample because PRWv1 doesn't have support for Created Timestamps. Once the OTLP translation layer migrates to PRWv2, we can let the PRWv2 handler decide what to do with its Created Timestamp and this method won't be necessary.

Copy link
Contributor Author

@aknuds1 aknuds1 Aug 31, 2024

Choose a reason for hiding this comment

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

this method won't be necessary.

Isn't it possible that this method will still be necessary for converting to PRW v2's created timestamp representation? I can't say for sure what the PRW v2 conversion code will look like.

Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

Oh I just realized this isn't used anymore :P

@aknuds1 aknuds1 requested a review from ArthurSens August 30, 2024 08:34
@jesusvazquez
Copy link
Member

I rebased the PR with main changes that included some of the tests files also present here resulting in a much smaller PR for review 👍

@aknuds1 aknuds1 force-pushed the arve/otlp-starttime branch from 5f1c411 to 6fd88cc Compare September 3, 2024 08:13
@aknuds1 aknuds1 marked this pull request as ready for review September 3, 2024 08:13
@aknuds1
Copy link
Contributor Author

aknuds1 commented Sep 3, 2024

Rebased the PR on main, and marked ready for review.

aknuds1 and others added 8 commits September 11, 2024 17:14
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@bboreham
Copy link
Member

bboreham commented Dec 3, 2024

Hi, I believe things moved on a bit in the fork we are using to test this out.
For instance the "subtract 1 millisecond" turned out to be wrong.
So, this PR should be updated again from the fork.

@github-actions github-actions bot removed the stale label Dec 3, 2024
@bboreham
Copy link
Member

bboreham commented Jul 8, 2025

Hello from the bug-scrub! @aknuds1 do you think you will get back to this?

I believe @krajorama was also looking at Created Timestamps.

@aknuds1
Copy link
Contributor Author

aknuds1 commented Jul 8, 2025

@krajorama Do you want to take this PR over?

@bwplotka
Copy link
Member

bwplotka commented Jul 8, 2025

FYI: We do want to long term deprecate zero injection feature... ideally. And use proper CT storage for CT handling 🙈 just saying, this is not perfect solution - depending on rationales to implement it here it might make sense.

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.

Handle OTLP StartTime (similar to OpenMetrics Created timestamp)
6 participants