diff --git a/cmd/mdatagen/internal/loader_test.go b/cmd/mdatagen/internal/loader_test.go index 19f3e118410..bcacf107208 100644 --- a/cmd/mdatagen/internal/loader_test.go +++ b/cmd/mdatagen/internal/loader_test.go @@ -288,6 +288,16 @@ func TestLoadMetadata(t *testing.T) { Async: true, }, }, + "queue_capacity": { + Enabled: true, + Description: "Queue capacity - sync gauge example.", + Unit: strPtr("{items}"), + Gauge: &Gauge{ + MetricValueType: MetricValueType{ + ValueType: pmetric.NumberDataPointValueTypeInt, + }, + }, + }, }, }, ScopeName: "go.opentelemetry.io/collector/internal/receiver/samplereceiver", diff --git a/cmd/mdatagen/internal/samplereceiver/documentation.md b/cmd/mdatagen/internal/samplereceiver/documentation.md index f810d0a0369..077f1bf8250 100644 --- a/cmd/mdatagen/internal/samplereceiver/documentation.md +++ b/cmd/mdatagen/internal/samplereceiver/documentation.md @@ -134,6 +134,14 @@ Cumulative bytes allocated for heap objects (see 'go doc runtime.MemStats.TotalA | ---- | ----------- | ---------- | --------- | | By | Sum | Int | true | +### otelcol_queue_capacity + +Queue capacity - sync gauge example. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {items} | Gauge | Int | + ### otelcol_queue_length This metric is optional and therefore not initialized in NewTelemetryBuilder. diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go index b44d14a8c70..df2d3e1ce0b 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go @@ -29,6 +29,7 @@ type TelemetryBuilder struct { BatchSizeTriggerSend metric.Int64Counter ProcessRuntimeTotalAllocBytes metric.Int64ObservableCounter observeProcessRuntimeTotalAllocBytes func(context.Context, metric.Observer) error + QueueCapacity metric.Int64Gauge QueueLength metric.Int64ObservableGauge RequestDuration metric.Float64Histogram } @@ -95,6 +96,12 @@ func NewTelemetryBuilder(settings component.TelemetrySettings, options ...Teleme errs = errors.Join(errs, err) _, err = getLeveledMeter(builder.meter, configtelemetry.LevelBasic, settings.MetricsLevel).RegisterCallback(builder.observeProcessRuntimeTotalAllocBytes, builder.ProcessRuntimeTotalAllocBytes) errs = errors.Join(errs, err) + builder.QueueCapacity, err = getLeveledMeter(builder.meter, configtelemetry.LevelBasic, settings.MetricsLevel).Int64Gauge( + "otelcol_queue_capacity", + metric.WithDescription("Queue capacity - sync gauge example."), + metric.WithUnit("{items}"), + ) + errs = errors.Join(errs, err) builder.RequestDuration, err = getLeveledMeter(builder.meter, configtelemetry.LevelBasic, settings.MetricsLevel).Float64Histogram( "otelcol_request_duration", metric.WithDescription("Duration of request [alpha]"), diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadatatest/generated_telemetrytest_test.go b/cmd/mdatagen/internal/samplereceiver/internal/metadatatest/generated_telemetrytest_test.go index 8783cd7f6d0..ccd897ac3cc 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadatatest/generated_telemetrytest_test.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadatatest/generated_telemetrytest_test.go @@ -22,6 +22,7 @@ func TestSetupTelemetry(t *testing.T) { require.NoError(t, err) require.NotNil(t, tb) tb.BatchSizeTriggerSend.Add(context.Background(), 1) + tb.QueueCapacity.Record(context.Background(), 1) tb.RequestDuration.Record(context.Background(), 1) testTel.AssertMetrics(t, []metricdata.Metrics{ @@ -49,6 +50,16 @@ func TestSetupTelemetry(t *testing.T) { }, }, }, + { + Name: "otelcol_queue_capacity", + Description: "Queue capacity - sync gauge example.", + Unit: "{items}", + Data: metricdata.Gauge[int64]{ + DataPoints: []metricdata.DataPoint[int64]{ + {}, + }, + }, + }, { Name: "otelcol_request_duration", Description: "Duration of request [alpha]", diff --git a/cmd/mdatagen/internal/samplereceiver/metadata.yaml b/cmd/mdatagen/internal/samplereceiver/metadata.yaml index d45cc7f0518..8014e3e5849 100644 --- a/cmd/mdatagen/internal/samplereceiver/metadata.yaml +++ b/cmd/mdatagen/internal/samplereceiver/metadata.yaml @@ -197,3 +197,9 @@ telemetry: gauge: async: true value_type: int + queue_capacity: + enabled: true + description: Queue capacity - sync gauge example. + unit: "{items}" + gauge: + value_type: int diff --git a/cmd/mdatagen/internal/templates/telemetrytest_test.go.tmpl b/cmd/mdatagen/internal/templates/telemetrytest_test.go.tmpl index 87abd5ceb55..2d4e44fca24 100644 --- a/cmd/mdatagen/internal/templates/telemetrytest_test.go.tmpl +++ b/cmd/mdatagen/internal/templates/telemetrytest_test.go.tmpl @@ -26,11 +26,9 @@ func TestSetupTelemetry(t *testing.T) { require.NotNil(t, tb) {{- range $name, $metric := .Telemetry.Metrics }} {{- if (and (not $metric.Optional) (not $metric.Data.Async)) }} - {{ if eq $metric.Data.Type "Gauge" -}} - tb.{{ $name.Render }}.Set(context.Background(), 1) - {{- else if eq $metric.Data.Type "Sum" -}} + {{- if eq $metric.Data.Type "Sum" }} tb.{{ $name.Render }}.Add(context.Background(), 1) - {{- else if eq $metric.Data.Type "Histogram" -}} + {{- else }} tb.{{ $name.Render }}.Record(context.Background(), 1) {{- end }} {{- end }}