Skip to content

[prometheusreceiver] Make use of created timestamp from prometheus #36660

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

Conversation

bacherfl
Copy link
Contributor

@bacherfl bacherfl commented Dec 4, 2024

Description

This PR implements the AppendCTZeroSample and AppendHistogramCTZeroSample methods which can be called by prometheus to pass through the creation timestamp of a metric

Link to tracking issue

Fixes #36473

Testing

Added unit tests

@github-actions github-actions bot added the receiver/prometheus Prometheus receiver label Dec 4, 2024
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
@dashpole
Copy link
Contributor

dashpole commented Dec 4, 2024

I think we might need the prometheus update for this to work: #36642

@bacherfl
Copy link
Contributor Author

bacherfl commented Dec 5, 2024

I think we might need the prometheus update for this to work: #36642

thanks for the link to the PR - I was wondering if I should also include the dependency update in my PR but in this case I will wait for the dependency update PR to get merged.

One other thing: As of now, it seems like the CreatedTimestamp() method is only implemented for the openmetrics parser, but not for the prometheus parser - So I think we need to wait with removing the receiver.prometheusreceiver.UseCreatedMetric and keep the code related to that for now.

Copy link
Contributor

github-actions bot commented Jan 1, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 1, 2025
@dashpole dashpole removed the Stale label Jan 6, 2025
@bacherfl bacherfl marked this pull request as ready for review February 17, 2025 13:21
@bacherfl bacherfl requested a review from a team as a code owner February 17, 2025 13:21
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

Really excited to see this!

@MovieStoreGuy MovieStoreGuy merged commit ed991d8 into open-telemetry:main Feb 20, 2025
162 checks passed
@github-actions github-actions bot added this to the next release milestone Feb 20, 2025
@@ -425,6 +425,11 @@ func (mf *metricFamily) addSeries(seriesRef uint64, metricName string, ls labels
return nil
}

func (mf *metricFamily) addCreationTimestamp(seriesRef uint64, ls labels.Labels, atMs, created int64) {
mg := mf.loadMetricGroupOrCreate(seriesRef, ls, atMs)
mg.created = float64(created)
Copy link
Member

Choose a reason for hiding this comment

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

This should be setting seconds but is setting milliseconds.

gracewehner added a commit to Azure/prometheus-collector that referenced this pull request May 28, 2025
Change the `EnableCreatedTimestampZeroIngestion` setting in the
prometheus scrape manager to use the otelcollector feature flag that has
the same name and is disabled by default.

This had introduced new parsing during a scrape loop that resulted in
very high CPU at higher metric volumes.

Reverts this PR:
open-telemetry/opentelemetry-collector-contrib#36660
so that the functionality for this is the same as before v0.121.0``
songy23 pushed a commit that referenced this pull request Jun 5, 2025
…us setting to fix high CPU for openmetrics (#40355)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
The PR #36660 enabled the setting in the scrape manager
`EnableCreatedTimestampZeroIngestion` by default. This enabled the
[Prometheus feature
flag](https://prometheus.io/docs/prometheus/latest/feature_flags/#created-timestamps-zero-injection)
by the same name. In Prometheus, when this is set to true, [a call to a
new
function](https://github.com/prometheus/prometheus/blob/1d9dfde9894f0c82b809b70aa5f9cecab25b8fea/scrape/scrape.go#L1770-L1799)
CreatedTimestamp() is run.

This currently isn't implemented for the Prometheus parser but is for
the OpenMetrics parser and [has a
comment](https://github.com/prometheus/prometheus/blob/main/model/textparse/openmetricsparse.go#L287)
that it may use additional CPU and memory resources. We are seeing a 10x
increase in CPU usage when there's a high volume of metrics scraped with
this scenario.

This PR puts the setting in the scrape manager behind a feature gate
that allows it to be disabled.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes #40245

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Tested with a custom build with this change.

<!--Describe the documentation added.-->
#### Documentation
Documentation about the feature gate exists
[here](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/prometheusreceiver/README.md#getting-started).

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Arthur Silva Sens <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
receiver/prometheus Prometheus receiver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prometheusreceiver: Make use of created timestamp from prometheus
5 participants