Skip to content
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

receiver/prometheus: use actual interval startTimeMs for cumulative types #3694

Conversation

odeke-em
Copy link
Member

With this change, we now infer the actual interval startTime
for cumulative types from the original starttime interval reinforcing
what the OpenTelemetry Proto recommendations say in
https://github.com/open-telemetry/opentelemetry-proto/blob/bc8ee79d8e01faf3310af2987268e94285f354da/opentelemetry/proto/metrics/v1/metrics.proto#L132-L140

Fixes #3691

@odeke-em odeke-em requested review from alolita, Aneurysm9 and a team as code owners July 22, 2021 06:48
@project-bot project-bot bot added this to In progress in Collector Jul 22, 2021
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 22, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 22, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 22, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

Please rebase, this PR contains changes already merged

@odeke-em odeke-em force-pushed the receiver-prometheus-fix-cumulativeType-startTime branch from 4cd3b20 to 7355a6a Compare July 22, 2021 16:05
@odeke-em
Copy link
Member Author

Please rebase, this PR contains changes already merged

Rebase done, please take a look @bogdandrutu!

@odeke-em odeke-em force-pushed the receiver-prometheus-fix-cumulativeType-startTime branch from 7355a6a to b36a526 Compare July 23, 2021 21:57
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 23, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
@bogdandrutu
Copy link
Member

Please review @Aneurysm9 @rakyll @dashpole @punya

@odeke-em odeke-em force-pushed the receiver-prometheus-fix-cumulativeType-startTime branch from b36a526 to 24ceec5 Compare July 27, 2021 16:54
@@ -166,7 +166,7 @@ func (tr *transaction) initTransaction(ls labels.Labels) error {
tr.instance = instance
}
tr.node, tr.resource = createNodeAndResource(job, instance, mc.SharedLabels().Get(model.SchemeLabel))
tr.metricBuilder = newMetricBuilder(mc, tr.useStartTimeMetric, tr.startTimeMetricRegex, tr.logger, tr.stalenessStore)
tr.metricBuilder = newMetricBuilder(mc, tr.useStartTimeMetric, tr.startTimeMetricRegex, tr.logger, tr.stalenessStore, tr.startTimeMs)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like an Appender is created when the config is loaded: https://github.com/prometheus/prometheus/blob/5cc30b716e23c98863093c0ed39315c1fe7c103e/scrape/manager.go#L257. That would mean that this start time is the start time of the first metric that the collector sees, which is approximately the start time of the collector. That seems like it would be incorrect in many cases. Is there something i'm missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, for every Scrape, a new storage.Appender is requested, not when the collector is started. This means that
even a new transaction is created per scrape and at the end either .Commit() or .Rollback() is invoked. This isn't a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks. Is the storage.Appender created after the scrape finishes, or before the scrape is started? We just need to make sure the start time isn't before the metric's timestamp

Copy link
Member

Choose a reason for hiding this comment

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

Another option for the moment is to leave the starttime unset (0) which is conforming with our specs, then fix this the correct timestamp later. This is to unblock the progress.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, thanks. Is the storage.Appender created after the scrape finishes, or before the scrape is started? We just need to make sure the start time isn't before the metric's timestamp

@dashpole we infer that startTime for the very first time that's passed into (*transaction).Append so it will ALWAYS be the first timestamp. initTransaction is lazily loaded and .startTimeMs will ALWAYS be set after the first .Append.

if tr.startTimeMs < 0 {
tr.startTimeMs = t
}

if tr.isNew {
if err := tr.initTransaction(ls); err != nil {
return 0, err
}
}

@dashpole to answer your question about Prometheus (but it is irrelevant to this code) the storage.Appender is created before the scrape begins per https://github.com/prometheus/prometheus/blob/1a430e5f894d6575478bcef52d25bfbe7134947e/scrape/scrape.go#L1182-L1237 or visually
Screen Shot 2021-07-29 at 2 19 49 PM
Screen Shot 2021-07-29 at 2 19 58 PM

Another option for the moment is to leave the starttime unset (0) which is conforming with our specs, then fix this the correct timestamp later. This is to unblock the progress.

@bogdandrutu thanks for raising this, I didn't know about using 0 conforming with specs. No, we are already good, the intervalStartTime is inferred from the very first start time when (*transaction).Append so we are all set.

…ypes

