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

Correctly handle gauge distributions in OCSliceToMetrics #2099

Closed
wants to merge 4 commits into from

Conversation

imccarten1
Copy link

@imccarten1 imccarten1 commented Nov 9, 2020

Description: internaldata.OCSliceToMetrics has been updated to correctly handle metrics of type MetricDescriptor_GAUGE_DISTRIBUTION. Previously metrics with this type were silently dropped.

Link to tracking Issue: Fixes open-telemetry/opentelemetry-collector-contrib#10584

Testing: I've added unit tests that handle type gauge distribution to metrics_to_oc_test.go and oc_to_metrics_test.go. I also successfully manually tested exporting metrics of this type from a custom receiver to Stackdriver.

Documentation: no documentation updated

@imccarten1 imccarten1 requested a review from a team November 9, 2020 22:10
@linux-foundation-easycla
Copy link

CLA Missing ID

@linux-foundation-easycla
Copy link

CLA Missing ID

@linux-foundation-easycla
Copy link

CLA Not Signed

@codecov
Copy link

codecov bot commented Nov 10, 2020

Codecov Report

Merging #2099 (a9f81f4) into master (1eada91) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    open-telemetry/opentelemetry-collector#2099      +/-   ##
==========================================
+ Coverage   92.15%   92.17%   +0.02%     
==========================================
  Files         279      279              
  Lines       17086    17144      +58     
==========================================
+ Hits        15746    15803      +57     
  Misses        921      921              
- Partials      419      420       +1     
Impacted Files Coverage Δ
internal/data/testdata/metric.go 100.00% <100.00%> (ø)
translator/internaldata/oc_to_metrics.go 91.94% <100.00%> (+0.17%) ⬆️
translator/internaldata/resource_to_oc.go 88.73% <0.00%> (-2.82%) ⬇️
translator/internaldata/metrics_to_oc.go 90.88% <0.00%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1eada91...a9f81f4. Read the comment docs.

Copy link
Member

@nilebox nilebox left a comment

Choose a reason for hiding this comment

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

LGTM.
If someone else can confirm what should be the "temporality" set to (see comment) it would be great.

metric.InitEmpty()
metric.SetDataType(pdata.MetricDataTypeDoubleHistogram)
metric.DoubleHistogram().InitEmpty()
return pdata.MetricDataTypeDoubleHistogram
Copy link
Member

Choose a reason for hiding this comment

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

We also return pdata.MetricDataTypeDoubleHistogram for case ocmetrics.MetricDescriptor_CUMULATIVE_DISTRIBUTION: below.
Is that correct to treat both types the same?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, the cumulative one sets

histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative)

Possible values are

const (
AggregationTemporalityUnspecified = AggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED)
AggregationTemporalityDelta = AggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA)
AggregationTemporalityCumulative = AggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE)
)

Not sure how the "Unspecified" is treated, do we need to set it to delta here?

Copy link
Member

Choose a reason for hiding this comment

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

Reverse conversion for reference:

case pdata.MetricDataTypeDoubleHistogram:
hd := metric.DoubleHistogram()
if hd.AggregationTemporality() == pdata.AggregationTemporalityCumulative {
return ocmetrics.MetricDescriptor_CUMULATIVE_DISTRIBUTION
}
return ocmetrics.MetricDescriptor_GAUGE_DISTRIBUTION

Copy link
Author

Choose a reason for hiding this comment

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

About the temporality value, there are other GAUGE type metrics such as MetricDescriptor_GAUGE_DOUBLE which also leave the AggregationTemporality unset in descriptorTypeToMetrics(). I was also able to get correctly formatted results in an end to end test of the change that sent metrics to Stackdriver.

Returning pdata.MetricDataTypeDoubleHistogram for both DISTRIBUTION type metrics seems to make sense based on the reverse operation in metrics_to_oc. The alternative would be creating a new MetricDataType in pdata which seems like a large change that might generate push back.

Copy link
Member

Choose a reason for hiding this comment

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

@imccarten1 this is tricky, because indeed for GAUGE_DOUBLE we do not set temporality because the Gauge in otlp proto does not have a temporality see https:/open-telemetry/opentelemetry-proto/blob/master/opentelemetry/proto/metrics/v1/metrics.proto#L153

I think the current way to "not" add temporality is wrong, if you want OTLP to support gauge histograms, please create a PR that adds a temporality called "GAUGE" in the proto, or document that missing temporality means "gauge" otherwise this is an abuse of the proto.

Copy link
Author

Choose a reason for hiding this comment

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

I've created a pull request to add the proto value AGGREGATION_TEMPORALITY_GAUGE. Please take a look. open-telemetry/opentelemetry-proto#236

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the Stale label Nov 20, 2020
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Nov 27, 2020
hughesjj pushed a commit to hughesjj/opentelemetry-collector that referenced this pull request Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenCensue: GAUGE_DISTRIBUTION metric not exported
4 participants