Skip to content
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

[mdatagen] Add basic telemetry test #10206

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading