Skip to content

Commit

Permalink
[mdatagen] Add basic telemetry test (open-telemetry#10206)
Browse files Browse the repository at this point in the history
This PR adds basic tests for the telemetry generation, and fixes the
documentation about value type being required for histograms.

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling authored and andrzej-stencel committed May 27, 2024
1 parent c37a36a commit c95da3a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
42 changes: 32 additions & 10 deletions cmd/mdatagen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import (

func TestRunContents(t *testing.T) {
tests := []struct {
yml string
wantMetricsGenerated bool
wantConfigGenerated bool
wantStatusGenerated bool
wantGoleakIgnore bool
wantGoleakSkip bool
wantGoleakSetup bool
wantGoleakTeardown bool
wantErr bool
yml string
wantMetricsGenerated bool
wantConfigGenerated bool
wantTelemetryGenerated bool
wantStatusGenerated bool
wantGoleakIgnore bool
wantGoleakSkip bool
wantGoleakSetup bool
wantGoleakTeardown bool
wantErr bool
}{
{
yml: "invalid.yaml",
Expand Down Expand Up @@ -88,6 +89,15 @@ func TestRunContents(t *testing.T) {
wantStatusGenerated: true,
wantGoleakTeardown: true,
},
{
yml: "with_telemetry.yaml",
wantStatusGenerated: true,
wantTelemetryGenerated: true,
},
{
yml: "invalid_telemetry_missing_value_type_for_histogram.yaml",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.yml, func(t *testing.T) {
Expand Down Expand Up @@ -117,7 +127,6 @@ foo
} else {
require.NoFileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_metrics.go"))
require.NoFileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_metrics_test.go"))
require.NoFileExists(t, filepath.Join(tmpdir, "documentation.md"))
}

if tt.wantConfigGenerated {
Expand All @@ -128,6 +137,19 @@ foo
require.NoFileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_config_test.go"))
}

if tt.wantTelemetryGenerated {
require.FileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_telemetry.go"))
require.FileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_telemetry_test.go"))
require.FileExists(t, filepath.Join(tmpdir, "documentation.md"))
} else {
require.NoFileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_telemetry.go"))
require.NoFileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_telemetry_test.go"))
}

if !tt.wantMetricsGenerated && !tt.wantTelemetryGenerated {
require.NoFileExists(t, filepath.Join(tmpdir, "documentation.md"))
}

var contents []byte
if tt.wantStatusGenerated {
require.FileExists(t, filepath.Join(tmpdir, "internal/metadata/generated_status.go"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/metadata-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ telemetry:
unit:
# Required: metric type with its settings.
<sum|gauge|histogram>:
# Required for sum and gauge metrics: type of number data point values.
# Required: type of number data point values.
value_type: <int|double>
# Required for sum metric: whether the metric is monotonic (no negative delta values).
monotonic: bool
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: metric

status:
class: receiver
stability:
beta: [traces, logs, metrics]
telemetry:
metrics:
sampling_decision_latency:
description: Latency (in microseconds) of a given sampling policy
unit: µs
enabled: true
histogram:
14 changes: 14 additions & 0 deletions cmd/mdatagen/testdata/with_telemetry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type: metric

status:
class: receiver
stability:
beta: [traces, logs, metrics]
telemetry:
metrics:
sampling_decision_latency:
description: Latency (in microseconds) of a given sampling policy
unit: µs
enabled: true
histogram:
value_type: int

0 comments on commit c95da3a

Please sign in to comment.