-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix/mdatagen histogram generation #14415
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
base: main
Are you sure you want to change the base?
Fix/mdatagen histogram generation #14415
Conversation
When service.telemetry.metrics.level is set to 'none', the collector should skip registering process metrics to avoid errors on platforms where gopsutil is not supported (such as AIX). This change conditionally registers process metrics only when the metrics level is not LevelNone, preventing the 'failed to register process metrics: not implemented yet' error on unsupported platforms. Fixes regression introduced in v0.136.0 where the check for metrics level was removed.
Similar to the resolution for pcommon.Value in previous changes, this update ensures consistent documentation across all pdata types by clarifying that calling functions on zero-initialized instances is invalid usage. Changes: - Updated template files (one_of_field.go, one_of_message_value.go) to generate improved comment wording - Updated pcommon/value.go comments manually - Updated all generated pdata files to use consistent wording: 'is invalid and will cause a panic' instead of 'will cause a panic' This makes it clearer that using zero-initialized instances is not just dangerous but explicitly invalid usage, improving API documentation clarity.
Fixes open-telemetry#14326 mdatagen was generating invalid Go code for histogram metrics by using NumberDataPoint API methods (SetDoubleValue, ValueType) on HistogramDataPoint types, causing compilation errors. Changes: Update metrics.go.tmpl to use HistogramDataPoint API for histogram metrics with dp.SetCount(1) and dp.SetSum(val). Update metrics_test.go.tmpl to assert dp.Count() and dp.Sum() for histograms. Add system.cpu.utilization histogram to samplescraper metadata for validation.
| @@ -223,8 +235,11 @@ func New(ctx context.Context, set Settings, cfg Config) (_ *Service, resultErr e | |||
| return nil, err | |||
| } | |||
|
|
|||
| if err := proctelemetry.RegisterProcessMetrics(srv.telemetrySettings); err != nil { | |||
| return nil, fmt.Errorf("failed to register process metrics: %w", err) | |||
| // Only register process metrics if metrics telemetry is enabled | |||
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.
This change seems unrelated. Could you keep your PRs atomic?
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.
Thanks for pointing this out 👍
You’re right — the process metrics change is unrelated to the mdatagen histogram fix.
I’ll split this into a separate PR and keep this one focused only on histogram generation.
Fixes #14326
mdatagen was generating invalid Go code for histogram metrics by using
NumberDataPointAPI methods (SetDoubleValue,ValueType) onHistogramDataPointtypes, causing compilation errors.Changes
metrics.go.tmpl:
{{- if eq $metric.Data.Type "Histogram" }}HistogramDataPointAPI:dp.SetCount(1)anddp.SetSum(val)instead ofdp.SetDoubleValue(val)dp.ExplicitBounds().FromRaw()anddp.BucketCounts().FromRaw()for bucket setupmetrics_test.go.tmpl:
assert.Equal(uint64(1), dp.Count())andassert.InDelta(float64(1), dp.Sum())for histogramsmetadata.yaml:
system.cpu.utilizationhistogram metric to samplescraper for validationTesting
go build ./...go test ./...Backward Compatibility
Example Usage
Generated code will correctly use
HistogramDataPointAPI methods.