From b6a28a3d734d8dfd7ed87c6937b161f47c930a43 Mon Sep 17 00:00:00 2001 From: Braydon Kains <93549768+braydonk@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:15:23 -0400 Subject: [PATCH 1/7] aggregateutil: allow filtering against empty attribute set (#35006) **Description:** It is a valid use case to aggregate against an empty label set, which will functionally clear all attributes. This behaviour was removed in #33655, which simplified the check to `len() == 0`, which covers the case of the label set being `nil` and having 0 elements as the same scenario. However, these are not the same scenario and have different meanings. This PR reintroduces the original behaviour, but in a more efficient way by recognizing a label set with 0 elements and clearing the attributes, which would be the logical conclusion after running the filter anyway. **Link to tracking Issue:** #34430 **Testing:** **Documentation:** --------- Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> --- .chloggen/aggregate_labels_empty.yaml | 27 +++++++++++++++++ .../coreinternal/aggregateutil/aggregate.go | 14 ++++++++- .../aggregateutil/aggregate_test.go | 4 +-- .../metrics_testcase_builder_test.go | 9 +++++- .../metrics_transform_processor_otlp.go | 2 +- ...rics_transform_processor_testcases_test.go | 29 +++++++++++++++++++ 6 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 .chloggen/aggregate_labels_empty.yaml diff --git a/.chloggen/aggregate_labels_empty.yaml b/.chloggen/aggregate_labels_empty.yaml new file mode 100644 index 000000000000..a98c8ed4f3c1 --- /dev/null +++ b/.chloggen/aggregate_labels_empty.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: metricstransform + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: The previously removed functionality of aggregating against an empty label set is restored. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [34430] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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: [] diff --git a/internal/coreinternal/aggregateutil/aggregate.go b/internal/coreinternal/aggregateutil/aggregate.go index dcfe176be121..c7bc4613b716 100644 --- a/internal/coreinternal/aggregateutil/aggregate.go +++ b/internal/coreinternal/aggregateutil/aggregate.go @@ -33,9 +33,21 @@ func CopyMetricDetails(from, to pmetric.Metric) { } func FilterAttrs(metric pmetric.Metric, filterAttrKeys []string) { - if len(filterAttrKeys) == 0 { + // filterAttrKeys being nil means the filter is to be skipped. + if filterAttrKeys == nil { return } + // filterAttrKeys being empty means it is explicitly expected to filter + // against an empty label set, which is functionally the same as removing + // all attributes. + if len(filterAttrKeys) == 0 { + RangeDataPointAttributes(metric, func(attrs pcommon.Map) bool { + attrs.Clear() + return true + }) + } + // filterAttrKeys having provided attributes means the filter continues + // as normal. RangeDataPointAttributes(metric, func(attrs pcommon.Map) bool { attrs.RemoveIf(func(k string, _ pcommon.Value) bool { return isNotPresent(k, filterAttrKeys) diff --git a/internal/coreinternal/aggregateutil/aggregate_test.go b/internal/coreinternal/aggregateutil/aggregate_test.go index a1e986b988e2..642e44996dd8 100644 --- a/internal/coreinternal/aggregateutil/aggregate_test.go +++ b/internal/coreinternal/aggregateutil/aggregate_test.go @@ -125,9 +125,7 @@ func Test_FilterAttributes(t *testing.T) { want: func() pmetric.Metric { m := pmetric.NewMetric() s := m.SetEmptySum() - d := s.DataPoints().AppendEmpty() - d.Attributes().PutStr("attr1", "val1") - d.Attributes().PutStr("attr2", "val2") + s.DataPoints().AppendEmpty() return m }, }, diff --git a/processor/metricstransformprocessor/metrics_testcase_builder_test.go b/processor/metricstransformprocessor/metrics_testcase_builder_test.go index dc2142b2ca76..55579b24b8b4 100644 --- a/processor/metricstransformprocessor/metrics_testcase_builder_test.go +++ b/processor/metricstransformprocessor/metrics_testcase_builder_test.go @@ -4,6 +4,8 @@ package metricstransformprocessor import ( + "fmt" + "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -54,7 +56,12 @@ func (b builder) addDoubleDatapoint(start, ts pcommon.Timestamp, val float64, at func (b builder) setAttrs(attrs pcommon.Map, attrValues []string) { if len(attrValues) != len(b.attrs) { - panic(attrValues) + panic( + fmt.Sprintf( + "not enough attributes, expected %d attributes but got %s", + len(b.attrs), + attrValues), + ) } for i, a := range b.attrs { attrs.PutStr(a, attrValues[i]) diff --git a/processor/metricstransformprocessor/metrics_transform_processor_otlp.go b/processor/metricstransformprocessor/metrics_transform_processor_otlp.go index ad2e3b42c6e8..1d1abac32830 100644 --- a/processor/metricstransformprocessor/metrics_transform_processor_otlp.go +++ b/processor/metricstransformprocessor/metrics_transform_processor_otlp.go @@ -554,7 +554,7 @@ func transformMetric(metric pmetric.Metric, transform internalTransform) bool { updateLabelOp(metric, op, transform.MetricIncludeFilter) case aggregateLabels: if canChangeMetric { - attrs := []string{} + attrs := make([]string, 0, len(op.labelSetMap)) for k, v := range op.labelSetMap { if v { attrs = append(attrs, k) diff --git a/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go b/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go index cc6e5ff742d7..5d5191e57664 100644 --- a/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go +++ b/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go @@ -667,6 +667,35 @@ var ( build(), }, }, + { + name: "metric_label_aggregation_empty_label_set", + transforms: []internalTransform{ + { + MetricIncludeFilter: internalFilterStrict{include: "metric1"}, + Action: Update, + Operations: []internalOperation{ + { + configOperation: Operation{ + Action: aggregateLabels, + AggregationType: aggregateutil.Sum, + LabelSet: []string{}, + }, + labelSetMap: map[string]bool{}, + }, + }, + }, + }, + in: []pmetric.Metric{ + metricBuilder(pmetric.MetricTypeGauge, "metric1", "label1", "label2", "label3"). + addIntDatapoint(0, 1, 1, "a", "b", "c"). + build(), + }, + out: []pmetric.Metric{ + metricBuilder(pmetric.MetricTypeGauge, "metric1"). + addIntDatapoint(0, 1, 1). + build(), + }, + }, { name: "metric_label_aggregation_ignored_for_partial_metric_match", transforms: []internalTransform{ From 1e1a9450f7f9b0194050e55c934f3e41f4450fc1 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:31:36 -0700 Subject: [PATCH 2/7] [cmd/telemetrygen] ensure validate is called (#35745) Prior to this change, the Validate func wasn't being called resulting in wonky error messages like the following: ``` 2024-10-10T15:39:40.139-0700 INFO logs/worker.go:49 stopping the exporter {"worker": 0} panic: runtime error: cannot convert slice with length 8 to array or pointer to array with length 16 goroutine 6 [running]: github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/logs.worker.simulateLogs({0x140002404c4, 0x1, {0x100dd3152, 0xb}, 0x9, {0x100dccf6b, 0x4}, 0x0, 0x7fefffffffffffff, 0x140002404e0, ...}, ...) github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/logs/worker.go:70 +0xa34 created by github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/logs.Run in goroutine 1 ``` With the validation in place, we now get a useful error message: ``` Error: TraceID must be a 32 character hex string, like: 'ae87dadd90e9935a4bc9660628efd569' ``` --------- Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- .../codeboten_validate-telemetrygen.yaml | 27 +++++++++ cmd/telemetrygen/internal/logs/config.go | 6 ++ cmd/telemetrygen/internal/logs/logs.go | 7 ++- cmd/telemetrygen/internal/logs/worker_test.go | 52 ++++++++++++++++++ cmd/telemetrygen/internal/metrics/config.go | 6 ++ cmd/telemetrygen/internal/metrics/metrics.go | 7 ++- .../internal/metrics/worker_test.go | 55 +++++++++++++++++++ cmd/telemetrygen/internal/traces/config.go | 9 +++ cmd/telemetrygen/internal/traces/traces.go | 6 +- .../internal/traces/worker_test.go | 30 ++++++++++ 10 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 .chloggen/codeboten_validate-telemetrygen.yaml diff --git a/.chloggen/codeboten_validate-telemetrygen.yaml b/.chloggen/codeboten_validate-telemetrygen.yaml new file mode 100644 index 000000000000..8d8c19aaeec9 --- /dev/null +++ b/.chloggen/codeboten_validate-telemetrygen.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: telemetrygen + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: ensure validate is called + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35745] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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: [] diff --git a/cmd/telemetrygen/internal/logs/config.go b/cmd/telemetrygen/internal/logs/config.go index 6a619b51223b..dd17973bb66d 100644 --- a/cmd/telemetrygen/internal/logs/config.go +++ b/cmd/telemetrygen/internal/logs/config.go @@ -4,6 +4,8 @@ package logs import ( + "fmt" + "github.com/spf13/pflag" "github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/common" @@ -36,6 +38,10 @@ func (c *Config) Flags(fs *pflag.FlagSet) { // Validate validates the test scenario parameters. func (c *Config) Validate() error { + if c.TotalDuration <= 0 && c.NumLogs <= 0 { + return fmt.Errorf("either `logs` or `duration` must be greater than 0") + } + if c.TraceID != "" { if err := common.ValidateTraceID(c.TraceID); err != nil { return err diff --git a/cmd/telemetrygen/internal/logs/logs.go b/cmd/telemetrygen/internal/logs/logs.go index 3132b0bc5f5a..ff428fc93e1b 100644 --- a/cmd/telemetrygen/internal/logs/logs.go +++ b/cmd/telemetrygen/internal/logs/logs.go @@ -60,7 +60,6 @@ func Start(cfg *Config) error { } if err = Run(cfg, expFunc, logger); err != nil { - logger.Error("failed to stop the exporter", zap.Error(err)) return err } @@ -69,10 +68,12 @@ func Start(cfg *Config) error { // Run executes the test scenario. func Run(c *Config, exp func() (sdklog.Exporter, error), logger *zap.Logger) error { + if err := c.Validate(); err != nil { + return err + } + if c.TotalDuration > 0 { c.NumLogs = 0 - } else if c.NumLogs <= 0 { - return fmt.Errorf("either `logs` or `duration` must be greater than 0") } limit := rate.Limit(c.Rate) diff --git a/cmd/telemetrygen/internal/logs/worker_test.go b/cmd/telemetrygen/internal/logs/worker_test.go index 3e759b606154..2d1095afe326 100644 --- a/cmd/telemetrygen/internal/logs/worker_test.go +++ b/cmd/telemetrygen/internal/logs/worker_test.go @@ -229,6 +229,58 @@ func TestLogsWithTraceIDAndSpanID(t *testing.T) { } } +func TestValidate(t *testing.T) { + tests := []struct { + name string + cfg *Config + wantErrMessage string + }{ + { + name: "No duration or NumLogs", + cfg: &Config{ + Config: common.Config{ + WorkerCount: 1, + }, + TraceID: "123", + }, + wantErrMessage: "either `logs` or `duration` must be greater than 0", + }, + { + name: "TraceID invalid", + cfg: &Config{ + Config: common.Config{ + WorkerCount: 1, + }, + NumLogs: 5, + TraceID: "123", + }, + wantErrMessage: "TraceID must be a 32 character hex string, like: 'ae87dadd90e9935a4bc9660628efd569'", + }, + { + name: "SpanID invalid", + cfg: &Config{ + Config: common.Config{ + WorkerCount: 1, + }, + NumLogs: 5, + TraceID: "ae87dadd90e9935a4bc9660628efd569", + SpanID: "123", + }, + wantErrMessage: "SpanID must be a 16 character hex string, like: '5828fa4960140870'", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &mockExporter{} + expFunc := func() (sdklog.Exporter, error) { + return m, nil + } + logger, _ := zap.NewDevelopment() + require.EqualError(t, Run(tt.cfg, expFunc, logger), tt.wantErrMessage) + }) + } +} + func configWithNoAttributes(qty int, body string) *Config { return &Config{ Body: body, diff --git a/cmd/telemetrygen/internal/metrics/config.go b/cmd/telemetrygen/internal/metrics/config.go index cab4633d28fb..fd8f2c4e9aa0 100644 --- a/cmd/telemetrygen/internal/metrics/config.go +++ b/cmd/telemetrygen/internal/metrics/config.go @@ -4,6 +4,8 @@ package metrics import ( + "fmt" + "github.com/spf13/pflag" "github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/common" @@ -39,6 +41,10 @@ func (c *Config) Flags(fs *pflag.FlagSet) { // Validate validates the test scenario parameters. func (c *Config) Validate() error { + if c.TotalDuration <= 0 && c.NumMetrics <= 0 { + return fmt.Errorf("either `metrics` or `duration` must be greater than 0") + } + if c.TraceID != "" { if err := common.ValidateTraceID(c.TraceID); err != nil { return err diff --git a/cmd/telemetrygen/internal/metrics/metrics.go b/cmd/telemetrygen/internal/metrics/metrics.go index 837f8f6ee711..baed4c4b5362 100644 --- a/cmd/telemetrygen/internal/metrics/metrics.go +++ b/cmd/telemetrygen/internal/metrics/metrics.go @@ -62,7 +62,6 @@ func Start(cfg *Config) error { } if err = Run(cfg, expFunc, logger); err != nil { - logger.Error("failed to stop the exporter", zap.Error(err)) return err } @@ -71,10 +70,12 @@ func Start(cfg *Config) error { // Run executes the test scenario. func Run(c *Config, exp func() (sdkmetric.Exporter, error), logger *zap.Logger) error { + if err := c.Validate(); err != nil { + return err + } + if c.TotalDuration > 0 { c.NumMetrics = 0 - } else if c.NumMetrics <= 0 { - return fmt.Errorf("either `metrics` or `duration` must be greater than 0") } limit := rate.Limit(c.Rate) diff --git a/cmd/telemetrygen/internal/metrics/worker_test.go b/cmd/telemetrygen/internal/metrics/worker_test.go index 67539d5f009a..7574ac203757 100644 --- a/cmd/telemetrygen/internal/metrics/worker_test.go +++ b/cmd/telemetrygen/internal/metrics/worker_test.go @@ -300,6 +300,61 @@ func TestGaugeMultipleTelemetryAttr(t *testing.T) { } } +func TestValidate(t *testing.T) { + tests := []struct { + name string + cfg *Config + wantErrMessage string + }{ + { + name: "No duration or NumMetrics", + cfg: &Config{ + Config: common.Config{ + WorkerCount: 1, + }, + MetricType: metricTypeSum, + TraceID: "123", + }, + wantErrMessage: "either `metrics` or `duration` must be greater than 0", + }, + { + name: "TraceID invalid", + cfg: &Config{ + Config: common.Config{ + WorkerCount: 1, + }, + NumMetrics: 5, + MetricType: metricTypeSum, + TraceID: "123", + }, + wantErrMessage: "TraceID must be a 32 character hex string, like: 'ae87dadd90e9935a4bc9660628efd569'", + }, + { + name: "SpanID invalid", + cfg: &Config{ + Config: common.Config{ + WorkerCount: 1, + }, + NumMetrics: 5, + MetricType: metricTypeSum, + TraceID: "ae87dadd90e9935a4bc9660628efd569", + SpanID: "123", + }, + wantErrMessage: "SpanID must be a 16 character hex string, like: '5828fa4960140870'", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &mockExporter{} + expFunc := func() (sdkmetric.Exporter, error) { + return m, nil + } + logger, _ := zap.NewDevelopment() + require.EqualError(t, Run(tt.cfg, expFunc, logger), tt.wantErrMessage) + }) + } +} + func configWithNoAttributes(metric metricType, qty int) *Config { return &Config{ Config: common.Config{ diff --git a/cmd/telemetrygen/internal/traces/config.go b/cmd/telemetrygen/internal/traces/config.go index 7b553b3cf04c..5bb63dffbd9a 100644 --- a/cmd/telemetrygen/internal/traces/config.go +++ b/cmd/telemetrygen/internal/traces/config.go @@ -4,6 +4,7 @@ package traces import ( + "fmt" "time" "github.com/spf13/pflag" @@ -40,3 +41,11 @@ func (c *Config) Flags(fs *pflag.FlagSet) { fs.IntVar(&c.LoadSize, "size", 0, "Desired minimum size in MB of string data for each trace generated. This can be used to test traces with large payloads, i.e. when testing the OTLP receiver endpoint max receive size.") fs.DurationVar(&c.SpanDuration, "span-duration", 123*time.Microsecond, "The duration of each generated span.") } + +// Validate validates the test scenario parameters. +func (c *Config) Validate() error { + if c.TotalDuration <= 0 && c.NumTraces <= 0 { + return fmt.Errorf("either `traces` or `duration` must be greater than 0") + } + return nil +} diff --git a/cmd/telemetrygen/internal/traces/traces.go b/cmd/telemetrygen/internal/traces/traces.go index 02817577b915..29c0aacc5d27 100644 --- a/cmd/telemetrygen/internal/traces/traces.go +++ b/cmd/telemetrygen/internal/traces/traces.go @@ -102,10 +102,12 @@ func Start(cfg *Config) error { // Run executes the test scenario. func Run(c *Config, logger *zap.Logger) error { + if err := c.Validate(); err != nil { + return err + } + if c.TotalDuration > 0 { c.NumTraces = 0 - } else if c.NumTraces <= 0 { - return fmt.Errorf("either `traces` or `duration` must be greater than 0") } limit := rate.Limit(c.Rate) diff --git a/cmd/telemetrygen/internal/traces/worker_test.go b/cmd/telemetrygen/internal/traces/worker_test.go index 70bb90ee164e..3f9e7ec8070e 100644 --- a/cmd/telemetrygen/internal/traces/worker_test.go +++ b/cmd/telemetrygen/internal/traces/worker_test.go @@ -310,6 +310,36 @@ func TestSpansWithMultipleAttrs(t *testing.T) { } } +func TestValidate(t *testing.T) { + tests := []struct { + name string + cfg *Config + wantErrMessage string + }{ + { + name: "No duration or NumTraces", + cfg: &Config{ + Config: common.Config{ + WorkerCount: 1, + }, + }, + wantErrMessage: "either `traces` or `duration` must be greater than 0", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + syncer := &mockSyncer{} + + tracerProvider := sdktrace.NewTracerProvider() + sp := sdktrace.NewSimpleSpanProcessor(syncer) + tracerProvider.RegisterSpanProcessor(sp) + otel.SetTracerProvider(tracerProvider) + logger, _ := zap.NewDevelopment() + require.EqualError(t, Run(tt.cfg, logger), tt.wantErrMessage) + }) + } +} + var _ sdktrace.SpanExporter = (*mockSyncer)(nil) type mockSyncer struct { From 18a598fbac881d92ce1ba06d2af57bbe4080309a Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 14 Oct 2024 02:30:38 -0700 Subject: [PATCH 3/7] Fix codeowners (#35754) Fix the allowlist to match memberships. --- cmd/githubgen/allowlist.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/githubgen/allowlist.txt b/cmd/githubgen/allowlist.txt index 0aad99b3ac17..6ba509caff99 100644 --- a/cmd/githubgen/allowlist.txt +++ b/cmd/githubgen/allowlist.txt @@ -23,4 +23,4 @@ m1rp jriguera abhishek-at-cloudwerx joker-star-l -ArthurSens \ No newline at end of file +michael-burt \ No newline at end of file From 5221a7a8774b855bb7898e3594f460290476dcdc Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Mon, 14 Oct 2024 17:52:35 +0800 Subject: [PATCH 4/7] telemetrygen: wire up InsecureSkipVerify (#35735) #### Description Thread the InsecureSkipVerify config through properly, so the relevant `tls.Config` struct field is set. Previously, The `--otlp-insecure-skip-verify` flag wasn't effective. I feel like we'd be better off using https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/exporters/autoexport and configuring these things with environment variables, instead of defining flags. I will open an issue for that. #### Link to tracking issue None #### Testing I have added a test that shows the HTTP exporter honours the Insecure, InsecureSkipVerify, and CaFile config fields. I have not done the same for gRPC due to lack of time - this can be done as a followup. OTOH the logic for HTTP & gRPC exporter options shares more now, so the HTTP path tests a fair bit of what gRPC will do anyway. --- .../telemetrygen-insecureskipverify.yaml | 27 ++++ cmd/telemetrygen/go.mod | 2 +- cmd/telemetrygen/internal/common/tls_utils.go | 58 +++----- cmd/telemetrygen/internal/logs/exporter.go | 8 +- cmd/telemetrygen/internal/metrics/exporter.go | 8 +- cmd/telemetrygen/internal/traces/exporter.go | 8 +- .../internal/traces/exporter_test.go | 137 ++++++++++++++++++ 7 files changed, 204 insertions(+), 44 deletions(-) create mode 100644 .chloggen/telemetrygen-insecureskipverify.yaml create mode 100644 cmd/telemetrygen/internal/traces/exporter_test.go diff --git a/.chloggen/telemetrygen-insecureskipverify.yaml b/.chloggen/telemetrygen-insecureskipverify.yaml new file mode 100644 index 000000000000..a1debf677268 --- /dev/null +++ b/.chloggen/telemetrygen-insecureskipverify.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: telemetrygen + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Enable the `--otlp-insecure-skip-verify` flag + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35735] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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: [user] diff --git a/cmd/telemetrygen/go.mod b/cmd/telemetrygen/go.mod index 7181398c24d3..2dcf1cd100bf 100644 --- a/cmd/telemetrygen/go.mod +++ b/cmd/telemetrygen/go.mod @@ -23,6 +23,7 @@ require ( go.opentelemetry.io/otel/sdk/log v0.6.0 go.opentelemetry.io/otel/sdk/metric v1.30.0 go.opentelemetry.io/otel/trace v1.30.0 + go.opentelemetry.io/proto/otlp v1.3.1 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 golang.org/x/time v0.7.0 @@ -45,7 +46,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect - go.opentelemetry.io/proto/otlp v1.3.1 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.29.0 // indirect golang.org/x/sys v0.25.0 // indirect diff --git a/cmd/telemetrygen/internal/common/tls_utils.go b/cmd/telemetrygen/internal/common/tls_utils.go index 286d7345adc1..6759541ec508 100644 --- a/cmd/telemetrygen/internal/common/tls_utils.go +++ b/cmd/telemetrygen/internal/common/tls_utils.go @@ -28,52 +28,37 @@ func caPool(caFile string) (*x509.CertPool, error) { return pool, nil } -func GetTLSCredentialsForGRPCExporter(caFile string, cAuth ClientAuth) (credentials.TransportCredentials, error) { - - pool, err := caPool(caFile) +func GetTLSCredentialsForGRPCExporter( + caFile string, + cAuth ClientAuth, + insecureSkipVerify bool, +) (credentials.TransportCredentials, error) { + tlsConfig, err := getTLSConfig(caFile, cAuth, insecureSkipVerify) if err != nil { return nil, err } + return credentials.NewTLS(tlsConfig), nil +} - var creds credentials.TransportCredentials - - if caFile != "" { - creds = credentials.NewTLS(&tls.Config{ - RootCAs: pool, - }) - } else { - creds = credentials.NewTLS(&tls.Config{}) - } - - // Configuration for mTLS - if cAuth.Enabled { - keypair, err := tls.LoadX509KeyPair(cAuth.ClientCertFile, cAuth.ClientKeyFile) - if err != nil { - return nil, err - } - creds = credentials.NewTLS(&tls.Config{ - RootCAs: pool, - Certificates: []tls.Certificate{keypair}, - }) - } - - return creds, nil +func GetTLSCredentialsForHTTPExporter( + caFile string, + cAuth ClientAuth, + insecureSkipVerify bool, +) (*tls.Config, error) { + return getTLSConfig(caFile, cAuth, insecureSkipVerify) } -func GetTLSCredentialsForHTTPExporter(caFile string, cAuth ClientAuth) (*tls.Config, error) { - pool, err := caPool(caFile) - if err != nil { - return nil, err +func getTLSConfig(caFile string, cAuth ClientAuth, insecureSkipVerify bool) (*tls.Config, error) { + tlsCfg := tls.Config{ + InsecureSkipVerify: insecureSkipVerify, } - var tlsCfg tls.Config - if caFile != "" { - tlsCfg = tls.Config{ - RootCAs: pool, + pool, err := caPool(caFile) + if err != nil { + return nil, err } - } else { - tlsCfg = tls.Config{} + tlsCfg.RootCAs = pool } // Configuration for mTLS @@ -82,7 +67,6 @@ func GetTLSCredentialsForHTTPExporter(caFile string, cAuth ClientAuth) (*tls.Con if err != nil { return nil, err } - tlsCfg.ClientAuth = tls.RequireAndVerifyClientCert tlsCfg.Certificates = []tls.Certificate{keypair} } return &tlsCfg, nil diff --git a/cmd/telemetrygen/internal/logs/exporter.go b/cmd/telemetrygen/internal/logs/exporter.go index 37df9ac9ac76..9543a45370cd 100644 --- a/cmd/telemetrygen/internal/logs/exporter.go +++ b/cmd/telemetrygen/internal/logs/exporter.go @@ -22,7 +22,9 @@ func grpcExporterOptions(cfg *Config) ([]otlploggrpc.Option, error) { if cfg.Insecure { grpcExpOpt = append(grpcExpOpt, otlploggrpc.WithInsecure()) } else { - credentials, err := common.GetTLSCredentialsForGRPCExporter(cfg.CaFile, cfg.ClientAuth) + credentials, err := common.GetTLSCredentialsForGRPCExporter( + cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify, + ) if err != nil { return nil, fmt.Errorf("failed to get TLS credentials: %w", err) } @@ -47,7 +49,9 @@ func httpExporterOptions(cfg *Config) ([]otlploghttp.Option, error) { if cfg.Insecure { httpExpOpt = append(httpExpOpt, otlploghttp.WithInsecure()) } else { - tlsCfg, err := common.GetTLSCredentialsForHTTPExporter(cfg.CaFile, cfg.ClientAuth) + tlsCfg, err := common.GetTLSCredentialsForHTTPExporter( + cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify, + ) if err != nil { return nil, fmt.Errorf("failed to get TLS credentials: %w", err) } diff --git a/cmd/telemetrygen/internal/metrics/exporter.go b/cmd/telemetrygen/internal/metrics/exporter.go index 1933c6aea73e..d8323ffbebd0 100644 --- a/cmd/telemetrygen/internal/metrics/exporter.go +++ b/cmd/telemetrygen/internal/metrics/exporter.go @@ -22,7 +22,9 @@ func grpcExporterOptions(cfg *Config) ([]otlpmetricgrpc.Option, error) { if cfg.Insecure { grpcExpOpt = append(grpcExpOpt, otlpmetricgrpc.WithInsecure()) } else { - credentials, err := common.GetTLSCredentialsForGRPCExporter(cfg.CaFile, cfg.ClientAuth) + credentials, err := common.GetTLSCredentialsForGRPCExporter( + cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify, + ) if err != nil { return nil, fmt.Errorf("failed to get TLS credentials: %w", err) } @@ -47,7 +49,9 @@ func httpExporterOptions(cfg *Config) ([]otlpmetrichttp.Option, error) { if cfg.Insecure { httpExpOpt = append(httpExpOpt, otlpmetrichttp.WithInsecure()) } else { - tlsCfg, err := common.GetTLSCredentialsForHTTPExporter(cfg.CaFile, cfg.ClientAuth) + tlsCfg, err := common.GetTLSCredentialsForHTTPExporter( + cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify, + ) if err != nil { return nil, fmt.Errorf("failed to get TLS credentials: %w", err) } diff --git a/cmd/telemetrygen/internal/traces/exporter.go b/cmd/telemetrygen/internal/traces/exporter.go index 8dfb3e51d502..4d75c36635c3 100644 --- a/cmd/telemetrygen/internal/traces/exporter.go +++ b/cmd/telemetrygen/internal/traces/exporter.go @@ -22,7 +22,9 @@ func grpcExporterOptions(cfg *Config) ([]otlptracegrpc.Option, error) { if cfg.Insecure { grpcExpOpt = append(grpcExpOpt, otlptracegrpc.WithInsecure()) } else { - credentials, err := common.GetTLSCredentialsForGRPCExporter(cfg.CaFile, cfg.ClientAuth) + credentials, err := common.GetTLSCredentialsForGRPCExporter( + cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify, + ) if err != nil { return nil, fmt.Errorf("failed to get TLS credentials: %w", err) } @@ -47,7 +49,9 @@ func httpExporterOptions(cfg *Config) ([]otlptracehttp.Option, error) { if cfg.Insecure { httpExpOpt = append(httpExpOpt, otlptracehttp.WithInsecure()) } else { - tlsCfg, err := common.GetTLSCredentialsForHTTPExporter(cfg.CaFile, cfg.ClientAuth) + tlsCfg, err := common.GetTLSCredentialsForHTTPExporter( + cfg.CaFile, cfg.ClientAuth, cfg.InsecureSkipVerify, + ) if err != nil { return nil, fmt.Errorf("failed to get TLS credentials: %w", err) } diff --git a/cmd/telemetrygen/internal/traces/exporter_test.go b/cmd/telemetrygen/internal/traces/exporter_test.go new file mode 100644 index 000000000000..b8af7442c836 --- /dev/null +++ b/cmd/telemetrygen/internal/traces/exporter_test.go @@ -0,0 +1,137 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package traces + +import ( + "context" + "encoding/pem" + "net/http" + "net/http/httptest" + "net/url" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" + tracepb "go.opentelemetry.io/proto/otlp/trace/v1" + + "github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/common" +) + +func TestHTTPExporterOptions_TLS(t *testing.T) { + // TODO add test cases for mTLS + for name, tc := range map[string]struct { + tls bool + tlsServerCA bool // use the httptest.Server's TLS cert as the CA + cfg Config + + expectTransportError bool + }{ + "Insecure": { + tls: false, + cfg: Config{Config: common.Config{Insecure: true}}, + }, + "InsecureSkipVerify": { + tls: true, + cfg: Config{Config: common.Config{InsecureSkipVerify: true}}, + }, + "InsecureSkipVerifyDisabled": { + tls: true, + expectTransportError: true, + }, + "CaFile": { + tls: true, + tlsServerCA: true, + }, + } { + t.Run(name, func(t *testing.T) { + var called bool + var h http.HandlerFunc = func(http.ResponseWriter, *http.Request) { + called = true + } + var srv *httptest.Server + if tc.tls { + srv = httptest.NewTLSServer(h) + } else { + srv = httptest.NewServer(h) + } + defer srv.Close() + srvURL, _ := url.Parse(srv.URL) + + cfg := tc.cfg + cfg.CustomEndpoint = srvURL.Host + if tc.tlsServerCA { + caFile := filepath.Join(t.TempDir(), "cert.pem") + err := os.WriteFile(caFile, pem.EncodeToMemory(&pem.Block{ + Type: "CERTIFICATE", + Bytes: srv.TLS.Certificates[0].Certificate[0], + }), 0600) + require.NoError(t, err) + cfg.CaFile = caFile + } + + opts, err := httpExporterOptions(&cfg) + require.NoError(t, err) + client := otlptracehttp.NewClient(opts...) + + err = client.UploadTraces(context.Background(), []*tracepb.ResourceSpans{}) + if tc.expectTransportError { + require.Error(t, err) + assert.False(t, called) + } else { + require.NoError(t, err) + assert.True(t, called) + } + }) + } +} + +func TestHTTPExporterOptions_HTTP(t *testing.T) { + for name, tc := range map[string]struct { + cfg Config + + expectedHTTPPath string + expectedHeader http.Header + }{ + "HTTPPath": { + cfg: Config{Config: common.Config{HTTPPath: "/foo"}}, + expectedHTTPPath: "/foo", + }, + "Headers": { + cfg: Config{ + Config: common.Config{Headers: map[string]any{"a": "b"}}, + }, + expectedHTTPPath: "/v1/traces", + expectedHeader: http.Header{"a": []string{"b"}}, + }, + } { + t.Run(name, func(t *testing.T) { + var httpPath string + var header http.Header + var h http.HandlerFunc = func(_ http.ResponseWriter, r *http.Request) { + httpPath = r.URL.Path + header = r.Header + } + srv := httptest.NewServer(h) + defer srv.Close() + srvURL, _ := url.Parse(srv.URL) + + cfg := tc.cfg + cfg.Insecure = true + cfg.CustomEndpoint = srvURL.Host + opts, err := httpExporterOptions(&cfg) + require.NoError(t, err) + client := otlptracehttp.NewClient(opts...) + + err = client.UploadTraces(context.Background(), []*tracepb.ResourceSpans{}) + require.NoError(t, err) + assert.Equal(t, tc.expectedHTTPPath, httpPath) + for k, expected := range tc.expectedHeader { + assert.Equal(t, expected, []string{header.Get(k)}) + } + }) + } +} From 0a6bb8a5a573408c9aa3e5949a413e721d3f832f Mon Sep 17 00:00:00 2001 From: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:18:58 +0530 Subject: [PATCH 5/7] [stanza/input/windows]: fix remote session leak while resubscribing (#35696) Stop the remote session before starting a new one while resubscribing. Closes https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35577 --- .../stanza-windows-remote-session-leak.yaml | 27 +++++++++++++++++++ pkg/stanza/operator/input/windows/input.go | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 .chloggen/stanza-windows-remote-session-leak.yaml diff --git a/.chloggen/stanza-windows-remote-session-leak.yaml b/.chloggen/stanza-windows-remote-session-leak.yaml new file mode 100644 index 000000000000..96200a5659f5 --- /dev/null +++ b/.chloggen/stanza-windows-remote-session-leak.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: stanza/input/windows + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Close remote session while resubscribing + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35577] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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: [] diff --git a/pkg/stanza/operator/input/windows/input.go b/pkg/stanza/operator/input/windows/input.go index 312709fc863e..e0324826e43f 100644 --- a/pkg/stanza/operator/input/windows/input.go +++ b/pkg/stanza/operator/input/windows/input.go @@ -201,6 +201,9 @@ func (i *Input) read(ctx context.Context) { i.Logger().Error("Failed to close remote subscription", zap.Error(closeErr)) return } + if err := i.stopRemoteSession(); err != nil { + i.Logger().Error("Failed to close remote session", zap.Error(err)) + } i.Logger().Info("Resubscribing, creating remote subscription") i.subscription = NewRemoteSubscription(i.remote.Server) if err := i.startRemoteSession(); err != nil { From 9b944d6ebd5612f5b3f74275febeea544157ca6d Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 14 Oct 2024 11:18:12 -0700 Subject: [PATCH 6/7] [chore] Remove unnecessary Host implementation funcs (#35773) Signed-off-by: Bogdan Drutu --- exporter/awss3exporter/go.mod | 2 +- exporter/awss3exporter/marshaler_test.go | 17 ----------------- exporter/elasticsearchexporter/exporter_test.go | 9 --------- exporter/elasticsearchexporter/go.mod | 2 +- exporter/fileexporter/encoding_test.go | 9 --------- exporter/fileexporter/go.mod | 2 +- exporter/rabbitmqexporter/go.mod | 2 +- exporter/rabbitmqexporter/marshaler_test.go | 9 --------- extension/awsproxy/factory_test.go | 9 --------- extension/awsproxy/go.mod | 2 +- .../observer/ecsobserver/extension_test.go | 9 --------- extension/observer/ecsobserver/go.mod | 2 +- .../k8sattributesprocessor/processor_test.go | 9 --------- receiver/awss3receiver/go.mod | 2 +- receiver/awss3receiver/receiver_test.go | 17 ----------------- receiver/carbonreceiver/go.mod | 2 +- receiver/carbonreceiver/receiver_test.go | 9 --------- .../dockerstatsreceiver/integration_test.go | 9 --------- .../receivercreator/observerhandler_test.go | 14 -------------- receiver/sapmreceiver/trace_receiver_test.go | 9 --------- receiver/signalfxreceiver/receiver_test.go | 9 --------- receiver/splunkhecreceiver/go.mod | 2 +- receiver/splunkhecreceiver/receiver_test.go | 9 --------- 23 files changed, 9 insertions(+), 156 deletions(-) diff --git a/exporter/awss3exporter/go.mod b/exporter/awss3exporter/go.mod index 0a7cc6e16292..c8c581622939 100644 --- a/exporter/awss3exporter/go.mod +++ b/exporter/awss3exporter/go.mod @@ -12,7 +12,6 @@ require ( go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/otelcol/otelcoltest v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 @@ -80,6 +79,7 @@ require ( go.opentelemetry.io/collector/otelcol v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/testdata v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/processor v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/processor/processorprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect diff --git a/exporter/awss3exporter/marshaler_test.go b/exporter/awss3exporter/marshaler_test.go index 5f5a9f799eb4..0f651fa87cc3 100644 --- a/exporter/awss3exporter/marshaler_test.go +++ b/exporter/awss3exporter/marshaler_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/pipeline" "go.uber.org/zap" ) @@ -51,28 +50,12 @@ type hostWithExtensions struct { encoding encodingExtension } -func (h hostWithExtensions) Start(context.Context, component.Host) error { - panic("unsupported") -} - -func (h hostWithExtensions) Shutdown(context.Context) error { - panic("unsupported") -} - -func (h hostWithExtensions) GetFactory(component.Kind, component.Type) component.Factory { - panic("unsupported") -} - func (h hostWithExtensions) GetExtensions() map[component.ID]component.Component { return map[component.ID]component.Component{ component.MustNewID("foo"): h.encoding, } } -func (h hostWithExtensions) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - panic("unsupported") -} - type encodingExtension struct { } diff --git a/exporter/elasticsearchexporter/exporter_test.go b/exporter/elasticsearchexporter/exporter_test.go index 77ff8e2d0b47..413853cfcd51 100644 --- a/exporter/elasticsearchexporter/exporter_test.go +++ b/exporter/elasticsearchexporter/exporter_test.go @@ -30,7 +30,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/pipeline" ) func TestExporterLogs(t *testing.T) { @@ -1600,18 +1599,10 @@ type mockHost struct { extensions map[component.ID]component.Component } -func (h *mockHost) GetFactory(kind component.Kind, typ component.Type) component.Factory { - panic(fmt.Errorf("expected call to GetFactory(%v, %v)", kind, typ)) -} - func (h *mockHost) GetExtensions() map[component.ID]component.Component { return h.extensions } -func (h *mockHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - panic(fmt.Errorf("expected call to GetExporters")) -} - type roundTripperFunc func(*http.Request) (*http.Response, error) func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) { diff --git a/exporter/elasticsearchexporter/go.mod b/exporter/elasticsearchexporter/go.mod index 2c17dd8e390d..f161860974f0 100644 --- a/exporter/elasticsearchexporter/go.mod +++ b/exporter/elasticsearchexporter/go.mod @@ -22,7 +22,6 @@ require ( go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/extension/auth v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/semconv v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 @@ -74,6 +73,7 @@ require ( go.opentelemetry.io/collector/extension/experimental/storage v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect diff --git a/exporter/fileexporter/encoding_test.go b/exporter/fileexporter/encoding_test.go index 17c783950aab..cf43b24ab896 100644 --- a/exporter/fileexporter/encoding_test.go +++ b/exporter/fileexporter/encoding_test.go @@ -19,7 +19,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/pipeline" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/otlpencodingextension" ) @@ -28,18 +27,10 @@ type hostWithEncoding struct { encodings map[component.ID]component.Component } -func (h hostWithEncoding) GetFactory(_ component.Kind, _ component.Type) component.Factory { - panic("unsupported") -} - func (h hostWithEncoding) GetExtensions() map[component.ID]component.Component { return h.encodings } -func (h hostWithEncoding) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - panic("unsupported") -} - func TestEncoding(t *testing.T) { f := NewFactory() cfg := f.CreateDefaultConfig().(*Config) diff --git a/exporter/fileexporter/go.mod b/exporter/fileexporter/go.mod index 296b6f13df6a..87dc1924a473 100644 --- a/exporter/fileexporter/go.mod +++ b/exporter/fileexporter/go.mod @@ -15,7 +15,6 @@ require ( go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/extension v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 @@ -48,6 +47,7 @@ require ( go.opentelemetry.io/collector/extension/experimental/storage v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/otel v1.30.0 // indirect diff --git a/exporter/rabbitmqexporter/go.mod b/exporter/rabbitmqexporter/go.mod index dd197de16aea..a26944139d4b 100644 --- a/exporter/rabbitmqexporter/go.mod +++ b/exporter/rabbitmqexporter/go.mod @@ -15,7 +15,6 @@ require ( go.opentelemetry.io/collector/consumer v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 ) @@ -81,6 +80,7 @@ require ( go.opentelemetry.io/collector/extension/experimental/storage v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect diff --git a/exporter/rabbitmqexporter/marshaler_test.go b/exporter/rabbitmqexporter/marshaler_test.go index 71b8cba66acf..4253b908a260 100644 --- a/exporter/rabbitmqexporter/marshaler_test.go +++ b/exporter/rabbitmqexporter/marshaler_test.go @@ -13,7 +13,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/pipeline" ) func TestMarshalUsingEncodingExtension(t *testing.T) { @@ -40,14 +39,6 @@ type mockEncodingExtension struct { mock.Mock } -func (h *mockHostWithEncodings) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - -func (h *mockHostWithEncodings) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (h *mockHostWithEncodings) GetExtensions() map[component.ID]component.Component { args := h.Called() return args.Get(0).(map[component.ID]component.Component) diff --git a/extension/awsproxy/factory_test.go b/extension/awsproxy/factory_test.go index 5a2f27a294c9..ab6d5fe5ce29 100644 --- a/extension/awsproxy/factory_test.go +++ b/extension/awsproxy/factory_test.go @@ -19,7 +19,6 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/extension/extensiontest" - "go.opentelemetry.io/collector/pipeline" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" @@ -101,18 +100,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/extension/awsproxy/go.mod b/extension/awsproxy/go.mod index 1b5bf4dddac0..29d104672940 100644 --- a/extension/awsproxy/go.mod +++ b/extension/awsproxy/go.mod @@ -12,7 +12,6 @@ require ( go.opentelemetry.io/collector/config/configtls v1.17.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/confmap v1.17.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/extension v0.111.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/zap v1.27.0 ) @@ -38,6 +37,7 @@ require ( go.opentelemetry.io/collector/featuregate v1.17.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/otel v1.30.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/otel/sdk v1.30.0 // indirect diff --git a/extension/observer/ecsobserver/extension_test.go b/extension/observer/ecsobserver/extension_test.go index c6a1adc1d994..491dfc830ae5 100644 --- a/extension/observer/ecsobserver/extension_test.go +++ b/extension/observer/ecsobserver/extension_test.go @@ -14,7 +14,6 @@ import ( "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/extension/extensiontest" - "go.opentelemetry.io/collector/pipeline" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/ecsobserver/internal/ecsmock" @@ -82,18 +81,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/extension/observer/ecsobserver/go.mod b/extension/observer/ecsobserver/go.mod index b2c7ef7de011..c5539879449f 100644 --- a/extension/observer/ecsobserver/go.mod +++ b/extension/observer/ecsobserver/go.mod @@ -10,7 +10,6 @@ require ( go.opentelemetry.io/collector/component/componentstatus v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/confmap v1.17.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/extension v0.111.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 @@ -34,6 +33,7 @@ require ( go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/otel v1.30.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/otel/sdk v1.30.0 // indirect diff --git a/processor/k8sattributesprocessor/processor_test.go b/processor/k8sattributesprocessor/processor_test.go index d97721691c45..4f9e8701b348 100644 --- a/processor/k8sattributesprocessor/processor_test.go +++ b/processor/k8sattributesprocessor/processor_test.go @@ -22,7 +22,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/processor" "go.opentelemetry.io/collector/processor/processortest" conventions "go.opentelemetry.io/collector/semconv/v1.8.0" @@ -1570,18 +1569,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/receiver/awss3receiver/go.mod b/receiver/awss3receiver/go.mod index 367b3da26481..e034d170d14b 100644 --- a/receiver/awss3receiver/go.mod +++ b/receiver/awss3receiver/go.mod @@ -15,7 +15,6 @@ require ( go.opentelemetry.io/collector/consumer v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/consumer/consumertest v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/semconv v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 @@ -59,6 +58,7 @@ require ( go.opentelemetry.io/collector/consumer/consumerprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/otel v1.30.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect diff --git a/receiver/awss3receiver/receiver_test.go b/receiver/awss3receiver/receiver_test.go index d262e6f1d6cf..0ca8534e48d9 100644 --- a/receiver/awss3receiver/receiver_test.go +++ b/receiver/awss3receiver/receiver_test.go @@ -17,7 +17,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/receiver/receiverhelper" "go.opentelemetry.io/collector/receiver/receivertest" conventions "go.opentelemetry.io/collector/semconv/v1.22.0" @@ -68,26 +67,10 @@ type hostWithExtensions struct { extensions map[component.ID]component.Component } -func (h hostWithExtensions) Start(context.Context, component.Host) error { - panic("unsupported") -} - -func (h hostWithExtensions) Shutdown(context.Context) error { - panic("unsupported") -} - -func (h hostWithExtensions) GetFactory(component.Kind, component.Type) component.Factory { - panic("unsupported") -} - func (h hostWithExtensions) GetExtensions() map[component.ID]component.Component { return h.extensions } -func (h hostWithExtensions) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - panic("unsupported") -} - type nonEncodingExtension struct{} func (e nonEncodingExtension) Start(_ context.Context, _ component.Host) error { diff --git a/receiver/carbonreceiver/go.mod b/receiver/carbonreceiver/go.mod index 8218044255c2..47f5dfbebe5b 100644 --- a/receiver/carbonreceiver/go.mod +++ b/receiver/carbonreceiver/go.mod @@ -12,7 +12,6 @@ require ( go.opentelemetry.io/collector/consumer v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/consumer/consumertest v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/otel/sdk v1.30.0 go.opentelemetry.io/otel/trace v1.30.0 @@ -43,6 +42,7 @@ require ( go.opentelemetry.io/collector/featuregate v1.17.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/otel v1.30.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect diff --git a/receiver/carbonreceiver/receiver_test.go b/receiver/carbonreceiver/receiver_test.go index 746fdb6ed1f9..15b391ed14a8 100644 --- a/receiver/carbonreceiver/receiver_test.go +++ b/receiver/carbonreceiver/receiver_test.go @@ -18,7 +18,6 @@ import ( "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/receiver/receivertest" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace/tracetest" @@ -248,18 +247,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/receiver/dockerstatsreceiver/integration_test.go b/receiver/dockerstatsreceiver/integration_test.go index 36f9632e3e7b..6c8b12e9234e 100644 --- a/receiver/dockerstatsreceiver/integration_test.go +++ b/receiver/dockerstatsreceiver/integration_test.go @@ -18,7 +18,6 @@ import ( "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pmetric" - "go.opentelemetry.io/collector/pipeline" rcvr "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/receivertest" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" @@ -162,18 +161,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/receiver/receivercreator/observerhandler_test.go b/receiver/receivercreator/observerhandler_test.go index ca33ad91101e..3968402f58e9 100644 --- a/receiver/receivercreator/observerhandler_test.go +++ b/receiver/receivercreator/observerhandler_test.go @@ -14,7 +14,6 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/otelcol" "go.opentelemetry.io/collector/otelcol/otelcoltest" - "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/receiver/receivertest" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer" @@ -466,11 +465,6 @@ func (m *mockHost) GetExtensions() map[component.ID]component.Component { return nil } -func (m *mockHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - m.t.Fatal("GetExporters") - return nil -} - func newMockRunner(t *testing.T) *mockRunner { cs := receivertest.NewNopSettings() return &mockRunner{ @@ -512,18 +506,10 @@ type reportingHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *reportingHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *reportingHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *reportingHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *reportingHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/receiver/sapmreceiver/trace_receiver_test.go b/receiver/sapmreceiver/trace_receiver_test.go index d2cf1ab12732..29d0d276571f 100644 --- a/receiver/sapmreceiver/trace_receiver_test.go +++ b/receiver/sapmreceiver/trace_receiver_test.go @@ -29,7 +29,6 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" - "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/receivertest" conventions "go.opentelemetry.io/collector/semconv/v1.27.0" @@ -480,18 +479,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/receiver/signalfxreceiver/receiver_test.go b/receiver/signalfxreceiver/receiver_test.go index 5574ebe16c34..4fd8322694f5 100644 --- a/receiver/signalfxreceiver/receiver_test.go +++ b/receiver/signalfxreceiver/receiver_test.go @@ -32,7 +32,6 @@ import ( "go.opentelemetry.io/collector/exporter/exportertest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" - "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/receiver/receivertest" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter" @@ -1067,18 +1066,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } diff --git a/receiver/splunkhecreceiver/go.mod b/receiver/splunkhecreceiver/go.mod index 4c2cb33c5801..57c823246219 100644 --- a/receiver/splunkhecreceiver/go.mod +++ b/receiver/splunkhecreceiver/go.mod @@ -22,7 +22,6 @@ require ( go.opentelemetry.io/collector/consumer/consumertest v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/semconv v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 @@ -71,6 +70,7 @@ require ( go.opentelemetry.io/collector/featuregate v1.17.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect go.opentelemetry.io/otel v1.30.0 // indirect diff --git a/receiver/splunkhecreceiver/receiver_test.go b/receiver/splunkhecreceiver/receiver_test.go index d74ad78977b1..3c7351aedd0e 100644 --- a/receiver/splunkhecreceiver/receiver_test.go +++ b/receiver/splunkhecreceiver/receiver_test.go @@ -30,7 +30,6 @@ import ( "go.opentelemetry.io/collector/exporter/exportertest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/plog" - "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/receiver/receivertest" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporter" @@ -2109,18 +2108,10 @@ type nopHost struct { reportFunc func(event *componentstatus.Event) } -func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory { - return nil -} - func (nh *nopHost) GetExtensions() map[component.ID]component.Component { return nil } -func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component { - return nil -} - func (nh *nopHost) Report(event *componentstatus.Event) { nh.reportFunc(event) } From d20c3f8a7d61d093b8fa0494d9bd765e31c03d97 Mon Sep 17 00:00:00 2001 From: lkwronski <45148751+lkwronski@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:08:22 +0200 Subject: [PATCH 7/7] Allow indexing string slice type (#35581) **Description:** Allow indexing string slice type. I can also add support for other types such as []int if needed. Let me know if this approach is good enough. I haven't found a more generic solution, thank you for any feedback. **Link to tracking Issue:** Fixes #29441 **Testing:** Unit test **Documentation:** --- .chloggen/lkwronski.issue-29441-slice.yaml | 27 +++++++++++++++++++ pkg/ottl/e2e/e2e_test.go | 7 +++++ pkg/ottl/expression.go | 18 ++++++++++--- pkg/ottl/expression_test.go | 30 ++++++++++++++++++++++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 .chloggen/lkwronski.issue-29441-slice.yaml diff --git a/.chloggen/lkwronski.issue-29441-slice.yaml b/.chloggen/lkwronski.issue-29441-slice.yaml new file mode 100644 index 000000000000..8d7f4e1908e3 --- /dev/null +++ b/.chloggen/lkwronski.issue-29441-slice.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/ottl + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Allow indexing string slice type + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [29441] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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: [user] diff --git a/pkg/ottl/e2e/e2e_test.go b/pkg/ottl/e2e/e2e_test.go index dcf89bd0c5e2..eab4906aaa00 100644 --- a/pkg/ottl/e2e/e2e_test.go +++ b/pkg/ottl/e2e/e2e_test.go @@ -1010,6 +1010,13 @@ func Test_e2e_ottl_features(t *testing.T) { tCtx.GetLogRecord().Attributes().PutBool("isMap", true) }, }, + { + name: "extract value from Split function result slice of type []string", + statement: `set(attributes["my.environment.2"], Split(resource.attributes["host.name"],"h")[1])`, + want: func(tCtx ottllog.TransformContext) { + tCtx.GetLogRecord().Attributes().PutStr("my.environment.2", "ost") + }, + }, } for _, tt := range tests { diff --git a/pkg/ottl/expression.go b/pkg/ottl/expression.go index ca3671e4ffa5..ea26f0b456ca 100644 --- a/pkg/ottl/expression.go +++ b/pkg/ottl/expression.go @@ -111,10 +111,15 @@ func (g exprGetter[K]) Get(ctx context.Context, tCtx K) (any, error) { } result = ottlcommon.GetValue(r.At(int(*k.Int))) case []any: - if int(*k.Int) >= len(r) || int(*k.Int) < 0 { - return nil, fmt.Errorf("index %v out of bounds", *k.Int) + result, err = getElementByIndex(r, k.Int) + if err != nil { + return nil, err + } + case []string: + result, err = getElementByIndex(r, k.Int) + if err != nil { + return nil, err } - result = r[*k.Int] default: return nil, fmt.Errorf("type, %T, does not support int indexing", result) } @@ -125,6 +130,13 @@ func (g exprGetter[K]) Get(ctx context.Context, tCtx K) (any, error) { return result, nil } +func getElementByIndex[T any](r []T, idx *int64) (any, error) { + if int(*idx) >= len(r) || int(*idx) < 0 { + return nil, fmt.Errorf("index %v out of bounds", *idx) + } + return r[*idx], nil +} + type listGetter[K any] struct { slice []Getter[K] } diff --git a/pkg/ottl/expression_test.go b/pkg/ottl/expression_test.go index 4aa426e558b3..ed6ccaaaadd2 100644 --- a/pkg/ottl/expression_test.go +++ b/pkg/ottl/expression_test.go @@ -59,6 +59,16 @@ func basicSlice() (ExprFunc[any], error) { }, nil } +func basicSliceString() (ExprFunc[any], error) { + return func(_ context.Context, _ any) (any, error) { + return []any{ + []string{ + "pass", + }, + }, nil + }, nil +} + func Test_newGetter(t *testing.T) { tests := []struct { name string @@ -237,6 +247,25 @@ func Test_newGetter(t *testing.T) { }, want: "pass", }, + { + name: "function call nested SliceString", + val: value{ + Literal: &mathExprLiteral{ + Converter: &converter{ + Function: "SliceString", + Keys: []key{ + { + Int: ottltest.Intp(0), + }, + { + Int: ottltest.Intp(0), + }, + }, + }, + }, + }, + want: "pass", + }, { name: "enum", val: value{ @@ -532,6 +561,7 @@ func Test_newGetter(t *testing.T) { createFactory("Map", &struct{}{}, basicMap), createFactory("PSlice", &struct{}{}, pslice), createFactory("Slice", &struct{}{}, basicSlice), + createFactory("SliceString", &struct{}{}, basicSliceString), ) p, _ := NewParser[any](