Skip to content

Commit

Permalink
Deprecate component_test in favor of metadatatest
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Dec 5, 2024
1 parent 52d8a1a commit 22a7b42
Show file tree
Hide file tree
Showing 47 changed files with 1,718 additions and 138 deletions.
25 changes: 25 additions & 0 deletions .chloggen/dep-comp-test.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: deprecation

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate component_test in favor of metadatatest

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

# (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:

# 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: [api]
6 changes: 6 additions & 0 deletions cmd/mdatagen/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func run(ymlPath string) error {
if err = os.MkdirAll(codeDir, 0700); err != nil {
return fmt.Errorf("unable to create output directory %q: %w", codeDir, err)
}
testDir := filepath.Join(ymlDir, "internal", md.GeneratedPackageName+"test")
if err = os.MkdirAll(testDir, 0700); err != nil {
return fmt.Errorf("unable to create output test directory %q: %w", codeDir, err)
}
if md.Status != nil {
if md.Status.Class != "cmd" && md.Status.Class != "pkg" && !md.Status.NotComponent {
if err = generateFile(filepath.Join(tmplDir, "status.go.tmpl"),
Expand Down Expand Up @@ -114,6 +118,8 @@ func run(ymlPath string) error {
}
toGenerate[filepath.Join(tmplDir, "telemetry.go.tmpl")] = filepath.Join(codeDir, "generated_telemetry.go")
toGenerate[filepath.Join(tmplDir, "telemetry_test.go.tmpl")] = filepath.Join(codeDir, "generated_telemetry_test.go")
toGenerate[filepath.Join(tmplDir, "telemetrytest.go.tmpl")] = filepath.Join(testDir, "generated_telemetrytest.go")
toGenerate[filepath.Join(tmplDir, "telemetrytest_test.go.tmpl")] = filepath.Join(testDir, "generated_telemetrytest_test.go")
}

if len(md.Metrics) != 0 || len(md.Telemetry.Metrics) != 0 || len(md.ResourceAttributes) != 0 { // if there's metrics or internal metrics, generate documentation for them
Expand Down
2 changes: 2 additions & 0 deletions cmd/mdatagen/internal/embedded_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestEnsureTemplatesLoaded(t *testing.T) {
path.Join(rootDir, "telemetry.go.tmpl"): {},
path.Join(rootDir, "telemetry_test.go.tmpl"): {},
path.Join(rootDir, "testdata", "config.yaml.tmpl"): {},
path.Join(rootDir, "telemetrytest.go.tmpl"): {},
path.Join(rootDir, "telemetrytest_test.go.tmpl"): {},
}
count = 0
)
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.

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.

12 changes: 7 additions & 5 deletions cmd/mdatagen/internal/samplereceiver/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (

"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"

"go.opentelemetry.io/collector/cmd/mdatagen/internal/samplereceiver/internal/metadata"
"go.opentelemetry.io/collector/cmd/mdatagen/internal/samplereceiver/internal/metadatatest"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/receivertest"
Expand All @@ -24,11 +26,11 @@ func TestGeneratedMetrics(t *testing.T) {
}

func TestComponentTelemetry(t *testing.T) {
tt := setupTestTelemetry()
tt := metadatatest.SetupTestTelemetry()
factory := NewFactory()
receiver, err := factory.CreateMetrics(context.Background(), tt.NewSettings(), componenttest.NewNopHost(), new(consumertest.MetricsSink))
require.NoError(t, err)
tt.assertMetrics(t, []metricdata.Metrics{
tt.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_batch_size_trigger_send",
Description: "Number of times the batch was sent due to a size trigger [deprecated since v0.110.0]",
Expand Down Expand Up @@ -57,11 +59,11 @@ func TestComponentTelemetry(t *testing.T) {
},
},
},
})
}, metricdatatest.IgnoreTimestamp())
rcv, ok := receiver.(nopReceiver)
require.True(t, ok)
rcv.initOptionalMetric()
tt.assertMetrics(t, []metricdata.Metrics{
tt.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_batch_size_trigger_send",
Description: "Number of times the batch was sent due to a size trigger [deprecated since v0.110.0]",
Expand Down Expand Up @@ -102,6 +104,6 @@ func TestComponentTelemetry(t *testing.T) {
},
},
},
})
}, metricdatatest.IgnoreTimestamp())
require.NoError(t, tt.Shutdown(context.Background()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
{{- end }}
)

// Deprecated: [v0.116.0] use metadatatest.TestTelemetry
type componentTestTelemetry struct {
reader *sdkmetric.ManualReader
meterProvider *sdkmetric.MeterProvider
Expand All @@ -44,6 +45,7 @@ func (tt *componentTestTelemetry) newTelemetrySettings() component.TelemetrySett
return set
}

// Deprecated: [v0.116.0] use metadatatest.SetupTestTelemetry
func setupTestTelemetry() componentTestTelemetry {
reader := sdkmetric.NewManualReader()
return componentTestTelemetry{
Expand Down
3 changes: 2 additions & 1 deletion cmd/mdatagen/internal/templates/telemetry.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
{{- end }}

"go.opentelemetry.io/otel/metric"
noopmetric "go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -128,7 +129,7 @@ func getLeveledMeter(meter metric.Meter, cfgLevel, srvLevel configtelemetry.Leve
if cfgLevel <= srvLevel {
return meter
}
return noop.Meter{}
return noopmetric.Meter{}
}

{{- end }}
1 change: 0 additions & 1 deletion cmd/mdatagen/internal/templates/telemetry_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configtelemetry"
)

type mockMeter struct {
Expand Down
Loading

0 comments on commit 22a7b42

Please sign in to comment.