From 85f47cbe3156876b769b58cd6a1280d6260b5c05 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Fri, 27 Oct 2023 17:19:32 +0200 Subject: [PATCH 1/6] Create a single interface for the Receiver and Exporter parsers Signed-off-by: Israel Blancas --- .../collector/adapters/config_to_ports.go | 151 ++++++------------ .../adapters/config_to_ports_test.go | 15 +- internal/manifests/collector/ingress.go | 2 +- .../collector/parser/exporter/exporter.go | 23 +-- .../parser/exporter/exporter_prometheus.go | 5 +- internal/manifests/collector/parser/parser.go | 31 ++++ .../collector/parser/receiver/receiver.go | 25 +-- .../parser/receiver/receiver_aws-xray.go | 7 +- .../parser/receiver/receiver_carbon.go | 7 +- .../parser/receiver/receiver_collectd.go | 7 +- .../receiver/receiver_fluent-forward.go | 7 +- .../parser/receiver/receiver_generic.go | 5 +- .../parser/receiver/receiver_generic_test.go | 3 +- .../parser/receiver/receiver_influxdb.go | 7 +- .../parser/receiver/receiver_jaeger.go | 5 +- .../parser/receiver/receiver_jaeger_test.go | 3 +- .../collector/parser/receiver/receiver_oc.go | 7 +- .../parser/receiver/receiver_otlp.go | 5 +- .../parser/receiver/receiver_otlp_test.go | 3 +- .../parser/receiver/receiver_sapm.go | 7 +- .../parser/receiver/receiver_signalfx.go | 7 +- .../parser/receiver/receiver_skywalking.go | 5 +- .../receiver/receiver_skywalking_test.go | 3 +- .../parser/receiver/receiver_splunk-hec.go | 7 +- .../parser/receiver/receiver_statsd.go | 3 +- .../parser/receiver/receiver_test.go | 6 +- .../parser/receiver/receiver_wavefront.go | 7 +- .../parser/receiver/receiver_zipkin-scribe.go | 7 +- .../parser/receiver/receiver_zipkin.go | 3 +- .../manifests/collector/servicemonitor.go | 2 +- 30 files changed, 185 insertions(+), 190 deletions(-) create mode 100644 internal/manifests/collector/parser/parser.go diff --git a/internal/manifests/collector/adapters/config_to_ports.go b/internal/manifests/collector/adapters/config_to_ports.go index 1741e6a18d..d76caf0c2e 100644 --- a/internal/manifests/collector/adapters/config_to_ports.go +++ b/internal/manifests/collector/adapters/config_to_ports.go @@ -15,7 +15,7 @@ package adapters import ( - "errors" + "fmt" "net" "sort" "strconv" @@ -24,26 +24,13 @@ import ( "github.com/mitchellh/mapstructure" corev1 "k8s.io/api/core/v1" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" exporterParser "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser/exporter" receiverParser "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser/receiver" ) -var ( - // ErrNoExporters indicates that there are no exporters in the configuration. - ErrNoExporters = errors.New("no exporters available as part of the configuration") - - // ErrNoReceivers indicates that there are no receivers in the configuration. - ErrNoReceivers = errors.New("no receivers available as part of the configuration") - - // ErrReceiversNotAMap indicates that the receivers property isn't a map of values. - ErrReceiversNotAMap = errors.New("receivers property in the configuration doesn't contain valid receivers") - - // ErrExportersNotAMap indicates that the exporters property isn't a map of values. - ErrExportersNotAMap = errors.New("exporters property in the configuration doesn't contain valid exporters") -) - -// ConfigToExporterPorts converts the incoming configuration object into a set of service ports required by the exporters. -func ConfigToExporterPorts(logger logr.Logger, config map[interface{}]interface{}) ([]corev1.ServicePort, error) { +// ConfigToComponentPorts converts the incoming configuration object into a set of service ports required by the exporters. +func ConfigToComponentPorts(logger logr.Logger, componentsName string, config map[interface{}]interface{}) ([]corev1.ServicePort, error) { // now, we gather which ports we might need to open // for that, we get all the exporters and check their `endpoint` properties, // extracting the port from it. The port name has to be a "DNS_LABEL", so, we try to make it follow the pattern: @@ -52,119 +39,71 @@ func ConfigToExporterPorts(logger logr.Logger, config map[interface{}]interface{ // the exporter-qualifier is what comes after the slash in the exporter name, but typically nil // examples: // ```yaml - // exporters: - // exampleexporter: + // components: + // componentexample: // endpoint: 0.0.0.0:12345 - // exampleexporter/settings: + // componentexample/settings: // endpoint: 0.0.0.0:12346 - // in this case, we have two ports, named: "exampleexporter" and "exampleexporter-settings" - exportersProperty, ok := config["exporters"] + // in this case, we have 2 ports, named: "componentexample" and "componentexample-settings" + componentsProperty, ok := config[componentsName] if !ok { - return nil, ErrNoExporters - } - expEnabled := GetEnabledExporters(logger, config) - if expEnabled == nil { - return nil, ErrExportersNotAMap + return nil, fmt.Errorf("no %s available as part of the configuration", componentsName) } - exporters, ok := exportersProperty.(map[interface{}]interface{}) + + components, ok := componentsProperty.(map[interface{}]interface{}) if !ok { - return nil, ErrExportersNotAMap + return nil, fmt.Errorf("%s doesn't contain valid components", componentsName) + } + + var compEnabled map[interface{}]bool + + switch componentsName { + case "exporters": + compEnabled = GetEnabledExporters(logger, config) + case "receivers": + compEnabled = GetEnabledReceivers(logger, config) + } + + if compEnabled == nil { + return nil, fmt.Errorf("no enabled %s available as part of the configuration", componentsName) } ports := []corev1.ServicePort{} - for key, val := range exporters { - // This check will pass only the enabled exporters, + for key, val := range components { + // This check will pass only the enabled components, // then only the related ports will be opened. - if !expEnabled[key] { + if !compEnabled[key] { continue } exporter, ok := val.(map[interface{}]interface{}) if !ok { - logger.V(2).Info("exporter doesn't seem to be a map of properties", "exporter", key) + logger.V(2).Info("component doesn't seem to be a map of properties", componentsName[:len(componentsName)-2], key) exporter = map[interface{}]interface{}{} } - exprtName := key.(string) - exprtParser, err := exporterParser.For(logger, exprtName, exporter) - if err != nil { - logger.V(2).Info("no parser found for '%s'", exprtName) - continue + cmptName := key.(string) + var cmptParser parser.ComponentPortParser + var err error + switch componentsName { + case "exporters": + cmptParser, err = exporterParser.For(logger, cmptName, exporter) + case "receivers": + cmptParser, err = receiverParser.For(logger, cmptName, exporter) } - exprtPorts, err := exprtParser.Ports() if err != nil { - logger.Error(err, "parser for '%s' has returned an error: %w", exprtName, err) - continue - } - - if len(exprtPorts) > 0 { - ports = append(ports, exprtPorts...) - } - } - - sort.Slice(ports, func(i, j int) bool { - return ports[i].Name < ports[j].Name - }) - - return ports, nil -} - -// ConfigToReceiverPorts converts the incoming configuration object into a set of service ports required by the receivers. -func ConfigToReceiverPorts(logger logr.Logger, config map[interface{}]interface{}) ([]corev1.ServicePort, error) { - // now, we gather which ports we might need to open - // for that, we get all the receivers and check their `endpoint` properties, - // extracting the port from it. The port name has to be a "DNS_LABEL", so, we try to make it follow the pattern: - // ${instance.Name}-${receiver.name}-${receiver.qualifier} - // the receiver-name is typically the node name from the receivers map - // the receiver-qualifier is what comes after the slash in the receiver name, but typically nil - // examples: - // ```yaml - // receivers: - // examplereceiver: - // endpoint: 0.0.0.0:12345 - // examplereceiver/settings: - // endpoint: 0.0.0.0:12346 - // in this case, we have two ports, named: "examplereceiver" and "examplereceiver-settings" - receiversProperty, ok := config["receivers"] - if !ok { - return nil, ErrNoReceivers - } - recEnabled := GetEnabledReceivers(logger, config) - if recEnabled == nil { - return nil, ErrReceiversNotAMap - } - receivers, ok := receiversProperty.(map[interface{}]interface{}) - if !ok { - return nil, ErrReceiversNotAMap - } - - ports := []corev1.ServicePort{} - for key, val := range receivers { - // This check will pass only the enabled receivers, - // then only the related ports will be opened. - if !recEnabled[key] { + logger.V(2).Info("no parser found for '%s'", cmptName) continue } - receiver, ok := val.(map[interface{}]interface{}) - if !ok { - logger.Info("receiver doesn't seem to be a map of properties", "receiver", key) - receiver = map[interface{}]interface{}{} - } - rcvrName := key.(string) - rcvrParser := receiverParser.For(logger, rcvrName, receiver) - - rcvrPorts, err := rcvrParser.Ports() + exprtPorts, err := cmptParser.Ports() if err != nil { - // should we break the process and return an error, or just ignore this faulty parser - // and let the other parsers add their ports to the service? right now, the best - // option seems to be to log the failures and move on, instead of failing them all - logger.Error(err, "parser for '%s' has returned an error: %w", rcvrName, err) + logger.Error(err, "parser for '%s' has returned an error: %w", cmptName, err) continue } - if len(rcvrPorts) > 0 { - ports = append(ports, rcvrPorts...) + if len(exprtPorts) > 0 { + ports = append(ports, exprtPorts...) } } @@ -176,12 +115,12 @@ func ConfigToReceiverPorts(logger logr.Logger, config map[interface{}]interface{ } func ConfigToPorts(logger logr.Logger, config map[interface{}]interface{}) []corev1.ServicePort { - ports, err := ConfigToReceiverPorts(logger, config) + ports, err := ConfigToComponentPorts(logger, "receivers", config) if err != nil { logger.Error(err, "there was a problem while getting the ports from the receivers") } - exporterPorts, err := ConfigToExporterPorts(logger, config) + exporterPorts, err := ConfigToComponentPorts(logger, "exporters", config) if err != nil { logger.Error(err, "there was a problem while getting the ports from the exporters") } diff --git a/internal/manifests/collector/adapters/config_to_ports_test.go b/internal/manifests/collector/adapters/config_to_ports_test.go index 7c7d9f3d8f..19a84595b5 100644 --- a/internal/manifests/collector/adapters/config_to_ports_test.go +++ b/internal/manifests/collector/adapters/config_to_ports_test.go @@ -26,6 +26,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser/receiver" ) @@ -83,7 +84,7 @@ func TestExtractPortsFromConfig(t *testing.T) { require.NotEmpty(t, config) // test - ports, err := adapters.ConfigToReceiverPorts(logger, config) + ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) assert.NoError(t, err) assert.Len(t, ports, 10) @@ -116,12 +117,12 @@ func TestNoPortsParsed(t *testing.T) { configStr string }{ { - expected: adapters.ErrNoReceivers, + expected: errors.New("no receivers available as part of the configuration"), desc: "empty", configStr: "", }, { - expected: adapters.ErrReceiversNotAMap, + expected: errors.New("receivers doesn't contain valid components"), desc: "not a map", configStr: "receivers: some-string", }, @@ -132,7 +133,7 @@ func TestNoPortsParsed(t *testing.T) { require.NoError(t, err) // test - ports, err := adapters.ConfigToReceiverPorts(logger, config) + ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) // verify assert.Nil(t, ports) @@ -161,7 +162,7 @@ func TestInvalidReceivers(t *testing.T) { require.NoError(t, err) // test - ports, err := adapters.ConfigToReceiverPorts(logger, config) + ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) // verify assert.NoError(t, err) @@ -179,7 +180,7 @@ func TestParserFailed(t *testing.T) { return nil, errors.New("mocked error") }, } - receiver.Register("mock", func(logger logr.Logger, name string, config map[interface{}]interface{}) receiver.ReceiverParser { + receiver.Register("mock", func(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return mockParser }) @@ -197,7 +198,7 @@ func TestParserFailed(t *testing.T) { } // test - ports, err := adapters.ConfigToReceiverPorts(logger, config) + ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) // verify assert.Len(t, ports, 0) diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index 36e7e15ae3..115011a204 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -144,7 +144,7 @@ func servicePortsFromCfg(logger logr.Logger, otelcol v1alpha1.OpenTelemetryColle return nil } - ports, err := adapters.ConfigToReceiverPorts(logger, configFromString) + ports, err := adapters.ConfigToComponentPorts(logger, "receivers", configFromString) if err != nil { logger.Error(err, "couldn't build the ingress for this instance") } diff --git a/internal/manifests/collector/parser/exporter/exporter.go b/internal/manifests/collector/parser/exporter/exporter.go index ae0282f736..93c66b8599 100644 --- a/internal/manifests/collector/parser/exporter/exporter.go +++ b/internal/manifests/collector/parser/exporter/exporter.go @@ -25,31 +25,20 @@ import ( "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -// ExporterParser is an interface that should be implemented by all exporter parsers. -type ExporterParser interface { - // Ports returns the service ports parsed based on the exporter's configuration - Ports() ([]corev1.ServicePort, error) - - // ParserName returns the name of this parser - ParserName() string -} - -// Builder specifies the signature required for parser builders. -type Builder func(logr.Logger, string, map[interface{}]interface{}) ExporterParser - -// registry holds a record of all known parsers. -var registry = make(map[string]Builder) +// registry holds a record of all known exporter parsers. +var registry = make(map[string]parser.Builder) // BuilderFor returns a parser builder for the given exporter name. -func BuilderFor(name string) Builder { +func BuilderFor(name string) parser.Builder { return registry[exporterType(name)] } // For returns a new parser for the given exporter name + config. -func For(logger logr.Logger, name string, config map[interface{}]interface{}) (ExporterParser, error) { +func For(logger logr.Logger, name string, config map[interface{}]interface{}) (parser.ComponentPortParser, error) { builder := BuilderFor(name) if builder == nil { return nil, fmt.Errorf("no builders for %s", name) @@ -58,7 +47,7 @@ func For(logger logr.Logger, name string, config map[interface{}]interface{}) (E } // Register adds a new parser builder to the list of known builders. -func Register(name string, builder Builder) { +func Register(name string, builder parser.Builder) { registry[name] = builder } diff --git a/internal/manifests/collector/parser/exporter/exporter_prometheus.go b/internal/manifests/collector/parser/exporter/exporter_prometheus.go index cc9e17748b..61d58588da 100644 --- a/internal/manifests/collector/parser/exporter/exporter_prometheus.go +++ b/internal/manifests/collector/parser/exporter/exporter_prometheus.go @@ -19,10 +19,11 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -var _ ExporterParser = &PrometheusExporterParser{} +var _ parser.ComponentPortParser = &PrometheusExporterParser{} const ( parserNamePrometheus = "__prometheus" @@ -37,7 +38,7 @@ type PrometheusExporterParser struct { } // NewPrometheusExporterParser builds a new parser for OTLP receivers. -func NewPrometheusExporterParser(logger logr.Logger, name string, config map[interface{}]interface{}) ExporterParser { +func NewPrometheusExporterParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &PrometheusExporterParser{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/parser.go b/internal/manifests/collector/parser/parser.go new file mode 100644 index 0000000000..62de283b15 --- /dev/null +++ b/internal/manifests/collector/parser/parser.go @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package parser + +import ( + "github.com/go-logr/logr" + corev1 "k8s.io/api/core/v1" +) + +type ComponentPortParser interface { + // Ports returns the service ports parsed based on the exporter's configuration + Ports() ([]corev1.ServicePort, error) + + // ParserName returns the name of this parser + ParserName() string +} + +// Builder specifies the signature required for parser builders. +type Builder func(logr.Logger, string, map[interface{}]interface{}) ComponentPortParser diff --git a/internal/manifests/collector/parser/receiver/receiver.go b/internal/manifests/collector/parser/receiver/receiver.go index 88c6b4bcf2..97147658f4 100644 --- a/internal/manifests/collector/parser/receiver/receiver.go +++ b/internal/manifests/collector/parser/receiver/receiver.go @@ -26,26 +26,15 @@ import ( corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -// ReceiverParser is an interface that should be implemented by all receiver parsers. -type ReceiverParser interface { - // Ports returns the service ports parsed based on the receiver's configuration - Ports() ([]corev1.ServicePort, error) - - // ParserName returns the name of this parser - ParserName() string -} - -// Builder specifies the signature required for parser builders. -type Builder func(logr.Logger, string, map[interface{}]interface{}) ReceiverParser - -// registry holds a record of all known parsers. -var registry = make(map[string]Builder) +// registry holds a record of all known receiver parsers. +var registry = make(map[string]parser.Builder) // BuilderFor returns a parser builder for the given receiver name. -func BuilderFor(name string) Builder { +func BuilderFor(name string) parser.Builder { builder := registry[receiverType(name)] if builder == nil { builder = NewGenericReceiverParser @@ -55,13 +44,13 @@ func BuilderFor(name string) Builder { } // For returns a new parser for the given receiver name + config. -func For(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func For(logger logr.Logger, name string, config map[interface{}]interface{}) (parser.ComponentPortParser, error) { builder := BuilderFor(name) - return builder(logger, name, config) + return builder(logger, name, config), nil } // Register adds a new parser builder to the list of known builders. -func Register(name string, builder Builder) { +func Register(name string, builder parser.Builder) { registry[name] = builder } diff --git a/internal/manifests/collector/parser/receiver/receiver_aws-xray.go b/internal/manifests/collector/parser/receiver/receiver_aws-xray.go index f5569f247e..9ccf578876 100644 --- a/internal/manifests/collector/parser/receiver/receiver_aws-xray.go +++ b/internal/manifests/collector/parser/receiver/receiver_aws-xray.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameAWSXRAY = "__awsxray" // NewAWSXrayReceiverParser builds a new parser for AWS xray receivers, from the contrib repository. -func NewAWSXrayReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewAWSXrayReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_carbon.go b/internal/manifests/collector/parser/receiver/receiver_carbon.go index 45c3c04473..72942a72e8 100644 --- a/internal/manifests/collector/parser/receiver/receiver_carbon.go +++ b/internal/manifests/collector/parser/receiver/receiver_carbon.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameCarbon = "__carbon" // NewCarbonReceiverParser builds a new parser for Carbon receivers, from the contrib repository. -func NewCarbonReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewCarbonReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_collectd.go b/internal/manifests/collector/parser/receiver/receiver_collectd.go index d18e6b72b2..71451464d8 100644 --- a/internal/manifests/collector/parser/receiver/receiver_collectd.go +++ b/internal/manifests/collector/parser/receiver/receiver_collectd.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameCollectd = "__collectd" // NewCollectdReceiverParser builds a new parser for Collectd receivers, from the contrib repository. -func NewCollectdReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewCollectdReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go b/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go index c55debd964..0be89e8bec 100644 --- a/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go +++ b/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameFluentForward = "__fluentforward" // NewFluentForwardReceiverParser builds a new parser for FluentForward receivers, from the contrib repository. -func NewFluentForwardReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewFluentForwardReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_generic.go b/internal/manifests/collector/parser/receiver/receiver_generic.go index 42d5975ec7..864b5bb111 100644 --- a/internal/manifests/collector/parser/receiver/receiver_generic.go +++ b/internal/manifests/collector/parser/receiver/receiver_generic.go @@ -18,12 +18,13 @@ import ( "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) const parserNameGeneric = "__generic" -var _ ReceiverParser = &GenericReceiver{} +var _ parser.ComponentPortParser = &GenericReceiver{} // GenericReceiver is a special parser for generic receivers. It doesn't self-register and should be created/used directly. type GenericReceiver struct { @@ -40,7 +41,7 @@ type GenericReceiver struct { // so that it can expose the required port based on the receiver's config. Receiver scrapers are ignored. // NewGenericReceiverParser builds a new parser for generic receivers. -func NewGenericReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewGenericReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_generic_test.go b/internal/manifests/collector/parser/receiver/receiver_generic_test.go index 4b6580d29e..1adfcf12df 100644 --- a/internal/manifests/collector/parser/receiver/receiver_generic_test.go +++ b/internal/manifests/collector/parser/receiver/receiver_generic_test.go @@ -21,6 +21,7 @@ import ( "github.com/stretchr/testify/assert" logf "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser/receiver" ) @@ -59,7 +60,7 @@ func TestFailedToParseEndpoint(t *testing.T) { func TestDownstreamParsers(t *testing.T) { for _, tt := range []struct { - builder func(logr.Logger, string, map[interface{}]interface{}) receiver.ReceiverParser + builder func(logr.Logger, string, map[interface{}]interface{}) parser.ComponentPortParser desc string receiverName string parserName string diff --git a/internal/manifests/collector/parser/receiver/receiver_influxdb.go b/internal/manifests/collector/parser/receiver/receiver_influxdb.go index d2e9cc3e58..05ea580d83 100644 --- a/internal/manifests/collector/parser/receiver/receiver_influxdb.go +++ b/internal/manifests/collector/parser/receiver/receiver_influxdb.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameInfluxdb = "__influxdb" // NewInfluxdbReceiverParser builds a new parser for Influxdb receivers, from the contrib repository. -func NewInfluxdbReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewInfluxdbReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_jaeger.go b/internal/manifests/collector/parser/receiver/receiver_jaeger.go index 26329a6ec9..dcc99d8bd9 100644 --- a/internal/manifests/collector/parser/receiver/receiver_jaeger.go +++ b/internal/manifests/collector/parser/receiver/receiver_jaeger.go @@ -20,10 +20,11 @@ import ( "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -var _ ReceiverParser = &JaegerReceiverParser{} +var _ parser.ComponentPortParser = &JaegerReceiverParser{} const ( parserNameJaeger = "__jaeger" @@ -42,7 +43,7 @@ type JaegerReceiverParser struct { } // NewJaegerReceiverParser builds a new parser for Jaeger receivers. -func NewJaegerReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewJaegerReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { if protocols, ok := config["protocols"].(map[interface{}]interface{}); ok { return &JaegerReceiverParser{ logger: logger, diff --git a/internal/manifests/collector/parser/receiver/receiver_jaeger_test.go b/internal/manifests/collector/parser/receiver/receiver_jaeger_test.go index 84f343a2cf..dadf3e0cb5 100644 --- a/internal/manifests/collector/parser/receiver/receiver_jaeger_test.go +++ b/internal/manifests/collector/parser/receiver/receiver_jaeger_test.go @@ -28,7 +28,8 @@ func TestJaegerSelfRegisters(t *testing.T) { func TestJaegerIsFoundByName(t *testing.T) { // test - p := For(logger, "jaeger", map[interface{}]interface{}{}) + p, err := For(logger, "jaeger", map[interface{}]interface{}{}) + assert.NoError(t, err) // verify assert.Equal(t, "__jaeger", p.ParserName()) diff --git a/internal/manifests/collector/parser/receiver/receiver_oc.go b/internal/manifests/collector/parser/receiver/receiver_oc.go index c2515a0ad4..30abd02a21 100644 --- a/internal/manifests/collector/parser/receiver/receiver_oc.go +++ b/internal/manifests/collector/parser/receiver/receiver_oc.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameOpenCensus = "__opencensus" // NewOpenCensusReceiverParser builds a new parser for OpenCensus receivers. -func NewOpenCensusReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewOpenCensusReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_otlp.go b/internal/manifests/collector/parser/receiver/receiver_otlp.go index 471ca10c8c..68972fd950 100644 --- a/internal/manifests/collector/parser/receiver/receiver_otlp.go +++ b/internal/manifests/collector/parser/receiver/receiver_otlp.go @@ -21,10 +21,11 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -var _ ReceiverParser = &OTLPReceiverParser{} +var _ parser.ComponentPortParser = &OTLPReceiverParser{} const ( parserNameOTLP = "__otlp" @@ -46,7 +47,7 @@ type OTLPReceiverParser struct { } // NewOTLPReceiverParser builds a new parser for OTLP receivers. -func NewOTLPReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewOTLPReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { if protocols, ok := config["protocols"].(map[interface{}]interface{}); ok { return &OTLPReceiverParser{ logger: logger, diff --git a/internal/manifests/collector/parser/receiver/receiver_otlp_test.go b/internal/manifests/collector/parser/receiver/receiver_otlp_test.go index 4f5e4bcb1d..7165153dde 100644 --- a/internal/manifests/collector/parser/receiver/receiver_otlp_test.go +++ b/internal/manifests/collector/parser/receiver/receiver_otlp_test.go @@ -27,7 +27,8 @@ func TestOTLPSelfRegisters(t *testing.T) { func TestOTLPIsFoundByName(t *testing.T) { // test - p := For(logger, "otlp", map[interface{}]interface{}{}) + p, err := For(logger, "otlp", map[interface{}]interface{}{}) + assert.NoError(t, err) // verify assert.Equal(t, "__otlp", p.ParserName()) diff --git a/internal/manifests/collector/parser/receiver/receiver_sapm.go b/internal/manifests/collector/parser/receiver/receiver_sapm.go index e0a3756abb..fb35e91633 100644 --- a/internal/manifests/collector/parser/receiver/receiver_sapm.go +++ b/internal/manifests/collector/parser/receiver/receiver_sapm.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameSAPM = "__sapm" // NewSAPMReceiverParser builds a new parser for SAPM receivers, from the contrib repository. -func NewSAPMReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewSAPMReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_signalfx.go b/internal/manifests/collector/parser/receiver/receiver_signalfx.go index a3ecc6873a..ef360dc011 100644 --- a/internal/manifests/collector/parser/receiver/receiver_signalfx.go +++ b/internal/manifests/collector/parser/receiver/receiver_signalfx.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameSignalFx = "__signalfx" // NewSignalFxReceiverParser builds a new parser for SignalFx receivers, from the contrib repository. -func NewSignalFxReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewSignalFxReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_skywalking.go b/internal/manifests/collector/parser/receiver/receiver_skywalking.go index 5bee2cb03e..9b72847ee9 100644 --- a/internal/manifests/collector/parser/receiver/receiver_skywalking.go +++ b/internal/manifests/collector/parser/receiver/receiver_skywalking.go @@ -21,10 +21,11 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -var _ ReceiverParser = &SkywalkingReceiverParser{} +var _ parser.ComponentPortParser = &SkywalkingReceiverParser{} const ( parserNameSkywalking = "__skywalking" @@ -41,7 +42,7 @@ type SkywalkingReceiverParser struct { } // NewSkywalkingReceiverParser builds a new parser for Skywalking receivers. -func NewSkywalkingReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewSkywalkingReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { if protocols, ok := config["protocols"].(map[interface{}]interface{}); ok { return &SkywalkingReceiverParser{ logger: logger, diff --git a/internal/manifests/collector/parser/receiver/receiver_skywalking_test.go b/internal/manifests/collector/parser/receiver/receiver_skywalking_test.go index e373e16d8e..ab00c852c2 100644 --- a/internal/manifests/collector/parser/receiver/receiver_skywalking_test.go +++ b/internal/manifests/collector/parser/receiver/receiver_skywalking_test.go @@ -27,7 +27,8 @@ func TestSkywalkingSelfRegisters(t *testing.T) { func TestSkywalkingIsFoundByName(t *testing.T) { // test - p := For(logger, "skywalking", map[interface{}]interface{}{}) + p, err := For(logger, "skywalking", map[interface{}]interface{}{}) + assert.NoError(t, err) // verify assert.Equal(t, "__skywalking", p.ParserName()) diff --git a/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go b/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go index aa7b478bf0..0771344749 100644 --- a/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go +++ b/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameSplunkHec = "__splunk_hec" // NewSplunkHecReceiverParser builds a new parser for Splunk Hec receivers, from the contrib repository. -func NewSplunkHecReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewSplunkHecReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_statsd.go b/internal/manifests/collector/parser/receiver/receiver_statsd.go index 725fb27270..d9898fd47c 100644 --- a/internal/manifests/collector/parser/receiver/receiver_statsd.go +++ b/internal/manifests/collector/parser/receiver/receiver_statsd.go @@ -16,13 +16,14 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" corev1 "k8s.io/api/core/v1" ) const parserNameStatsd = "__statsd" // NewStatsdReceiverParser builds a new parser for Statsd receivers, from the contrib repository. -func NewStatsdReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewStatsdReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_test.go b/internal/manifests/collector/parser/receiver/receiver_test.go index c972f7cd23..9f7d42c7be 100644 --- a/internal/manifests/collector/parser/receiver/receiver_test.go +++ b/internal/manifests/collector/parser/receiver/receiver_test.go @@ -22,6 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" logf "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) @@ -118,7 +119,8 @@ func TestIgnorekubeletstatsEndpoint(t *testing.T) { func TestReceiverFallbackWhenNotRegistered(t *testing.T) { // test - p := For(logger, "myreceiver", map[interface{}]interface{}{}) + p, err := For(logger, "myreceiver", map[interface{}]interface{}{}) + assert.NoError(t, err) // test assert.Equal(t, "__generic", p.ParserName()) @@ -127,7 +129,7 @@ func TestReceiverFallbackWhenNotRegistered(t *testing.T) { func TestReceiverShouldFindRegisteredParser(t *testing.T) { // prepare builderCalled := false - Register("mock", func(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { + Register("mock", func(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { builderCalled = true return &mockParser{} }) diff --git a/internal/manifests/collector/parser/receiver/receiver_wavefront.go b/internal/manifests/collector/parser/receiver/receiver_wavefront.go index 658d192c2a..ec993ea580 100644 --- a/internal/manifests/collector/parser/receiver/receiver_wavefront.go +++ b/internal/manifests/collector/parser/receiver/receiver_wavefront.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameWavefront = "__wavefront" // NewWavefrontReceiverParser builds a new parser for Wavefront receivers, from the contrib repository. -func NewWavefrontReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewWavefrontReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go b/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go index c45968b1db..95cf983555 100644 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go +++ b/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go @@ -14,12 +14,15 @@ package receiver -import "github.com/go-logr/logr" +import ( + "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" +) const parserNameZipkinScribe = "__zipkinscribe" // NewZipkinScribeReceiverParser builds a new parser for ZipkinScribe receivers. -func NewZipkinScribeReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewZipkinScribeReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { return &GenericReceiver{ logger: logger, name: name, diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin.go b/internal/manifests/collector/parser/receiver/receiver_zipkin.go index 412a8b6cf7..f9565379f1 100644 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin.go +++ b/internal/manifests/collector/parser/receiver/receiver_zipkin.go @@ -16,13 +16,14 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" corev1 "k8s.io/api/core/v1" ) const parserNameZipkin = "__zipkin" // NewZipkinReceiverParser builds a new parser for Zipkin receivers. -func NewZipkinReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { +func NewZipkinReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { http := "http" return &GenericReceiver{ logger: logger, diff --git a/internal/manifests/collector/servicemonitor.go b/internal/manifests/collector/servicemonitor.go index abe78c8ce7..86a51a268f 100644 --- a/internal/manifests/collector/servicemonitor.go +++ b/internal/manifests/collector/servicemonitor.go @@ -79,7 +79,7 @@ func endpointsFromConfig(logger logr.Logger, otelcol v1alpha1.OpenTelemetryColle return []monitoringv1.Endpoint{} } - exporterPorts, err := adapters.ConfigToExporterPorts(logger, c) + exporterPorts, err := adapters.ConfigToComponentPorts(logger, "exporters", c) if err != nil { logger.Error(err, "couldn't build service monitors from configuration") return []monitoringv1.Endpoint{} From dab0145744732e53f894bc9e196bf383f22be113 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Fri, 27 Oct 2023 17:32:47 +0200 Subject: [PATCH 2/6] Fix lint Signed-off-by: Israel Blancas --- .../manifests/collector/parser/receiver/receiver_aws-xray.go | 1 + .../manifests/collector/parser/receiver/receiver_carbon.go | 1 + .../manifests/collector/parser/receiver/receiver_collectd.go | 1 + .../collector/parser/receiver/receiver_fluent-forward.go | 1 + .../manifests/collector/parser/receiver/receiver_influxdb.go | 1 + internal/manifests/collector/parser/receiver/receiver_oc.go | 1 + internal/manifests/collector/parser/receiver/receiver_sapm.go | 1 + .../manifests/collector/parser/receiver/receiver_signalfx.go | 1 + .../manifests/collector/parser/receiver/receiver_splunk-hec.go | 1 + .../manifests/collector/parser/receiver/receiver_statsd.go | 3 ++- internal/manifests/collector/parser/receiver/receiver_test.go | 2 +- .../manifests/collector/parser/receiver/receiver_wavefront.go | 1 + .../collector/parser/receiver/receiver_zipkin-scribe.go | 1 + .../manifests/collector/parser/receiver/receiver_zipkin.go | 3 ++- 14 files changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/manifests/collector/parser/receiver/receiver_aws-xray.go b/internal/manifests/collector/parser/receiver/receiver_aws-xray.go index 9ccf578876..44618b3aa5 100644 --- a/internal/manifests/collector/parser/receiver/receiver_aws-xray.go +++ b/internal/manifests/collector/parser/receiver/receiver_aws-xray.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_carbon.go b/internal/manifests/collector/parser/receiver/receiver_carbon.go index 72942a72e8..b1b0aaa4ce 100644 --- a/internal/manifests/collector/parser/receiver/receiver_carbon.go +++ b/internal/manifests/collector/parser/receiver/receiver_carbon.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_collectd.go b/internal/manifests/collector/parser/receiver/receiver_collectd.go index 71451464d8..aa42ab0397 100644 --- a/internal/manifests/collector/parser/receiver/receiver_collectd.go +++ b/internal/manifests/collector/parser/receiver/receiver_collectd.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go b/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go index 0be89e8bec..88881923fa 100644 --- a/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go +++ b/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_influxdb.go b/internal/manifests/collector/parser/receiver/receiver_influxdb.go index 05ea580d83..0930a29f73 100644 --- a/internal/manifests/collector/parser/receiver/receiver_influxdb.go +++ b/internal/manifests/collector/parser/receiver/receiver_influxdb.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_oc.go b/internal/manifests/collector/parser/receiver/receiver_oc.go index 30abd02a21..3463a8d398 100644 --- a/internal/manifests/collector/parser/receiver/receiver_oc.go +++ b/internal/manifests/collector/parser/receiver/receiver_oc.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_sapm.go b/internal/manifests/collector/parser/receiver/receiver_sapm.go index fb35e91633..924b88bff5 100644 --- a/internal/manifests/collector/parser/receiver/receiver_sapm.go +++ b/internal/manifests/collector/parser/receiver/receiver_sapm.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_signalfx.go b/internal/manifests/collector/parser/receiver/receiver_signalfx.go index ef360dc011..549e802453 100644 --- a/internal/manifests/collector/parser/receiver/receiver_signalfx.go +++ b/internal/manifests/collector/parser/receiver/receiver_signalfx.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go b/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go index 0771344749..676415334b 100644 --- a/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go +++ b/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_statsd.go b/internal/manifests/collector/parser/receiver/receiver_statsd.go index d9898fd47c..0f41520e22 100644 --- a/internal/manifests/collector/parser/receiver/receiver_statsd.go +++ b/internal/manifests/collector/parser/receiver/receiver_statsd.go @@ -16,8 +16,9 @@ package receiver import ( "github.com/go-logr/logr" - "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" corev1 "k8s.io/api/core/v1" + + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) const parserNameStatsd = "__statsd" diff --git a/internal/manifests/collector/parser/receiver/receiver_test.go b/internal/manifests/collector/parser/receiver/receiver_test.go index 9f7d42c7be..44cb04519d 100644 --- a/internal/manifests/collector/parser/receiver/receiver_test.go +++ b/internal/manifests/collector/parser/receiver/receiver_test.go @@ -135,7 +135,7 @@ func TestReceiverShouldFindRegisteredParser(t *testing.T) { }) // test - For(logger, "mock", map[interface{}]interface{}{}) + _, _ = For(logger, "mock", map[interface{}]interface{}{}) // verify assert.True(t, builderCalled) diff --git a/internal/manifests/collector/parser/receiver/receiver_wavefront.go b/internal/manifests/collector/parser/receiver/receiver_wavefront.go index ec993ea580..f2eafb8556 100644 --- a/internal/manifests/collector/parser/receiver/receiver_wavefront.go +++ b/internal/manifests/collector/parser/receiver/receiver_wavefront.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go b/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go index 95cf983555..8f8d9fe210 100644 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go +++ b/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go @@ -16,6 +16,7 @@ package receiver import ( "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin.go b/internal/manifests/collector/parser/receiver/receiver_zipkin.go index f9565379f1..debbf8e9a4 100644 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin.go +++ b/internal/manifests/collector/parser/receiver/receiver_zipkin.go @@ -16,8 +16,9 @@ package receiver import ( "github.com/go-logr/logr" - "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" corev1 "k8s.io/api/core/v1" + + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" ) const parserNameZipkin = "__zipkin" From d2c8f97b3f999861d304ad8d4780ac97f2940292 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Mon, 30 Oct 2023 12:41:43 +0100 Subject: [PATCH 3/6] Use ComponentType Signed-off-by: Israel Blancas --- .../collector/adapters/config_to_ports.go | 39 ++++++++++++------- .../adapters/config_to_ports_test.go | 8 ++-- internal/manifests/collector/ingress.go | 2 +- .../manifests/collector/servicemonitor.go | 2 +- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/internal/manifests/collector/adapters/config_to_ports.go b/internal/manifests/collector/adapters/config_to_ports.go index d76caf0c2e..d58425a3e6 100644 --- a/internal/manifests/collector/adapters/config_to_ports.go +++ b/internal/manifests/collector/adapters/config_to_ports.go @@ -29,8 +29,19 @@ import ( receiverParser "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser/receiver" ) +type ComponentType int + +const ( + Receivers ComponentType = iota + Exporters +) + +func (c ComponentType) String() string { + return [...]string{"receivers", "exporters"}[c] +} + // ConfigToComponentPorts converts the incoming configuration object into a set of service ports required by the exporters. -func ConfigToComponentPorts(logger logr.Logger, componentsName string, config map[interface{}]interface{}) ([]corev1.ServicePort, error) { +func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[interface{}]interface{}) ([]corev1.ServicePort, error) { // now, we gather which ports we might need to open // for that, we get all the exporters and check their `endpoint` properties, // extracting the port from it. The port name has to be a "DNS_LABEL", so, we try to make it follow the pattern: @@ -45,27 +56,27 @@ func ConfigToComponentPorts(logger logr.Logger, componentsName string, config ma // componentexample/settings: // endpoint: 0.0.0.0:12346 // in this case, we have 2 ports, named: "componentexample" and "componentexample-settings" - componentsProperty, ok := config[componentsName] + componentsProperty, ok := config[cType.String()] if !ok { - return nil, fmt.Errorf("no %s available as part of the configuration", componentsName) + return nil, fmt.Errorf("no %s available as part of the configuration", cType) } components, ok := componentsProperty.(map[interface{}]interface{}) if !ok { - return nil, fmt.Errorf("%s doesn't contain valid components", componentsName) + return nil, fmt.Errorf("%s doesn't contain valid components", cType.String()) } var compEnabled map[interface{}]bool - switch componentsName { - case "exporters": + switch cType { + case Exporters: compEnabled = GetEnabledExporters(logger, config) - case "receivers": + case Receivers: compEnabled = GetEnabledReceivers(logger, config) } if compEnabled == nil { - return nil, fmt.Errorf("no enabled %s available as part of the configuration", componentsName) + return nil, fmt.Errorf("no enabled %s available as part of the configuration", cType) } ports := []corev1.ServicePort{} @@ -77,17 +88,17 @@ func ConfigToComponentPorts(logger logr.Logger, componentsName string, config ma } exporter, ok := val.(map[interface{}]interface{}) if !ok { - logger.V(2).Info("component doesn't seem to be a map of properties", componentsName[:len(componentsName)-2], key) + logger.V(2).Info("component doesn't seem to be a map of properties", cType.String()[:len(cType.String())-2], key) exporter = map[interface{}]interface{}{} } cmptName := key.(string) var cmptParser parser.ComponentPortParser var err error - switch componentsName { - case "exporters": + switch cType { + case Exporters: cmptParser, err = exporterParser.For(logger, cmptName, exporter) - case "receivers": + case Receivers: cmptParser, err = receiverParser.For(logger, cmptName, exporter) } @@ -115,12 +126,12 @@ func ConfigToComponentPorts(logger logr.Logger, componentsName string, config ma } func ConfigToPorts(logger logr.Logger, config map[interface{}]interface{}) []corev1.ServicePort { - ports, err := ConfigToComponentPorts(logger, "receivers", config) + ports, err := ConfigToComponentPorts(logger, Receivers, config) if err != nil { logger.Error(err, "there was a problem while getting the ports from the receivers") } - exporterPorts, err := ConfigToComponentPorts(logger, "exporters", config) + exporterPorts, err := ConfigToComponentPorts(logger, Exporters, config) if err != nil { logger.Error(err, "there was a problem while getting the ports from the exporters") } diff --git a/internal/manifests/collector/adapters/config_to_ports_test.go b/internal/manifests/collector/adapters/config_to_ports_test.go index 19a84595b5..908a389139 100644 --- a/internal/manifests/collector/adapters/config_to_ports_test.go +++ b/internal/manifests/collector/adapters/config_to_ports_test.go @@ -84,7 +84,7 @@ func TestExtractPortsFromConfig(t *testing.T) { require.NotEmpty(t, config) // test - ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) assert.NoError(t, err) assert.Len(t, ports, 10) @@ -133,7 +133,7 @@ func TestNoPortsParsed(t *testing.T) { require.NoError(t, err) // test - ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) // verify assert.Nil(t, ports) @@ -162,7 +162,7 @@ func TestInvalidReceivers(t *testing.T) { require.NoError(t, err) // test - ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) // verify assert.NoError(t, err) @@ -198,7 +198,7 @@ func TestParserFailed(t *testing.T) { } // test - ports, err := adapters.ConfigToComponentPorts(logger, "receivers", config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) // verify assert.Len(t, ports, 0) diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index 115011a204..2545383df0 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -144,7 +144,7 @@ func servicePortsFromCfg(logger logr.Logger, otelcol v1alpha1.OpenTelemetryColle return nil } - ports, err := adapters.ConfigToComponentPorts(logger, "receivers", configFromString) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, configFromString) if err != nil { logger.Error(err, "couldn't build the ingress for this instance") } diff --git a/internal/manifests/collector/servicemonitor.go b/internal/manifests/collector/servicemonitor.go index 86a51a268f..4c265dd418 100644 --- a/internal/manifests/collector/servicemonitor.go +++ b/internal/manifests/collector/servicemonitor.go @@ -79,7 +79,7 @@ func endpointsFromConfig(logger logr.Logger, otelcol v1alpha1.OpenTelemetryColle return []monitoringv1.Endpoint{} } - exporterPorts, err := adapters.ConfigToComponentPorts(logger, "exporters", c) + exporterPorts, err := adapters.ConfigToComponentPorts(logger, adapters.Exporters, c) if err != nil { logger.Error(err, "couldn't build service monitors from configuration") return []monitoringv1.Endpoint{} From 88626105d5fbe9c96e2d0f599f1a786c25b92c31 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Mon, 6 Nov 2023 20:55:21 +0100 Subject: [PATCH 4/6] Apply changes requested in code review Signed-off-by: Israel Blancas --- .../collector/adapters/config_to_ports.go | 28 +++++++++---------- .../adapters/config_to_ports_test.go | 8 +++--- internal/manifests/collector/ingress.go | 2 +- .../manifests/collector/servicemonitor.go | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/manifests/collector/adapters/config_to_ports.go b/internal/manifests/collector/adapters/config_to_ports.go index d58425a3e6..e605dfae6b 100644 --- a/internal/manifests/collector/adapters/config_to_ports.go +++ b/internal/manifests/collector/adapters/config_to_ports.go @@ -32,12 +32,12 @@ import ( type ComponentType int const ( - Receivers ComponentType = iota - Exporters + ComponentTypeReceiver ComponentType = iota + ComponentTypeExporter ) func (c ComponentType) String() string { - return [...]string{"receivers", "exporters"}[c] + return [...]string{"receiver", "exporter"}[c] } // ConfigToComponentPorts converts the incoming configuration object into a set of service ports required by the exporters. @@ -56,27 +56,27 @@ func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[ // componentexample/settings: // endpoint: 0.0.0.0:12346 // in this case, we have 2 ports, named: "componentexample" and "componentexample-settings" - componentsProperty, ok := config[cType.String()] + componentsProperty, ok := config[fmt.Sprintf("%ss", cType.String())] if !ok { - return nil, fmt.Errorf("no %s available as part of the configuration", cType) + return nil, fmt.Errorf("no %ss available as part of the configuration", cType) } components, ok := componentsProperty.(map[interface{}]interface{}) if !ok { - return nil, fmt.Errorf("%s doesn't contain valid components", cType.String()) + return nil, fmt.Errorf("%ss doesn't contain valid components", cType.String()) } var compEnabled map[interface{}]bool switch cType { - case Exporters: + case ComponentTypeExporter: compEnabled = GetEnabledExporters(logger, config) - case Receivers: + case ComponentTypeReceiver: compEnabled = GetEnabledReceivers(logger, config) } if compEnabled == nil { - return nil, fmt.Errorf("no enabled %s available as part of the configuration", cType) + return nil, fmt.Errorf("no enabled %ss available as part of the configuration", cType) } ports := []corev1.ServicePort{} @@ -88,7 +88,7 @@ func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[ } exporter, ok := val.(map[interface{}]interface{}) if !ok { - logger.V(2).Info("component doesn't seem to be a map of properties", cType.String()[:len(cType.String())-2], key) + logger.V(2).Info("component doesn't seem to be a map of properties", cType.String(), key) exporter = map[interface{}]interface{}{} } @@ -96,9 +96,9 @@ func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[ var cmptParser parser.ComponentPortParser var err error switch cType { - case Exporters: + case ComponentTypeExporter: cmptParser, err = exporterParser.For(logger, cmptName, exporter) - case Receivers: + case ComponentTypeReceiver: cmptParser, err = receiverParser.For(logger, cmptName, exporter) } @@ -126,12 +126,12 @@ func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[ } func ConfigToPorts(logger logr.Logger, config map[interface{}]interface{}) []corev1.ServicePort { - ports, err := ConfigToComponentPorts(logger, Receivers, config) + ports, err := ConfigToComponentPorts(logger, ComponentTypeReceiver, config) if err != nil { logger.Error(err, "there was a problem while getting the ports from the receivers") } - exporterPorts, err := ConfigToComponentPorts(logger, Exporters, config) + exporterPorts, err := ConfigToComponentPorts(logger, ComponentTypeExporter, config) if err != nil { logger.Error(err, "there was a problem while getting the ports from the exporters") } diff --git a/internal/manifests/collector/adapters/config_to_ports_test.go b/internal/manifests/collector/adapters/config_to_ports_test.go index 908a389139..c2ae638ef5 100644 --- a/internal/manifests/collector/adapters/config_to_ports_test.go +++ b/internal/manifests/collector/adapters/config_to_ports_test.go @@ -84,7 +84,7 @@ func TestExtractPortsFromConfig(t *testing.T) { require.NotEmpty(t, config) // test - ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.ComponentTypeReceiver, config) assert.NoError(t, err) assert.Len(t, ports, 10) @@ -133,7 +133,7 @@ func TestNoPortsParsed(t *testing.T) { require.NoError(t, err) // test - ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.ComponentTypeReceiver, config) // verify assert.Nil(t, ports) @@ -162,7 +162,7 @@ func TestInvalidReceivers(t *testing.T) { require.NoError(t, err) // test - ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.ComponentTypeReceiver, config) // verify assert.NoError(t, err) @@ -198,7 +198,7 @@ func TestParserFailed(t *testing.T) { } // test - ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, config) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.ComponentTypeReceiver, config) // verify assert.Len(t, ports, 0) diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index 2545383df0..d1b68106eb 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -144,7 +144,7 @@ func servicePortsFromCfg(logger logr.Logger, otelcol v1alpha1.OpenTelemetryColle return nil } - ports, err := adapters.ConfigToComponentPorts(logger, adapters.Receivers, configFromString) + ports, err := adapters.ConfigToComponentPorts(logger, adapters.ComponentTypeReceiver, configFromString) if err != nil { logger.Error(err, "couldn't build the ingress for this instance") } diff --git a/internal/manifests/collector/servicemonitor.go b/internal/manifests/collector/servicemonitor.go index 4c265dd418..8b0a775f29 100644 --- a/internal/manifests/collector/servicemonitor.go +++ b/internal/manifests/collector/servicemonitor.go @@ -79,7 +79,7 @@ func endpointsFromConfig(logger logr.Logger, otelcol v1alpha1.OpenTelemetryColle return []monitoringv1.Endpoint{} } - exporterPorts, err := adapters.ConfigToComponentPorts(logger, adapters.Exporters, c) + exporterPorts, err := adapters.ConfigToComponentPorts(logger, adapters.ComponentTypeExporter, c) if err != nil { logger.Error(err, "couldn't build service monitors from configuration") return []monitoringv1.Endpoint{} From d5d53e8b08ed66d86deee7629594838b8f84fbf3 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Mon, 20 Nov 2023 16:16:51 +0100 Subject: [PATCH 5/6] Simplify getting the enabled components Signed-off-by: Israel Blancas --- .../collector/adapters/config_to_ports.go | 9 +------- .../collector/adapters/config_validate.go | 21 ++++++------------- .../adapters/config_validate_test.go | 4 ++-- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/internal/manifests/collector/adapters/config_to_ports.go b/internal/manifests/collector/adapters/config_to_ports.go index e605dfae6b..b712e1df40 100644 --- a/internal/manifests/collector/adapters/config_to_ports.go +++ b/internal/manifests/collector/adapters/config_to_ports.go @@ -66,14 +66,7 @@ func ConfigToComponentPorts(logger logr.Logger, cType ComponentType, config map[ return nil, fmt.Errorf("%ss doesn't contain valid components", cType.String()) } - var compEnabled map[interface{}]bool - - switch cType { - case ComponentTypeExporter: - compEnabled = GetEnabledExporters(logger, config) - case ComponentTypeReceiver: - compEnabled = GetEnabledReceivers(logger, config) - } + compEnabled := getEnabledComponents(config, cType) if compEnabled == nil { return nil, fmt.Errorf("no enabled %ss available as part of the configuration", cType) diff --git a/internal/manifests/collector/adapters/config_validate.go b/internal/manifests/collector/adapters/config_validate.go index 221a4f21a6..8283702cf5 100644 --- a/internal/manifests/collector/adapters/config_validate.go +++ b/internal/manifests/collector/adapters/config_validate.go @@ -14,22 +14,13 @@ package adapters -import ( - "github.com/go-logr/logr" -) +import "fmt" // Following Otel Doc: Configuring a receiver does not enable it. The receivers are enabled via pipelines within the service section. -// GetEnabledReceivers returns all enabled receivers as a true flag set. If it can't find any receiver, it will return a nil interface. -func GetEnabledReceivers(_ logr.Logger, config map[interface{}]interface{}) map[interface{}]bool { - return getEnabledComponents(config, "receivers") -} - -func GetEnabledExporters(_ logr.Logger, config map[interface{}]interface{}) map[interface{}]bool { - return getEnabledComponents(config, "exporters") -} - -func getEnabledComponents(config map[interface{}]interface{}, componentType string) map[interface{}]bool { - cfgComponents, ok := config[componentType] +// getEnabledComponents returns all enabled components as a true flag set. If it can't find any receiver, it will return a nil interface. +func getEnabledComponents(config map[interface{}]interface{}, componentType ComponentType) map[interface{}]bool { + componentTypePlural := fmt.Sprintf("%ss", componentType) + cfgComponents, ok := config[componentTypePlural] if !ok { return nil } @@ -85,7 +76,7 @@ func getEnabledComponents(config map[interface{}]interface{}, componentType stri return nil } for pipSpecID, pipSpecCfg := range pipelineDesc { - if pipSpecID.(string) == componentType { + if pipSpecID.(string) == componentTypePlural { receiversList, ok := pipSpecCfg.([]interface{}) if !ok { continue diff --git a/internal/manifests/collector/adapters/config_validate_test.go b/internal/manifests/collector/adapters/config_validate_test.go index 34cf841181..8b154e145f 100644 --- a/internal/manifests/collector/adapters/config_validate_test.go +++ b/internal/manifests/collector/adapters/config_validate_test.go @@ -61,7 +61,7 @@ service: require.NotEmpty(t, config) // test - check := GetEnabledReceivers(logger, config) + check := getEnabledComponents(config, ComponentTypeReceiver) require.NotEmpty(t, check) } @@ -102,6 +102,6 @@ service: require.NotEmpty(t, config) // test - check := GetEnabledReceivers(logger, config) + check := getEnabledComponents(config, ComponentTypeReceiver) require.Empty(t, check) } From 3ee5b15b7b89977b2b9ab9136afb5cf20968bca5 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Mon, 20 Nov 2023 18:27:51 +0100 Subject: [PATCH 6/6] Fix lint Signed-off-by: Israel Blancas --- apis/v1alpha1/collector_webhook_test.go | 2 ++ apis/v1alpha1/instrumentation_webhook_test.go | 1 + apis/v1alpha1/opampbridge_webhook_test.go | 2 ++ controllers/reconcile_test.go | 4 ++++ internal/manifests/collector/adapters/config_validate_test.go | 4 ---- internal/webhook/podmutation/webhookhandler_test.go | 2 ++ pkg/instrumentation/podmutator_test.go | 1 + 7 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apis/v1alpha1/collector_webhook_test.go b/apis/v1alpha1/collector_webhook_test.go index 8ccc26bb11..fd8763ebd5 100644 --- a/apis/v1alpha1/collector_webhook_test.go +++ b/apis/v1alpha1/collector_webhook_test.go @@ -277,6 +277,7 @@ func TestOTELColDefaultingWebhook(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { cvw := &CollectorWebhook{ logger: logr.Discard(), @@ -786,6 +787,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { cvw := &CollectorWebhook{ logger: logr.Discard(), diff --git a/apis/v1alpha1/instrumentation_webhook_test.go b/apis/v1alpha1/instrumentation_webhook_test.go index 46f7327ad8..81049cbc0c 100644 --- a/apis/v1alpha1/instrumentation_webhook_test.go +++ b/apis/v1alpha1/instrumentation_webhook_test.go @@ -116,6 +116,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { ctx := context.Background() if test.err == "" { diff --git a/apis/v1alpha1/opampbridge_webhook_test.go b/apis/v1alpha1/opampbridge_webhook_test.go index 947eaa03e6..b67551b8ee 100644 --- a/apis/v1alpha1/opampbridge_webhook_test.go +++ b/apis/v1alpha1/opampbridge_webhook_test.go @@ -108,6 +108,7 @@ func TestOpAMPBridgeDefaultingWebhook(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { webhook := &OpAMPBridgeWebhook{ logger: logr.Discard(), @@ -294,6 +295,7 @@ func TestOpAMPBridgeValidatingWebhook(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { webhook := &OpAMPBridgeWebhook{ logger: logr.Discard(), diff --git a/controllers/reconcile_test.go b/controllers/reconcile_test.go index 699cc57702..7ab86fffd6 100644 --- a/controllers/reconcile_test.go +++ b/controllers/reconcile_test.go @@ -490,6 +490,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { testContext := context.Background() nsn := types.NamespacedName{Name: tt.args.params.OtelCol.Name, Namespace: tt.args.params.OtelCol.Namespace} @@ -523,6 +524,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { } // run the next set of checks for pid, updateParam := range tt.args.updates { + updateParam := updateParam existing := v1alpha1.OpenTelemetryCollector{} found, err := populateObjectIfExists(t, &existing, nsn) assert.True(t, found) @@ -642,6 +644,7 @@ func TestOpAMPBridgeReconciler_Reconcile(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { testContext := context.Background() nsn := types.NamespacedName{Name: tt.args.params.OpAMPBridge.Name, Namespace: tt.args.params.OpAMPBridge.Namespace} @@ -676,6 +679,7 @@ func TestOpAMPBridgeReconciler_Reconcile(t *testing.T) { } // run the next set of checks for pid, updateParam := range tt.args.updates { + updateParam := updateParam existing := v1alpha1.OpAMPBridge{} found, err := populateObjectIfExists(t, &existing, nsn) assert.True(t, found) diff --git a/internal/manifests/collector/adapters/config_validate_test.go b/internal/manifests/collector/adapters/config_validate_test.go index 8b154e145f..7003235fed 100644 --- a/internal/manifests/collector/adapters/config_validate_test.go +++ b/internal/manifests/collector/adapters/config_validate_test.go @@ -17,13 +17,9 @@ package adapters import ( "testing" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "github.com/stretchr/testify/require" ) -var logger = logf.Log.WithName("unit-tests") - func TestConfigValidate(t *testing.T) { // prepare diff --git a/internal/webhook/podmutation/webhookhandler_test.go b/internal/webhook/podmutation/webhookhandler_test.go index d5bb69b795..0adbc2b929 100644 --- a/internal/webhook/podmutation/webhookhandler_test.go +++ b/internal/webhook/podmutation/webhookhandler_test.go @@ -123,6 +123,7 @@ func TestShouldInjectSidecar(t *testing.T) { }, }, } { + tt := tt t.Run(tt.name, func(t *testing.T) { err := k8sClient.Create(context.Background(), &tt.ns) require.NoError(t, err) @@ -341,6 +342,7 @@ func TestPodShouldNotBeChanged(t *testing.T) { }}, }, } { + tt := tt t.Run(tt.name, func(t *testing.T) { err := k8sClient.Create(context.Background(), &tt.ns) require.NoError(t, err) diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index b2b39d45f1..7e764abf07 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -5139,6 +5139,7 @@ func TestMutatePod(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { if test.setFeatureGates != nil { test.setFeatureGates(t)