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

Deprecate component_test in favor of metadatatest #11812

Merged
merged 1 commit into from
Jan 6, 2025
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
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 @@
if err = os.MkdirAll(codeDir, 0o700); 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, 0o700); err != nil {
return fmt.Errorf("unable to create output test directory %q: %w", codeDir, err)
}

Check warning on line 84 in cmd/mdatagen/internal/command.go

View check run for this annotation

Codecov / codecov/patch

cmd/mdatagen/internal/command.go#L83-L84

Added lines #L83 - L84 were not covered by tests
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 @@
}
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.SetupTelemetry()
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.117.0] use metadatatest.Telemetry
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.SetupTelemetry
func setupTestTelemetry() componentTestTelemetry {
reader := sdkmetric.NewManualReader()
return componentTestTelemetry{
Expand Down
5 changes: 4 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,9 @@ import (
{{- end }}

"go.opentelemetry.io/otel/metric"
{{- if .Telemetry.Metrics }}
noopmetric "go.opentelemetry.io/otel/metric/noop"
{{- end }}
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -128,7 +131,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
Loading