With this change, we now infer the actual interval startTime
for cumulative types from the original starttime interval reinforcing
what the OpenTelemetry Proto recommendations say in
https://github.com/open-telemetry/opentelemetry-proto/blob/bc8ee79d8e01faf3310af2987268e94285f354da/opentelemetry/proto/metrics/v1/metrics.proto#L132-L140

Fixes open-telemetry#3691
@odeke-em odeke-em force-pushed the receiver-prometheus-fix-cumulativeType-startTime branch from 24ceec5 to f7cee29 Compare July 29, 2021 19:56
@odeke-em odeke-em requested a review from dashpole July 29, 2021 22:18
@odeke-em
Copy link
Member Author

Thank you for the review @dashpole and @bogdandrutu!

odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 29, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 29, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 29, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Jul 30, 2021
Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes open-telemetry#3691
Depends on PR open-telemetry#3694
Depends on PR open-telemetry#3695
@bogdandrutu bogdandrutu merged commit b328e13 into open-telemetry:main Aug 2, 2021
Collector automation moved this from Reviewer approved to Done Aug 2, 2021
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 2, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will allow us
to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 2, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will allow us
to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
bogdandrutu pushed a commit that referenced this pull request Aug 3, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will allow us
to delete all the prior code!!

Updates #3137
Updates PR #3674
Requires PR #3694
Updates #3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 4, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 4, 2021
Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes open-telemetry#3691
Depends on PR open-telemetry#3694
Depends on PR open-telemetry#3695
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 4, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 4, 2021
Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes open-telemetry#3691
Depends on PR open-telemetry#3694
Depends on PR open-telemetry#3695
@odeke-em odeke-em deleted the receiver-prometheus-fix-cumulativeType-startTime branch August 11, 2021 23:18
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 12, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 12, 2021
Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes open-telemetry#3691
Depends on PR open-telemetry#3694
Depends on PR open-telemetry#3695
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 17, 2021
This change wires together the logic to convert
the pdata converters into a method ToMetricPdata
that appends converted metrics. The next change or two,
will then hook everything up directly and will
allow us to delete all the prior code!!

Updates #3137
Updates PR open-telemetry#3674
Requires PR open-telemetry#3694
Updates open-telemetry#3691
odeke-em added a commit to orijtech/opentelemetry-collector that referenced this pull request Aug 17, 2021
Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes open-telemetry#3691
Depends on PR open-telemetry#3694
Depends on PR open-telemetry#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 11, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 11, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 11, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 11, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 11, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 11, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 13, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 13, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 13, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 13, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 13, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 14, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 17, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
odeke-em added a commit to orijtech/opentelemetry-collector-contrib that referenced this pull request Sep 21, 2021
…thout OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695
bogdandrutu pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Dec 8, 2021
* receiver/prometheus: roundtrip Prometheus->Pdata direct conversion without OpenCensus

Wire up and use the direct Prometheus->Pdata conversion end to end.
With this change the receiver will no longer need OpenCensus.

This change will involve more follow-ups that just migrate over the tests,
because we don't want a super bloated/massive PR.

Fixes #4892
Depends on PR open-telemetry/opentelemetry-collector#3694
Depends on PR open-telemetry/opentelemetry-collector#3695

* Retrofit top level package for pdata comparisons

* Reuse for pdata metrics creators from PR #5231

* Shed all in-code direct references to OpenCensus

* receiver/prometheus: fix tests

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: buffer metrics in builder to avoid issues with out-of-order exposition

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: restore prom->OC->pdata pipeline

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: add feature gate to control whether to use OpenCensus or pdata directly

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: localize metrics test helpers

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: store metrics in a map in metricbuilder to avoid issues with out-of-order exposition data

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: run component tests against both OC and pdata export paths

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: ensure OC metrics builder tests are deterministic

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: restore replace directive to ensure use of local copy of opencensus translator during development

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: fix lint issues

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: fix lint issues

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* make porto

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: run e2e tests in parallel to avoid doubling test suite runtime

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Revert "receiver/prometheus: run e2e tests in parallel to avoid doubling test suite runtime"

This reverts commit 7e04b44.

* receiver/prometheus: address PR feedback

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: ensure test helper can extract timestamp from metrics of any type

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: tests should not be expecting empty label values

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* make porto

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: remove gauge histogram pdata adjustment tests

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: remove unused gauge histogram data generator helper

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Fix lint errors

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* receiver/prometheus: Add comments detailing use of locks in metrics adjuster.

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Collector
  
Done
Development

Successfully merging this pull request may close these issues.

receiver/prometheus/internal: use actual startTimeMs of interval for toDoubleValue
6 participants