Skip to content

Commit

Permalink
[cmd/mdatagen] Remove level field from metrics (#12145)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
<!-- Issue number if applicable -->

Removes `level` field. This will be added back in the future once #11754
is completed.

#### Link to tracking issue

Updates #11061
  • Loading branch information
mx-psi authored Jan 22, 2025
1 parent d3ba5a3 commit b844bb7
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 154 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_deprecate-level-mdatagen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: cmd/mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove `level` field from metrics definition

# One or more tracking issues or pull requests related to the change
issues: [12145]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: This mechanism will be added back once a new views mechanism is implemented.

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
6 changes: 0 additions & 6 deletions cmd/mdatagen/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"golang.org/x/text/language"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/pdata/pmetric"
)
Expand Down Expand Up @@ -60,11 +59,6 @@ type Metric struct {

// Attributes is the list of attributes that the metric emits.
Attributes []AttributeName `mapstructure:"attributes"`

// Level specifies the minimum `configtelemetry.Level` for which
// the metric will be emitted. This only applies to internal telemetry
// configuration.
Level configtelemetry.Level `mapstructure:"level"`
}

type Stability struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions cmd/mdatagen/internal/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@ package internal // import "go.opentelemetry.io/collector/cmd/mdatagen/internal"
type Telemetry struct {
Metrics map[MetricName]Metric `mapstructure:"metrics"`
}

func (t Telemetry) Levels() map[string]any {
levels := map[string]any{}
for _, m := range t.Metrics {
levels[m.Level.String()] = nil
}
return levels
}
11 changes: 2 additions & 9 deletions cmd/mdatagen/internal/templates/telemetry.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewTelemetryBuilder(settings component.TelemetrySettings, options ...Teleme

{{- range $name, $metric := .Telemetry.Metrics }}
{{- if not $metric.Optional }}
builder.{{ $name.Render }}, err = getLeveledMeter(builder.meter, configtelemetry.Level{{ $metric.Level }}, settings.MetricsLevel).{{ $metric.Data.Instrument }}(
builder.{{ $name.Render }}, err = builder.meter.{{ $metric.Data.Instrument }}(
"otelcol_{{ $name }}",
metric.WithDescription("{{ $metric.Description }}{{ $metric.Stability }}"),
metric.WithUnit("{{ $metric.Unit }}"),
Expand All @@ -119,19 +119,12 @@ func NewTelemetryBuilder(settings component.TelemetrySettings, options ...Teleme
)
errs = errors.Join(errs, err)
{{- if $metric.Data.Async }}
_, err = getLeveledMeter(builder.meter, configtelemetry.Level{{ $metric.Level }}, settings.MetricsLevel).RegisterCallback(builder.observe{{ $name.Render }}, builder.{{ $name.Render }})
_, err = builder.meter.RegisterCallback(builder.observe{{ $name.Render }}, builder.{{ $name.Render }})
errs = errors.Join(errs, err)
{{- end }}
{{- end }}
{{- end }}
return &builder, errs
}

func getLeveledMeter(meter metric.Meter, cfgLevel, srvLevel configtelemetry.Level) metric.Meter {
if cfgLevel <= srvLevel {
return meter
}
return noopmetric.Meter{}
}

{{- end }}
27 changes: 9 additions & 18 deletions exporter/exporterhelper/internal/metadata/generated_telemetry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions processor/batchprocessor/batch_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestBatchProcessorSentBySize(t *testing.T) {
tel.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_processor_batch_batch_send_size_bytes",
Description: "Number of bytes in batch that was sent",
Description: "Number of bytes in batch that was sent. Only available on detailed level.",
Unit: "By",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestBatchProcessorSentBySizeWithMaxSize(t *testing.T) {
tel.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_processor_batch_batch_send_size_bytes",
Description: "Number of bytes in batch that was sent",
Description: "Number of bytes in batch that was sent. Only available on detailed level.",
Unit: "By",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestBatchMetricProcessorBatchSize(t *testing.T) {
tel.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_processor_batch_batch_send_size_bytes",
Description: "Number of bytes in batch that was sent",
Description: "Number of bytes in batch that was sent. Only available on detailed level.",
Unit: "By",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
Expand Down Expand Up @@ -975,7 +975,7 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) {
tel.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_processor_batch_batch_send_size_bytes",
Description: "Number of bytes in batch that was sent",
Description: "Number of bytes in batch that was sent. Only available on detailed level.",
Unit: "By",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
Expand Down
2 changes: 1 addition & 1 deletion processor/batchprocessor/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Number of units in the batch

### otelcol_processor_batch_batch_send_size_bytes

Number of bytes in batch that was sent
Number of bytes in batch that was sent. Only available on detailed level.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
Expand Down
23 changes: 7 additions & 16 deletions processor/batchprocessor/internal/metadata/generated_telemetry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions processor/batchprocessor/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ telemetry:
value_type: int
bucket_boundaries: [ 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000, 100000 ]
processor_batch_batch_send_size_bytes:
level: detailed
enabled: true
description: Number of bytes in batch that was sent
description: Number of bytes in batch that was sent. Only available on detailed level.
unit: By
histogram:
value_type: int
Expand Down
Loading

0 comments on commit b844bb7

Please sign in to comment.