-
Notifications
You must be signed in to change notification settings - Fork 3.7k
receiver/prometheus: wire up direct pdata conversion mechanism #6421
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
Changes from 25 commits
1c4423a
5cf4213
959a3ed
de159f6
a90ea33
20bf876
0874f0f
4739bcf
1c85958
65fd778
6770a1c
9208e41
8845e18
e710275
5a56ab7
f862b94
598f4a2
2112e47
838f7a5
7e04b44
d3ff42a
4fb78ab
f293579
514e284
ac4dbd9
29dfb74
ae0559b
d0bd35d
4922d5c
5f52842
589a21d
ad029fa
24060cf
4fce276
9344131
5c67cc5
9ed90fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal" | ||
|
|
||
| import "go.opentelemetry.io/collector/model/pdata" | ||
|
|
||
| type kv struct { | ||
| Key, Value string | ||
| } | ||
|
|
||
| func distPointPdata(ts pdata.Timestamp, bounds []float64, counts []uint64) *pdata.HistogramDataPoint { | ||
| hdp := pdata.NewHistogramDataPoint() | ||
| hdp.SetExplicitBounds(bounds) | ||
| hdp.SetBucketCounts(counts) | ||
| hdp.SetTimestamp(ts) | ||
| var sum float64 | ||
| var count uint64 | ||
| for i, bcount := range counts { | ||
| count += bcount | ||
| if i > 0 { | ||
| sum += float64(bcount) * bounds[i-1] | ||
| } | ||
| } | ||
| hdp.SetCount(count) | ||
| hdp.SetSum(sum) | ||
|
|
||
| return &hdp | ||
| } | ||
|
|
||
| func gaugeDistMetricPdata(name string, kvp []*kv, startTs pdata.Timestamp, points ...*pdata.HistogramDataPoint) *pdata.Metric { | ||
| hMetric := cumulativeDistMetricPdata(name, kvp, startTs, points...) | ||
| hMetric.Histogram().SetAggregationTemporality(pdata.MetricAggregationTemporalityDelta) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I understand, all prometheus data is cumulative including gauge, but am likely wrong. Wondering if there is a reference for the mapping, I searched around and found this doc with a broken link to a design doc. Would help reviewing this PR if there's information about the mapping somewhere
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not actually sure. This is inherited test helper code that seems to be used to test adjustment of gauge histograms, which should never be encountered since the appender won't build them and the metric adjuster will short circuit when encountering a distribution with other than cumulative temporality. I think this can be removed without impacting functionality or test coverage. |
||
| return hMetric | ||
| } | ||
|
|
||
| func cumulativeDistMetricPdata(name string, kvp []*kv, startTs pdata.Timestamp, points ...*pdata.HistogramDataPoint) *pdata.Metric { | ||
| metric := pdata.NewMetric() | ||
| metric.SetName(name) | ||
| metric.SetDataType(pdata.MetricDataTypeHistogram) | ||
| histogram := metric.Histogram() | ||
| histogram.SetAggregationTemporality(pdata.MetricAggregationTemporalityCumulative) | ||
|
|
||
| destPointL := histogram.DataPoints() | ||
| // By default the AggregationTemporality is Cumulative until it'll be changed by the caller. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can tell this is referring to line 53
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment is either a vestige of a prior pdata API or a misunderstanding by the original author. The default aggregation temporality appears to be unspecified. See https://github.com/open-telemetry/opentelemetry-collector/blob/main/model/pdata/metrics.go#L256-L261. I am removing this comment. |
||
| for _, point := range points { | ||
| destPoint := destPointL.AppendEmpty() | ||
| point.CopyTo(destPoint) | ||
| point.SetStartTimestamp(startTs) | ||
| attrs := destPoint.Attributes() | ||
| for _, kv := range kvp { | ||
| attrs.InsertString(kv.Key, kv.Value) | ||
| } | ||
| } | ||
| return &metric | ||
| } | ||
|
|
||
| func doublePointPdata(ts pdata.Timestamp, value float64) *pdata.NumberDataPoint { | ||
| ndp := pdata.NewNumberDataPoint() | ||
| ndp.SetTimestamp(ts) | ||
| ndp.SetDoubleVal(value) | ||
|
|
||
| return &ndp | ||
| } | ||
|
|
||
| func gaugeMetricPdata(name string, kvp []*kv, startTs pdata.Timestamp, points ...*pdata.NumberDataPoint) *pdata.Metric { | ||
| metric := pdata.NewMetric() | ||
| metric.SetName(name) | ||
| metric.SetDataType(pdata.MetricDataTypeGauge) | ||
|
|
||
| destPointL := metric.Gauge().DataPoints() | ||
| for _, point := range points { | ||
| destPoint := destPointL.AppendEmpty() | ||
| point.CopyTo(destPoint) | ||
| point.SetStartTimestamp(startTs) | ||
| attrs := destPoint.Attributes() | ||
| for _, kv := range kvp { | ||
| attrs.InsertString(kv.Key, kv.Value) | ||
| } | ||
| } | ||
| return &metric | ||
| } | ||
|
|
||
| func summaryPointPdata(ts pdata.Timestamp, count uint64, sum float64, quantiles, values []float64) *pdata.SummaryDataPoint { | ||
| sdp := pdata.NewSummaryDataPoint() | ||
| sdp.SetTimestamp(ts) | ||
| sdp.SetCount(count) | ||
| sdp.SetSum(sum) | ||
| qvL := sdp.QuantileValues() | ||
| for i := 0; i < len(quantiles); i++ { | ||
| qvi := qvL.AppendEmpty() | ||
| qvi.SetQuantile(quantiles[i]) | ||
| qvi.SetValue(values[i]) | ||
| } | ||
| return &sdp | ||
| } | ||
|
|
||
| func summaryMetricPdata(name string, kvp []*kv, startTs pdata.Timestamp, points ...*pdata.SummaryDataPoint) *pdata.Metric { | ||
| metric := pdata.NewMetric() | ||
| metric.SetName(name) | ||
| metric.SetDataType(pdata.MetricDataTypeSummary) | ||
|
|
||
| destPointL := metric.Summary().DataPoints() | ||
| for _, point := range points { | ||
| destPoint := destPointL.AppendEmpty() | ||
| point.CopyTo(destPoint) | ||
| point.SetStartTimestamp(startTs) | ||
| attrs := destPoint.Attributes() | ||
| for _, kv := range kvp { | ||
| attrs.InsertString(kv.Key, kv.Value) | ||
| } | ||
| } | ||
| return &metric | ||
| } | ||
|
|
||
| func sumMetricPdata(name string, kvp []*kv, startTs pdata.Timestamp, points ...*pdata.NumberDataPoint) *pdata.Metric { | ||
| metric := pdata.NewMetric() | ||
| metric.SetName(name) | ||
| metric.SetDataType(pdata.MetricDataTypeSum) | ||
| sum := metric.Sum() | ||
| sum.SetAggregationTemporality(pdata.MetricAggregationTemporalityCumulative) | ||
| sum.SetIsMonotonic(true) | ||
|
|
||
|
Aneurysm9 marked this conversation as resolved.
|
||
| destPointL := sum.DataPoints() | ||
| for _, point := range points { | ||
| destPoint := destPointL.AppendEmpty() | ||
| point.CopyTo(destPoint) | ||
| point.SetStartTimestamp(startTs) | ||
| attrs := destPoint.Attributes() | ||
| for _, kv := range kvp { | ||
| attrs.InsertString(kv.Key, kv.Value) | ||
| } | ||
| } | ||
| return &metric | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably simpler just to use
featuregate.IsEnabled(pdataPipelineGate.ID)where it is needed, rather than store it here. Is there a way to set feature gates during a test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is only a global feature gate registry, so it can't necessarily be used in tests. The feature gate registry also has a lock, so we recommend that the feature status is checked once and stored if it is needed repeatedly. There is no mechanism for operators to change feature gate statuses during program runtime, so it should be safe to read this once and re-use it.