Skip to content

Commit

Permalink
[chore] [mdatagen] Fix generated telemetry tests (#12034)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored Jan 7, 2025
1 parent 83c909f commit ced38e8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
10 changes: 10 additions & 0 deletions cmd/mdatagen/internal/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions cmd/mdatagen/internal/samplereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

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.

6 changes: 6 additions & 0 deletions cmd/mdatagen/internal/samplereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions cmd/mdatagen/internal/templates/telemetrytest_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit ced38e8

Please sign in to comment.