diff --git a/internal/manifests/collector/adapters/config_to_ports.go b/internal/manifests/collector/adapters/config_to_ports.go deleted file mode 100644 index 444eb0f9fe..0000000000 --- a/internal/manifests/collector/adapters/config_to_ports.go +++ /dev/null @@ -1,27 +0,0 @@ -// 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 adapters - -type ComponentType int - -const ( - ComponentTypeReceiver ComponentType = iota - ComponentTypeExporter - ComponentTypeProcessor -) - -func (c ComponentType) String() string { - return [...]string{"receiver", "exporter", "processor"}[c] -} diff --git a/internal/manifests/collector/adapters/config_to_rbac.go b/internal/manifests/collector/adapters/config_to_rbac.go deleted file mode 100644 index 55fd2d9bef..0000000000 --- a/internal/manifests/collector/adapters/config_to_rbac.go +++ /dev/null @@ -1,63 +0,0 @@ -// 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 adapters - -import ( - "github.com/go-logr/logr" - rbacv1 "k8s.io/api/rbac/v1" - - "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser/processor" -) - -// ConfigToRBAC parses the OpenTelemetry Collector configuration and checks what RBAC resources are needed to be created. -func ConfigToRBAC(logger logr.Logger, config map[interface{}]interface{}) []rbacv1.PolicyRule { - var policyRules []rbacv1.PolicyRule - processorsRaw, ok := config["processors"] - if !ok { - logger.V(2).Info("no processors available as part of the configuration") - return policyRules - } - - processors, ok := processorsRaw.(map[interface{}]interface{}) - if !ok { - logger.V(2).Info("processors doesn't contain valid components") - return policyRules - } - - enabledProcessors := getEnabledComponents(config, ComponentTypeProcessor) - - for key, val := range processors { - if !enabledProcessors[key] { - continue - } - - processorCfg, ok := val.(map[interface{}]interface{}) - if !ok { - logger.V(2).Info("processor doesn't seem to be a map of properties", "processor", key) - processorCfg = map[interface{}]interface{}{} - } - - processorName := key.(string) - processorParser, err := processor.For(logger, processorName, processorCfg) - if err != nil { - logger.V(2).Info("no parser found for", "processor", processorName) - continue - } - - policyRules = append(policyRules, processorParser.GetRBACRules()...) - } - - return policyRules -} diff --git a/internal/manifests/collector/adapters/config_to_rbac_test.go b/internal/manifests/collector/adapters/config_to_rbac_test.go deleted file mode 100644 index 8260d23648..0000000000 --- a/internal/manifests/collector/adapters/config_to_rbac_test.go +++ /dev/null @@ -1,100 +0,0 @@ -// 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 adapters - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - rbacv1 "k8s.io/api/rbac/v1" - logf "sigs.k8s.io/controller-runtime/pkg/log" -) - -func TestConfigRBAC(t *testing.T) { - tests := []struct { - desc string - config string - expectedRules []rbacv1.PolicyRule - }{ - { - desc: "No processors", - config: `processors: -service: - traces: - processors:`, - expectedRules: ([]rbacv1.PolicyRule)(nil), - }, - { - desc: "processors no rbac", - config: `processors: - batch: -service: - pipelines: - traces: - processors: [batch]`, - expectedRules: ([]rbacv1.PolicyRule)(nil), - }, - { - desc: "resourcedetection-processor k8s", - config: `processors: - resourcedetection: - detectors: [k8snode] -service: - pipelines: - traces: - processors: [resourcedetection]`, - expectedRules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"nodes"}, - Verbs: []string{"get", "list"}, - }, - }, - }, - { - desc: "resourcedetection-processor openshift", - config: `processors: - resourcedetection: - detectors: [openshift] -service: - pipelines: - traces: - processors: [resourcedetection]`, - expectedRules: []rbacv1.PolicyRule{ - { - APIGroups: []string{"config.openshift.io"}, - Resources: []string{"infrastructures", "infrastructures/status"}, - Verbs: []string{"get", "watch", "list"}, - }, - }, - }, - } - - var logger = logf.Log.WithName("collector-unit-tests") - - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - config, err := ConfigFromString(tt.config) - require.NoError(t, err, tt.desc) - require.NotEmpty(t, config, tt.desc) - - // test - rules := ConfigToRBAC(logger, config) - assert.NoError(t, err) - assert.Equal(t, tt.expectedRules, rules, tt.desc) - }) - } -} diff --git a/internal/manifests/collector/adapters/config_validate.go b/internal/manifests/collector/adapters/config_validate.go deleted file mode 100644 index ff0c86c9b8..0000000000 --- a/internal/manifests/collector/adapters/config_validate.go +++ /dev/null @@ -1,110 +0,0 @@ -// 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 adapters - -import "fmt" - -// Following Otel Doc: Configuring a receiver does not enable it. The receivers are enabled via pipelines within the service section. -// 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.String()) - cfgComponents, ok := config[componentTypePlural] - if !ok { - return nil - } - components, ok := cfgComponents.(map[interface{}]interface{}) - if !ok { - return nil - } - availableComponents := map[interface{}]bool{} - - for compID := range components { - - //Safe Cast - componentID, withComponent := compID.(string) - if !withComponent { - return nil - } - //Getting all components present in the components (exporters,receivers...) section and setting them to false. - availableComponents[componentID] = false - } - - cfgService, withService := config["service"].(map[interface{}]interface{}) - if !withService { - return nil - } - - pipeline, withPipeline := cfgService["pipelines"].(map[interface{}]interface{}) - if !withPipeline { - return nil - } - availablePipelines := map[string]bool{} - - for pipID := range pipeline { - //Safe Cast - pipelineID, existsPipeline := pipID.(string) - if !existsPipeline { - return nil - } - //Getting all the available pipelines. - availablePipelines[pipelineID] = true - } - - if len(pipeline) > 0 { - for pipelineID, pipelineCfg := range pipeline { - //Safe Cast - pipelineV, withPipelineCfg := pipelineID.(string) - if !withPipelineCfg { - continue - } - //Condition will get information if there are multiple configured pipelines. - if len(pipelineV) > 0 { - pipelineDesc, ok := pipelineCfg.(map[interface{}]interface{}) - if !ok { - return nil - } - for pipSpecID, pipSpecCfg := range pipelineDesc { - if pipSpecID.(string) == componentTypePlural { - receiversList, ok := pipSpecCfg.([]interface{}) - if !ok { - continue - } - // If receiversList is empty means that we haven't any enabled Receiver. - if len(receiversList) == 0 { - availableComponents = nil - } else { - // All enabled receivers will be set as true - for _, comKey := range receiversList { - //Safe Cast - receiverKey, ok := comKey.(string) - if !ok { - return nil - } - availableComponents[receiverKey] = true - } - } - //Removing all non-enabled receivers - for comID, comKey := range availableComponents { - if !(comKey) { - delete(availableComponents, comID) - } - } - } - } - } - } - } - return availableComponents -} diff --git a/internal/manifests/collector/adapters/config_validate_test.go b/internal/manifests/collector/adapters/config_validate_test.go deleted file mode 100644 index 7003235fed..0000000000 --- a/internal/manifests/collector/adapters/config_validate_test.go +++ /dev/null @@ -1,103 +0,0 @@ -// 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 adapters - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestConfigValidate(t *testing.T) { - // prepare - - // First Test - Exporters - configStr := ` -receivers: - httpd/mtls: - protocols: - http: - endpoint: mysite.local:55690 - jaeger: - protocols: - grpc: - prometheus: - protocols: - grpc: - -processors: - -exporters: - debug: - -service: - pipelines: - metrics: - receivers: [httpd/mtls, jaeger] - exporters: [debug] - metrics/1: - receivers: [httpd/mtls, jaeger] - exporters: [debug] -` - // // prepare - config, err := ConfigFromString(configStr) - require.NoError(t, err) - require.NotEmpty(t, config) - - // test - check := getEnabledComponents(config, ComponentTypeReceiver) - require.NotEmpty(t, check) -} - -func TestEmptyEnabledReceivers(t *testing.T) { - // prepare - - // First Test - Exporters - configStr := ` -receivers: - httpd/mtls: - protocols: - http: - endpoint: mysite.local:55690 - jaeger: - protocols: - grpc: - prometheus: - protocols: - grpc: - -processors: - -exporters: - debug: - -service: - pipelines: - metrics: - receivers: [] - exporters: [] - metrics/1: - receivers: [] - exporters: [] -` - // // prepare - config, err := ConfigFromString(configStr) - require.NoError(t, err) - require.NotEmpty(t, config) - - // test - check := getEnabledComponents(config, ComponentTypeReceiver) - require.Empty(t, check) -} diff --git a/internal/manifests/collector/parser/exporter/exporter.go b/internal/manifests/collector/parser/exporter/exporter.go deleted file mode 100644 index 93c66b8599..0000000000 --- a/internal/manifests/collector/parser/exporter/exporter.go +++ /dev/null @@ -1,128 +0,0 @@ -// 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 is for parsing the OpenTelemetry Collector configuration. -package exporter - -import ( - "errors" - "fmt" - "regexp" - "strconv" - "strings" - - "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" -) - -// 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) 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{}) (parser.ComponentPortParser, error) { - builder := BuilderFor(name) - if builder == nil { - return nil, fmt.Errorf("no builders for %s", name) - } - return builder(logger, name, config), nil -} - -// Register adds a new parser builder to the list of known builders. -func Register(name string, builder parser.Builder) { - registry[name] = builder -} - -// IsRegistered checks whether a parser is registered with the given name. -func IsRegistered(name string) bool { - _, ok := registry[name] - return ok -} - -var ( - endpointKey = "endpoint" -) - -func singlePortFromConfigEndpoint(logger logr.Logger, name string, config map[interface{}]interface{}) *corev1.ServicePort { - endpoint := getAddressFromConfig(logger, name, endpointKey, config) - - switch e := endpoint.(type) { - case nil: - break - case string: - port, err := portFromEndpoint(e) - if err != nil { - logger.WithValues(endpointKey, e).Error(err, "couldn't parse the endpoint's port") - return nil - } - - return &corev1.ServicePort{ - Name: naming.PortName(name, port), - Port: port, - } - default: - logger.WithValues(endpointKey, endpoint).Error(fmt.Errorf("unrecognized type %T", endpoint), "exporter's endpoint isn't a string") - } - - return nil -} - -func getAddressFromConfig(logger logr.Logger, name, key string, config map[interface{}]interface{}) interface{} { - endpoint, ok := config[key] - if !ok { - logger.V(2).Info("%s exporter doesn't have an %s", name, key) - return nil - } - return endpoint -} - -func portFromEndpoint(endpoint string) (int32, error) { - var err error - var port int64 - - r := regexp.MustCompile(":[0-9]+") - - if r.MatchString(endpoint) { - port, err = strconv.ParseInt(strings.Replace(r.FindString(endpoint), ":", "", -1), 10, 32) - - if err != nil { - return 0, err - } - } - - if port == 0 { - return 0, errors.New("port should not be empty") - } - - return int32(port), err -} - -func exporterType(name string) string { - // exporters have a name like: - // - myexporter/custom - // - myexporter - // we extract the "myexporter" part and see if we have a parser for the exporter - if strings.Contains(name, "/") { - return name[:strings.Index(name, "/")] - } - - return name -} diff --git a/internal/manifests/collector/parser/exporter/exporter_prometheus.go b/internal/manifests/collector/parser/exporter/exporter_prometheus.go deleted file mode 100644 index 30047de70e..0000000000 --- a/internal/manifests/collector/parser/exporter/exporter_prometheus.go +++ /dev/null @@ -1,77 +0,0 @@ -// 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 exporter - -import ( - "github.com/go-logr/logr" - 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 _ parser.ComponentPortParser = &PrometheusExporterParser{} - -const ( - parserNamePrometheus = "__prometheus" - defaultPrometheusPort = 8888 -) - -// PrometheusExporterParser parses the configuration for OTLP receivers. -type PrometheusExporterParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewPrometheusExporterParser builds a new parser for OTLP receivers. -func NewPrometheusExporterParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { - return &PrometheusExporterParser{ - logger: logger, - name: name, - config: config, - } -} - -// Ports returns all the service ports for all protocols in this parser. -func (o *PrometheusExporterParser) Ports() ([]corev1.ServicePort, error) { - ports := []corev1.ServicePort{} - if o.config == nil { - ports = append(ports, - corev1.ServicePort{ - Name: naming.PortName(o.name, defaultPrometheusPort), - Port: defaultPrometheusPort, - TargetPort: intstr.FromInt(int(defaultPrometheusPort)), - Protocol: corev1.ProtocolTCP, - }, - ) - } else { - if port := singlePortFromConfigEndpoint(o.logger, o.name, o.config); port != nil { - ports = append(ports, *port) - } - } - - return ports, nil -} - -// ParserName returns the name of this parser. -func (o *PrometheusExporterParser) ParserName() string { - return parserNamePrometheus -} - -func init() { - Register("prometheus", NewPrometheusExporterParser) -} diff --git a/internal/manifests/collector/parser/exporter/exporter_test.go b/internal/manifests/collector/parser/exporter/exporter_test.go deleted file mode 100644 index bc468be110..0000000000 --- a/internal/manifests/collector/parser/exporter/exporter_test.go +++ /dev/null @@ -1,79 +0,0 @@ -// 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 exporter - -import ( - "testing" - - "github.com/stretchr/testify/assert" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/intstr" -) - -func TestPorts(t *testing.T) { - tests := []struct { - testName string - parser *PrometheusExporterParser - want []v1.ServicePort - }{ - { - testName: "Valid Configuration", - parser: &PrometheusExporterParser{ - name: "test-exporter", - config: map[interface{}]interface{}{ - "endpoint": "http://myprometheus.io:9090", - }, - }, - want: []v1.ServicePort{ - { - Name: "test-exporter", - Port: 9090, - }, - }, - }, - { - testName: "Empty Configuration", - parser: &PrometheusExporterParser{ - name: "test-exporter", - config: nil, // Simulate no configuration provided - }, - want: []v1.ServicePort{ - { - Name: "test-exporter", - Port: defaultPrometheusPort, - TargetPort: intstr.FromInt(int(defaultPrometheusPort)), - Protocol: v1.ProtocolTCP, - }, - }, - }, - { - testName: "Invalid Endpoint No Port", - parser: &PrometheusExporterParser{ - name: "test-exporter", - config: map[interface{}]interface{}{ - "endpoint": "invalidendpoint", - }, - }, - want: []v1.ServicePort{}, - }, - } - - for _, tt := range tests { - t.Run(tt.testName, func(t *testing.T) { - ports, _ := tt.parser.Ports() - assert.Equal(t, tt.want, ports) - }) - } -} diff --git a/internal/manifests/collector/parser/parser.go b/internal/manifests/collector/parser/parser.go deleted file mode 100644 index 62de283b15..0000000000 --- a/internal/manifests/collector/parser/parser.go +++ /dev/null @@ -1,31 +0,0 @@ -// 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/processor/processor.go b/internal/manifests/collector/parser/processor/processor.go deleted file mode 100644 index 784fffeade..0000000000 --- a/internal/manifests/collector/parser/processor/processor.go +++ /dev/null @@ -1,73 +0,0 @@ -// 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 is for parsing the OpenTelemetry Collector configuration. -package processor - -import ( - "fmt" - "strings" - - "github.com/go-logr/logr" - rbacv1 "k8s.io/api/rbac/v1" -) - -// ProcessorParser specifies the methods to implement to parse a processor. -type ProcessorParser interface { - ParserName() string - GetRBACRules() []rbacv1.PolicyRule -} - -// Builder specifies the signature required for parser builders. -type Builder func(logr.Logger, string, map[interface{}]interface{}) ProcessorParser - -// registry holds a record of all known processor parsers. -var registry = make(map[string]Builder) - -// BuilderFor returns a parser builder for the given processor name. -func BuilderFor(name string) Builder { - return registry[processorType(name)] -} - -// For returns a new parser for the given processor name + config. -func For(logger logr.Logger, name string, config map[interface{}]interface{}) (ProcessorParser, error) { - builder := BuilderFor(name) - if builder == nil { - return nil, fmt.Errorf("no builders for %s", name) - } - return builder(logger, name, config), nil -} - -// Register adds a new parser builder to the list of known builders. -func Register(name string, builder Builder) { - registry[name] = builder -} - -// IsRegistered checks whether a parser is registered with the given name. -func IsRegistered(name string) bool { - _, ok := registry[name] - return ok -} - -func processorType(name string) string { - // processors have a name like: - // - myprocessor/custom - // - myprocessor - // we extract the "myprocessor" part and see if we have a parser for the processor - if strings.Contains(name, "/") { - return name[:strings.Index(name, "/")] - } - - return name -} diff --git a/internal/manifests/collector/parser/processor/processor_k8sattributes.go b/internal/manifests/collector/parser/processor/processor_k8sattributes.go deleted file mode 100644 index 76fb45e08f..0000000000 --- a/internal/manifests/collector/parser/processor/processor_k8sattributes.go +++ /dev/null @@ -1,106 +0,0 @@ -// 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 processor - -import ( - "fmt" - "strings" - - "github.com/go-logr/logr" - rbacv1 "k8s.io/api/rbac/v1" -) - -var _ ProcessorParser = &K8sAttributesParser{} - -const ( - parserNameK8sAttributes = "__k8sattributes" -) - -// PrometheusExporterParser parses the configuration for k8sattributes processor. -type K8sAttributesParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewK8sAttributesParser builds a new parser k8sattributes processor. -func NewK8sAttributesParser(logger logr.Logger, name string, config map[interface{}]interface{}) ProcessorParser { - return &K8sAttributesParser{ - logger: logger, - name: name, - config: config, - } -} - -// ParserName returns the name of this parser. -func (o *K8sAttributesParser) ParserName() string { - return parserNameK8sAttributes -} - -func (o *K8sAttributesParser) GetRBACRules() []rbacv1.PolicyRule { - // These policies need to be added always - var prs []rbacv1.PolicyRule = []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"pods", "namespaces"}, - Verbs: []string{"get", "watch", "list"}, - }, - } - - replicasetPolicy := rbacv1.PolicyRule{ - APIGroups: []string{"apps"}, - Resources: []string{"replicasets"}, - Verbs: []string{"get", "watch", "list"}, - } - - extractCfg, ok := o.config["extract"] - if !ok { - // k8s.deployment.name is enabled by default so, replicasets permissions are needed - // https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/32248#discussion_r1560077826 - prs = append(prs, replicasetPolicy) - return prs - } - - metadataCfg, ok := extractCfg.(map[interface{}]interface{})["metadata"] - if !ok { - return prs - } - - metadata, ok := metadataCfg.([]interface{}) - if !ok { - return prs - } - - for _, m := range metadata { - metadataField := fmt.Sprint(m) - if metadataField == "k8s.deployment.uid" || metadataField == "k8s.deployment.name" { - prs = append(prs, replicasetPolicy) - } else if strings.Contains(metadataField, "k8s.node") { - prs = append(prs, - rbacv1.PolicyRule{ - APIGroups: []string{""}, - Resources: []string{"nodes"}, - Verbs: []string{"get", "watch", "list"}, - }, - ) - } - } - - return prs -} - -func init() { - Register("k8sattributes", NewK8sAttributesParser) -} diff --git a/internal/manifests/collector/parser/processor/processor_k8sattributes_test.go b/internal/manifests/collector/parser/processor/processor_k8sattributes_test.go deleted file mode 100644 index 7274ffaa3d..0000000000 --- a/internal/manifests/collector/parser/processor/processor_k8sattributes_test.go +++ /dev/null @@ -1,144 +0,0 @@ -// 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 processor - -import ( - "testing" - - "github.com/stretchr/testify/assert" - rbacv1 "k8s.io/api/rbac/v1" - logf "sigs.k8s.io/controller-runtime/pkg/log" -) - -var logger = logf.Log.WithName("unit-tests") - -func TestK8sAttributesRBAC(t *testing.T) { - - tests := []struct { - name string - config map[interface{}]interface{} - expectedRules []rbacv1.PolicyRule - }{ - { - name: "no extra parameters", - config: nil, - expectedRules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"pods", "namespaces"}, - Verbs: []string{"get", "watch", "list"}, - }, - { - APIGroups: []string{"apps"}, - Resources: []string{"replicasets"}, - Verbs: []string{"get", "watch", "list"}, - }, - }, - }, - { - name: "extract k8s.deployment.name", - config: map[interface{}]interface{}{ - "extract": map[interface{}]interface{}{ - "metadata": []interface{}{ - "k8s.deployment.name", - }, - }, - }, - expectedRules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"pods", "namespaces"}, - Verbs: []string{"get", "watch", "list"}, - }, - { - APIGroups: []string{"apps"}, - Resources: []string{"replicasets"}, - Verbs: []string{"get", "watch", "list"}, - }, - }, - }, - { - name: "extract k8s.deployment.uid", - config: map[interface{}]interface{}{ - "extract": map[interface{}]interface{}{ - "metadata": []interface{}{ - "k8s.deployment.uid", - }, - }, - }, - expectedRules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"pods", "namespaces"}, - Verbs: []string{"get", "watch", "list"}, - }, - { - APIGroups: []string{"apps"}, - Resources: []string{"replicasets"}, - Verbs: []string{"get", "watch", "list"}, - }, - }, - }, - { - name: "extract k8s.pod.name", - config: map[interface{}]interface{}{ - "extract": map[interface{}]interface{}{ - "metadata": []interface{}{ - "k8s.pod.name", - }, - }, - }, - expectedRules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"pods", "namespaces"}, - Verbs: []string{"get", "watch", "list"}, - }, - }, - }, - { - name: "extract k8s.node", - config: map[interface{}]interface{}{ - "extract": map[interface{}]interface{}{ - "metadata": []interface{}{ - "k8s.node", - }, - }, - }, - expectedRules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"pods", "namespaces"}, - Verbs: []string{"get", "watch", "list"}, - }, - { - APIGroups: []string{""}, - Resources: []string{"nodes"}, - Verbs: []string{"get", "watch", "list"}, - }, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - p := NewK8sAttributesParser(logger, "test", tt.config) - rules := p.GetRBACRules() - assert.Equal(t, tt.expectedRules, rules) - }) - - } - -} diff --git a/internal/manifests/collector/parser/processor/processor_resourcedetection.go b/internal/manifests/collector/parser/processor/processor_resourcedetection.go deleted file mode 100644 index 4145f6baa6..0000000000 --- a/internal/manifests/collector/parser/processor/processor_resourcedetection.go +++ /dev/null @@ -1,87 +0,0 @@ -// 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 processor - -import ( - "fmt" - - "github.com/go-logr/logr" - rbacv1 "k8s.io/api/rbac/v1" -) - -var _ ProcessorParser = &ResourceDetectionParser{} - -const ( - parserNameResourceDetection = "__resourcedetection" -) - -// PrometheusExporterParser parses the configuration for OTLP receivers. -type ResourceDetectionParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewPrometheusExporterParser builds a new parser for OTLP receivers. -func NewResourceDetectionParser(logger logr.Logger, name string, config map[interface{}]interface{}) ProcessorParser { - return &ResourceDetectionParser{ - logger: logger, - name: name, - config: config, - } -} - -// ParserName returns the name of this parser. -func (o *ResourceDetectionParser) ParserName() string { - return parserNameResourceDetection -} - -func (o *ResourceDetectionParser) GetRBACRules() []rbacv1.PolicyRule { - var prs []rbacv1.PolicyRule - - detectorsCfg, ok := o.config["detectors"] - if !ok { - return prs - } - - detectors, ok := detectorsCfg.([]interface{}) - if !ok { - return prs - } - for _, d := range detectors { - detectorName := fmt.Sprint(d) - switch detectorName { - case "k8snode": - policy := rbacv1.PolicyRule{ - APIGroups: []string{""}, - Resources: []string{"nodes"}, - Verbs: []string{"get", "list"}, - } - prs = append(prs, policy) - case "openshift": - policy := rbacv1.PolicyRule{ - APIGroups: []string{"config.openshift.io"}, - Resources: []string{"infrastructures", "infrastructures/status"}, - Verbs: []string{"get", "watch", "list"}, - } - prs = append(prs, policy) - } - } - return prs -} - -func init() { - Register("resourcedetection", NewResourceDetectionParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver.go b/internal/manifests/collector/parser/receiver/receiver.go deleted file mode 100644 index 127891747b..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver.go +++ /dev/null @@ -1,180 +0,0 @@ -// 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 is for parsing the OpenTelemetry Collector configuration. -package receiver - -import ( - "errors" - "fmt" - "regexp" - "strconv" - "strings" - - "github.com/go-logr/logr" - 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" -) - -// 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) parser.Builder { - builder := registry[receiverType(name)] - if builder == nil { - builder = NewGenericReceiverParser - } - - return builder -} - -// For returns a new parser for the given receiver name + config. -func For(logger logr.Logger, name string, config map[interface{}]interface{}) (parser.ComponentPortParser, error) { - builder := BuilderFor(name) - return builder(logger, name, config), nil -} - -// Register adds a new parser builder to the list of known builders. -func Register(name string, builder parser.Builder) { - registry[name] = builder -} - -// IsRegistered checks whether a parser is registered with the given name. -func IsRegistered(name string) bool { - _, ok := registry[name] - return ok -} - -var ( - endpointKey = "endpoint" - listenAddressKey = "listen_address" - scraperReceivers = map[string]struct{}{ - "prometheus": {}, - "kubeletstats": {}, - "sshcheck": {}, - "cloudfoundry": {}, - "vcenter": {}, - "oracledb": {}, - "snmp": {}, - "googlecloudpubsub": {}, - "chrony": {}, - "jmx": {}, - "podman_stats": {}, - "pulsar": {}, - "docker_stats": {}, - "aerospike": {}, - "zookeeper": {}, - "prometheus_simple": {}, - "saphana": {}, - "riak": {}, - "redis": {}, - "rabbitmq": {}, - "purefb": {}, - "postgresql": {}, - "nsxt": {}, - "nginx": {}, - "mysql": {}, - "memcached": {}, - "httpcheck": {}, - "haproxy": {}, - "flinkmetrics": {}, - "couchdb": {}, - } -) - -func isScraperReceiver(name string) bool { - _, exists := scraperReceivers[name] - return exists -} - -func singlePortFromConfigEndpoint(logger logr.Logger, name string, config map[interface{}]interface{}) *v1.ServicePort { - var endpoint interface{} - var receiverType = receiverType(name) - switch { - // ignore the receiver as it holds the field key endpoint, and it - // is a scraper, we only expose endpoint through k8s service objects for - // receivers that aren't scrapers. - case isScraperReceiver(receiverType): - return nil - - default: - endpoint = getAddressFromConfig(logger, name, endpointKey, config) - } - - switch e := endpoint.(type) { - case nil: - break - case string: - port, err := portFromEndpoint(e) - if err != nil { - logger.WithValues(endpointKey, e).Error(err, "couldn't parse the endpoint's port") - return nil - } - - return &corev1.ServicePort{ - Name: naming.PortName(name, port), - Port: port, - } - default: - logger.WithValues(endpointKey, endpoint).Error(fmt.Errorf("unrecognized type %T", endpoint), "receiver's endpoint isn't a string") - } - - return nil -} - -func getAddressFromConfig(logger logr.Logger, name, key string, config map[interface{}]interface{}) interface{} { - endpoint, ok := config[key] - if !ok { - logger.V(2).Info("%s receiver doesn't have an %s", name, key) - return nil - } - return endpoint -} - -func portFromEndpoint(endpoint string) (int32, error) { - var err error - var port int64 - - r := regexp.MustCompile(":[0-9]+") - - if r.MatchString(endpoint) { - port, err = strconv.ParseInt(strings.Replace(r.FindString(endpoint), ":", "", -1), 10, 32) - - if err != nil { - return 0, err - } - } - - if port == 0 { - return 0, errors.New("port should not be empty") - } - - return int32(port), err -} - -func receiverType(name string) string { - // receivers have a name like: - // - myreceiver/custom - // - myreceiver - // we extract the "myreceiver" part and see if we have a parser for the receiver - if strings.Contains(name, "/") { - return name[:strings.Index(name, "/")] - } - - return name -} diff --git a/internal/manifests/collector/parser/receiver/receiver_aws-xray.go b/internal/manifests/collector/parser/receiver/receiver_aws-xray.go deleted file mode 100644 index 44618b3aa5..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_aws-xray.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 2000, - parserName: parserNameAWSXRAY, - } -} - -func init() { - Register("awsxray", NewAWSXrayReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_aws-xray_test.go b/internal/manifests/collector/parser/receiver/receiver_aws-xray_test.go deleted file mode 100644 index 5a99f9e893..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_aws-xray_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the AWS XRAY parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_carbon.go b/internal/manifests/collector/parser/receiver/receiver_carbon.go deleted file mode 100644 index b1b0aaa4ce..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_carbon.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 2003, - parserName: parserNameCarbon, - } -} - -func init() { - Register("carbon", NewCarbonReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_carbon_test.go b/internal/manifests/collector/parser/receiver/receiver_carbon_test.go deleted file mode 100644 index 370732182d..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_carbon_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the Carbon parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_collectd.go b/internal/manifests/collector/parser/receiver/receiver_collectd.go deleted file mode 100644 index aa42ab0397..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_collectd.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 8081, - parserName: parserNameCollectd, - } -} - -func init() { - Register("collectd", NewCollectdReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_collectd_test.go b/internal/manifests/collector/parser/receiver/receiver_collectd_test.go deleted file mode 100644 index 5e0e6d0121..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_collectd_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the Collectd parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go b/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go deleted file mode 100644 index 88881923fa..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_fluent-forward.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 8006, - parserName: parserNameFluentForward, - } -} - -func init() { - Register("fluentforward", NewFluentForwardReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_fluent-forward_test.go b/internal/manifests/collector/parser/receiver/receiver_fluent-forward_test.go deleted file mode 100644 index af15006983..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_fluent-forward_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the FluentForward parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_generic.go b/internal/manifests/collector/parser/receiver/receiver_generic.go deleted file mode 100644 index 864b5bb111..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_generic.go +++ /dev/null @@ -1,77 +0,0 @@ -// 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 receiver - -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 _ 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 { - config map[interface{}]interface{} - defaultAppProtocol *string - logger logr.Logger - name string - defaultProtocol corev1.Protocol - parserName string - defaultPort int32 -} - -// NOTE: Operator will sync with only receivers that aren't scrapers. Operator sync up receivers -// 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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - parserName: parserNameGeneric, - } -} - -// Ports returns all the service ports for all protocols in this parser. -func (g *GenericReceiver) Ports() ([]corev1.ServicePort, error) { - port := singlePortFromConfigEndpoint(g.logger, g.name, g.config) - if port != nil { - port.Protocol = g.defaultProtocol - port.AppProtocol = g.defaultAppProtocol - return []corev1.ServicePort{*port}, nil - } - - if g.defaultPort > 0 { - return []corev1.ServicePort{{ - Port: g.defaultPort, - Name: naming.PortName(g.name, g.defaultPort), - Protocol: g.defaultProtocol, - AppProtocol: g.defaultAppProtocol, - }}, nil - } - - return []corev1.ServicePort{}, nil -} - -// ParserName returns the name of this parser. -func (g *GenericReceiver) ParserName() string { - return g.parserName -} diff --git a/internal/manifests/collector/parser/receiver/receiver_generic_test.go b/internal/manifests/collector/parser/receiver/receiver_generic_test.go deleted file mode 100644 index 1adfcf12df..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_generic_test.go +++ /dev/null @@ -1,125 +0,0 @@ -// 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 receiver_test - -import ( - "testing" - - "github.com/go-logr/logr" - "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" -) - -var logger = logf.Log.WithName("unit-tests") - -func TestParseEndpoint(t *testing.T) { - // prepare - // there's no parser registered to handle "myreceiver", so, it falls back to the generic parser - builder := receiver.NewGenericReceiverParser(logger, "myreceiver", map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1234", - }) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 1) - assert.EqualValues(t, 1234, ports[0].Port) -} - -func TestFailedToParseEndpoint(t *testing.T) { - // prepare - // there's no parser registered to handle "myreceiver", so, it falls back to the generic parser - builder := receiver.NewGenericReceiverParser(logger, "myreceiver", map[interface{}]interface{}{ - "endpoint": "0.0.0.0", - }) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 0) -} - -func TestDownstreamParsers(t *testing.T) { - for _, tt := range []struct { - builder func(logr.Logger, string, map[interface{}]interface{}) parser.ComponentPortParser - desc string - receiverName string - parserName string - defaultPort int - }{ - {receiver.NewZipkinReceiverParser, "zipkin", "zipkin", "__zipkin", 9411}, - {receiver.NewOpenCensusReceiverParser, "opencensus", "opencensus", "__opencensus", 55678}, - - // contrib receivers - {receiver.NewCarbonReceiverParser, "carbon", "carbon", "__carbon", 2003}, - {receiver.NewCollectdReceiverParser, "collectd", "collectd", "__collectd", 8081}, - {receiver.NewSAPMReceiverParser, "sapm", "sapm", "__sapm", 7276}, - {receiver.NewSignalFxReceiverParser, "signalfx", "signalfx", "__signalfx", 9943}, - {receiver.NewWavefrontReceiverParser, "wavefront", "wavefront", "__wavefront", 2003}, - {receiver.NewZipkinScribeReceiverParser, "zipkin-scribe", "zipkin-scribe", "__zipkinscribe", 9410}, - {receiver.NewFluentForwardReceiverParser, "fluentforward", "fluentforward", "__fluentforward", 8006}, - {receiver.NewStatsdReceiverParser, "statsd", "statsd", "__statsd", 8125}, - {receiver.NewInfluxdbReceiverParser, "influxdb", "influxdb", "__influxdb", 8086}, - {receiver.NewSplunkHecReceiverParser, "splunk-hec", "splunk-hec", "__splunk_hec", 8088}, - {receiver.NewAWSXrayReceiverParser, "awsxray", "awsxray", "__awsxray", 2000}, - } { - t.Run(tt.receiverName, func(t *testing.T) { - t.Run("builds successfully", func(t *testing.T) { - // test - builder := tt.builder(logger, tt.receiverName, map[interface{}]interface{}{}) - - // verify - assert.Equal(t, tt.parserName, builder.ParserName()) - }) - - t.Run("assigns the expected port", func(t *testing.T) { - // prepare - builder := tt.builder(logger, tt.receiverName, map[interface{}]interface{}{}) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 1) - assert.EqualValues(t, tt.defaultPort, ports[0].Port) - assert.Equal(t, tt.receiverName, ports[0].Name) - }) - - t.Run("allows port to be overridden", func(t *testing.T) { - // prepare - builder := tt.builder(logger, tt.receiverName, map[interface{}]interface{}{ - "endpoint": "0.0.0.0:65535", - }) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 1) - assert.EqualValues(t, 65535, ports[0].Port) - assert.Equal(t, tt.receiverName, ports[0].Name) - }) - }) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_influxdb.go b/internal/manifests/collector/parser/receiver/receiver_influxdb.go deleted file mode 100644 index 0930a29f73..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_influxdb.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 8086, - parserName: parserNameInfluxdb, - } -} - -func init() { - Register("influxdb", NewInfluxdbReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_influxdb_test.go b/internal/manifests/collector/parser/receiver/receiver_influxdb_test.go deleted file mode 100644 index 94f596ee06..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_influxdb_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the Influxdb parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_jaeger.go b/internal/manifests/collector/parser/receiver/receiver_jaeger.go deleted file mode 100644 index dcc99d8bd9..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_jaeger.go +++ /dev/null @@ -1,138 +0,0 @@ -// 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 receiver - -import ( - "fmt" - - "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 _ parser.ComponentPortParser = &JaegerReceiverParser{} - -const ( - parserNameJaeger = "__jaeger" - - defaultGRPCPort int32 = 14250 - defaultThriftHTTPPort int32 = 14268 - defaultThriftCompactPort int32 = 6831 - defaultThriftBinaryPort int32 = 6832 -) - -// JaegerReceiverParser parses the configuration for Jaeger-specific receivers. -type JaegerReceiverParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewJaegerReceiverParser builds a new parser for Jaeger receivers. -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, - name: name, - config: protocols, - } - } - - return &JaegerReceiverParser{ - name: name, - config: map[interface{}]interface{}{}, - } -} - -// Ports returns all the service ports for all protocols in this parser. -func (j *JaegerReceiverParser) Ports() ([]corev1.ServicePort, error) { - ports := []corev1.ServicePort{} - - for _, protocol := range []struct { - name string - transportProtocol corev1.Protocol - appProtocol string - defaultPort int32 - }{ - { - name: "grpc", - defaultPort: defaultGRPCPort, - transportProtocol: corev1.ProtocolTCP, - appProtocol: "grpc", - }, - { - name: "thrift_http", - defaultPort: defaultThriftHTTPPort, - transportProtocol: corev1.ProtocolTCP, - appProtocol: "http", - }, - { - name: "thrift_compact", - defaultPort: defaultThriftCompactPort, - transportProtocol: corev1.ProtocolUDP, - }, - { - name: "thrift_binary", - defaultPort: defaultThriftBinaryPort, - transportProtocol: corev1.ProtocolUDP, - }, - } { - // do we have the protocol specified at all? - if receiverProtocol, ok := j.config[protocol.name]; ok { - // we have the specified protocol, we definitely need a service port - nameWithProtocol := fmt.Sprintf("%s-%s", j.name, protocol.name) - var protocolPort *corev1.ServicePort - - // do we have a configuration block for the protocol? - settings, ok := receiverProtocol.(map[interface{}]interface{}) - if ok { - protocolPort = singlePortFromConfigEndpoint(j.logger, nameWithProtocol, settings) - } - - // have we parsed a port based on the configuration block? - // if not, we use the default port - if protocolPort == nil { - protocolPort = &corev1.ServicePort{ - Name: naming.PortName(nameWithProtocol, protocol.defaultPort), - Port: protocol.defaultPort, - } - } - - // set the appropriate transport protocol (i.e. TCP/UDP) for this kind of receiver protocol - protocolPort.Protocol = protocol.transportProtocol - - if protocol.appProtocol != "" { - c := protocol.appProtocol - protocolPort.AppProtocol = &c - } - - // at this point, we *have* a port specified, add it to the list of ports - ports = append(ports, *protocolPort) - } - } - - return ports, nil -} - -// ParserName returns the name of this parser. -func (j *JaegerReceiverParser) ParserName() string { - return parserNameJaeger -} - -func init() { - Register("jaeger", NewJaegerReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_jaeger_test.go b/internal/manifests/collector/parser/receiver/receiver_jaeger_test.go deleted file mode 100644 index dadf3e0cb5..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_jaeger_test.go +++ /dev/null @@ -1,115 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" - corev1 "k8s.io/api/core/v1" -) - -func TestJaegerSelfRegisters(t *testing.T) { - // verify - assert.True(t, IsRegistered("jaeger")) -} - -func TestJaegerIsFoundByName(t *testing.T) { - // test - p, err := For(logger, "jaeger", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // verify - assert.Equal(t, "__jaeger", p.ParserName()) -} - -func TestJaegerMinimalConfiguration(t *testing.T) { - // prepare - builder := NewJaegerReceiverParser(logger, "jaeger", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{}, - }, - }) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 1) - assert.EqualValues(t, 14250, ports[0].Port) - assert.EqualValues(t, corev1.ProtocolTCP, ports[0].Protocol) -} - -func TestJaegerPortsOverridden(t *testing.T) { - // prepare - builder := NewJaegerReceiverParser(logger, "jaeger", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1234", - }, - }, - }) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 1) - assert.EqualValues(t, 1234, ports[0].Port) - assert.EqualValues(t, corev1.ProtocolTCP, ports[0].Protocol) -} - -func TestJaegerExposeDefaultPorts(t *testing.T) { - // prepare - builder := NewJaegerReceiverParser(logger, "jaeger", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{}, - "thrift_http": map[interface{}]interface{}{}, - "thrift_compact": map[interface{}]interface{}{}, - "thrift_binary": map[interface{}]interface{}{}, - }, - }) - - expectedResults := map[string]struct { - transportProtocol corev1.Protocol - portNumber int32 - seen bool - }{ - "jaeger-grpc": {portNumber: 14250, transportProtocol: corev1.ProtocolTCP}, - "port-14268": {portNumber: 14268, transportProtocol: corev1.ProtocolTCP}, - "port-6831": {portNumber: 6831, transportProtocol: corev1.ProtocolUDP}, - "port-6832": {portNumber: 6832, transportProtocol: corev1.ProtocolUDP}, - } - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 4) - - for _, port := range ports { - r := expectedResults[port.Name] - r.seen = true - expectedResults[port.Name] = r - assert.EqualValues(t, r.portNumber, port.Port) - assert.EqualValues(t, r.transportProtocol, port.Protocol) - } - for k, v := range expectedResults { - assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_loki.go b/internal/manifests/collector/parser/receiver/receiver_loki.go deleted file mode 100644 index 6cdac81356..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_loki.go +++ /dev/null @@ -1,131 +0,0 @@ -// 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 receiver - -import ( - "fmt" - - "github.com/go-logr/logr" - 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 _ parser.ComponentPortParser = &LokiReceiverParser{} - -const ( - parserNameLoki = "__loki" - - defaultLokiGRPCPort int32 = 9095 - defaultLokiHTTPPort int32 = 3100 -) - -// LokiReceiverParser parses the configuration for Loki receivers. -type LokiReceiverParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewLokiReceiverParser builds a new parser for Loki receivers. -func NewLokiReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { - if protocols, ok := config["protocols"].(map[interface{}]interface{}); ok { - return &LokiReceiverParser{ - logger: logger, - name: name, - config: protocols, - } - } - - return &LokiReceiverParser{ - name: name, - config: map[interface{}]interface{}{}, - } -} - -// Ports returns all the service ports for all protocols in this parser. -func (o *LokiReceiverParser) Ports() ([]corev1.ServicePort, error) { - ports := []corev1.ServicePort{} - - for _, protocol := range []struct { - name string - defaultPorts []corev1.ServicePort - }{ - { - name: grpc, - defaultPorts: []corev1.ServicePort{ - { - Name: naming.PortName(fmt.Sprintf("%s-grpc", o.name), defaultLokiGRPCPort), - Port: defaultLokiGRPCPort, - TargetPort: intstr.FromInt(int(defaultLokiGRPCPort)), - AppProtocol: &grpc, - }, - }, - }, - { - name: http, - defaultPorts: []corev1.ServicePort{ - { - Name: naming.PortName(fmt.Sprintf("%s-http", o.name), defaultLokiHTTPPort), - Port: defaultLokiHTTPPort, - TargetPort: intstr.FromInt(int(defaultLokiHTTPPort)), - AppProtocol: &http, - }, - }, - }, - } { - // do we have the protocol specified at all? - if receiverProtocol, ok := o.config[protocol.name]; ok { - // we have the specified protocol, we definitely need a service port - nameWithProtocol := fmt.Sprintf("%s-%s", o.name, protocol.name) - var protocolPort *corev1.ServicePort - - // do we have a configuration block for the protocol? - settings, ok := receiverProtocol.(map[interface{}]interface{}) - if ok { - protocolPort = singlePortFromConfigEndpoint(o.logger, nameWithProtocol, settings) - } - - // have we parsed a port based on the configuration block? - // if not, we use the default port - if protocolPort == nil { - ports = append(ports, protocol.defaultPorts...) - } else { - // infer protocol and appProtocol from protocol.name - if protocol.name == grpc { - protocolPort.Protocol = corev1.ProtocolTCP - protocolPort.AppProtocol = &grpc - } else if protocol.name == http { - protocolPort.Protocol = corev1.ProtocolTCP - protocolPort.AppProtocol = &http - } - ports = append(ports, *protocolPort) - } - } - } - - return ports, nil -} - -// ParserName returns the name of this parser. -func (o *LokiReceiverParser) ParserName() string { - return parserNameLoki -} - -func init() { - Register("loki", NewLokiReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_loki_test.go b/internal/manifests/collector/parser/receiver/receiver_loki_test.go deleted file mode 100644 index cc10edc9f1..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_loki_test.go +++ /dev/null @@ -1,109 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestLokiSelfRegisters(t *testing.T) { - // verify - assert.True(t, IsRegistered("loki")) -} - -func TestLokiIsFoundByName(t *testing.T) { - // test - p, err := For(logger, "loki", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // verify - assert.Equal(t, "__loki", p.ParserName()) -} - -func TestLokiPortsOverridden(t *testing.T) { - // prepare - builder := NewLokiReceiverParser(logger, "loki", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1234", - }, - "http": map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1235", - }, - }, - }) - - expectedResults := map[string]struct { - portNumber int32 - seen bool - }{ - "loki-grpc": {portNumber: 1234}, - "loki-http": {portNumber: 1235}, - } - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, len(expectedResults)) - - for _, port := range ports { - r := expectedResults[port.Name] - r.seen = true - expectedResults[port.Name] = r - assert.EqualValues(t, r.portNumber, port.Port) - } - for k, v := range expectedResults { - assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) - } -} - -func TestLokiExposeDefaultPorts(t *testing.T) { - // prepare - builder := NewLokiReceiverParser(logger, "loki", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{}, - "http": map[interface{}]interface{}{}, - }, - }) - - expectedResults := map[string]struct { - portNumber int32 - seen bool - }{ - "loki-grpc": {portNumber: 9095}, - "loki-http": {portNumber: 3100}, - } - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, len(expectedResults)) - - for _, port := range ports { - r := expectedResults[port.Name] - r.seen = true - expectedResults[port.Name] = r - assert.EqualValues(t, r.portNumber, port.Port) - } - for k, v := range expectedResults { - assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_oc.go b/internal/manifests/collector/parser/receiver/receiver_oc.go deleted file mode 100644 index 6619439a82..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_oc.go +++ /dev/null @@ -1,40 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - httpAppProtocol := "http" - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 55678, - parserName: parserNameOpenCensus, - defaultAppProtocol: &httpAppProtocol, - } -} - -func init() { - Register("opencensus", NewOpenCensusReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_oc_test.go b/internal/manifests/collector/parser/receiver/receiver_oc_test.go deleted file mode 100644 index 74b6062427..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_oc_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the OpenCensus parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_otlp.go b/internal/manifests/collector/parser/receiver/receiver_otlp.go deleted file mode 100644 index 68972fd950..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_otlp.go +++ /dev/null @@ -1,136 +0,0 @@ -// 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 receiver - -import ( - "fmt" - - "github.com/go-logr/logr" - 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 _ parser.ComponentPortParser = &OTLPReceiverParser{} - -const ( - parserNameOTLP = "__otlp" - - defaultOTLPGRPCPort int32 = 4317 - defaultOTLPHTTPPort int32 = 4318 -) - -var ( - grpc = "grpc" - http = "http" -) - -// OTLPReceiverParser parses the configuration for OTLP receivers. -type OTLPReceiverParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewOTLPReceiverParser builds a new parser for OTLP receivers. -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, - name: name, - config: protocols, - } - } - - return &OTLPReceiverParser{ - name: name, - config: map[interface{}]interface{}{}, - } -} - -// Ports returns all the service ports for all protocols in this parser. -func (o *OTLPReceiverParser) Ports() ([]corev1.ServicePort, error) { - ports := []corev1.ServicePort{} - - for _, protocol := range []struct { - name string - defaultPorts []corev1.ServicePort - }{ - { - name: grpc, - defaultPorts: []corev1.ServicePort{ - { - Name: naming.PortName(fmt.Sprintf("%s-grpc", o.name), defaultOTLPGRPCPort), - Port: defaultOTLPGRPCPort, - TargetPort: intstr.FromInt(int(defaultOTLPGRPCPort)), - AppProtocol: &grpc, - }, - }, - }, - { - name: http, - defaultPorts: []corev1.ServicePort{ - { - Name: naming.PortName(fmt.Sprintf("%s-http", o.name), defaultOTLPHTTPPort), - Port: defaultOTLPHTTPPort, - TargetPort: intstr.FromInt(int(defaultOTLPHTTPPort)), - AppProtocol: &http, - }, - }, - }, - } { - // do we have the protocol specified at all? - if receiverProtocol, ok := o.config[protocol.name]; ok { - // we have the specified protocol, we definitely need a service port - nameWithProtocol := fmt.Sprintf("%s-%s", o.name, protocol.name) - var protocolPort *corev1.ServicePort - - // do we have a configuration block for the protocol? - settings, ok := receiverProtocol.(map[interface{}]interface{}) - if ok { - protocolPort = singlePortFromConfigEndpoint(o.logger, nameWithProtocol, settings) - } - - // have we parsed a port based on the configuration block? - // if not, we use the default port - if protocolPort == nil { - ports = append(ports, protocol.defaultPorts...) - } else { - // infer protocol and appProtocol from protocol.name - if protocol.name == grpc { - protocolPort.Protocol = corev1.ProtocolTCP - protocolPort.AppProtocol = &grpc - } else if protocol.name == http { - protocolPort.Protocol = corev1.ProtocolTCP - protocolPort.AppProtocol = &http - } - ports = append(ports, *protocolPort) - } - } - } - - return ports, nil -} - -// ParserName returns the name of this parser. -func (o *OTLPReceiverParser) ParserName() string { - return parserNameOTLP -} - -func init() { - Register("otlp", NewOTLPReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_otlp_test.go b/internal/manifests/collector/parser/receiver/receiver_otlp_test.go deleted file mode 100644 index 7165153dde..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_otlp_test.go +++ /dev/null @@ -1,109 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestOTLPSelfRegisters(t *testing.T) { - // verify - assert.True(t, IsRegistered("otlp")) -} - -func TestOTLPIsFoundByName(t *testing.T) { - // test - p, err := For(logger, "otlp", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // verify - assert.Equal(t, "__otlp", p.ParserName()) -} - -func TestOTLPPortsOverridden(t *testing.T) { - // prepare - builder := NewOTLPReceiverParser(logger, "otlp", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1234", - }, - "http": map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1235", - }, - }, - }) - - expectedResults := map[string]struct { - portNumber int32 - seen bool - }{ - "otlp-grpc": {portNumber: 1234}, - "otlp-http": {portNumber: 1235}, - } - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, len(expectedResults)) - - for _, port := range ports { - r := expectedResults[port.Name] - r.seen = true - expectedResults[port.Name] = r - assert.EqualValues(t, r.portNumber, port.Port) - } - for k, v := range expectedResults { - assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) - } -} - -func TestOTLPExposeDefaultPorts(t *testing.T) { - // prepare - builder := NewOTLPReceiverParser(logger, "otlp", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{}, - "http": map[interface{}]interface{}{}, - }, - }) - - expectedResults := map[string]struct { - portNumber int32 - seen bool - }{ - "otlp-grpc": {portNumber: 4317}, - "otlp-http": {portNumber: 4318}, - } - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, len(expectedResults)) - - for _, port := range ports { - r := expectedResults[port.Name] - r.seen = true - expectedResults[port.Name] = r - assert.EqualValues(t, r.portNumber, port.Port) - } - for k, v := range expectedResults { - assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_sapm.go b/internal/manifests/collector/parser/receiver/receiver_sapm.go deleted file mode 100644 index 924b88bff5..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_sapm.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 7276, - parserName: parserNameSAPM, - } -} - -func init() { - Register("sapm", NewSAPMReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_sapm_test.go b/internal/manifests/collector/parser/receiver/receiver_sapm_test.go deleted file mode 100644 index 0940086266..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_sapm_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the SAPM parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_signalfx.go b/internal/manifests/collector/parser/receiver/receiver_signalfx.go deleted file mode 100644 index 549e802453..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_signalfx.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 9943, - parserName: parserNameSignalFx, - } -} - -func init() { - Register("signalfx", NewSignalFxReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_signalfx_test.go b/internal/manifests/collector/parser/receiver/receiver_signalfx_test.go deleted file mode 100644 index eaee10189f..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_signalfx_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the SignalFx parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_skywalking.go b/internal/manifests/collector/parser/receiver/receiver_skywalking.go deleted file mode 100644 index 9b72847ee9..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_skywalking.go +++ /dev/null @@ -1,131 +0,0 @@ -// 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 receiver - -import ( - "fmt" - - "github.com/go-logr/logr" - 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 _ parser.ComponentPortParser = &SkywalkingReceiverParser{} - -const ( - parserNameSkywalking = "__skywalking" - - defaultSkywalkingGRPCPort int32 = 11800 - defaultSkywalkingHTTPPort int32 = 12800 -) - -// SkywalkingReceiverParser parses the configuration for Skywalking receivers. -type SkywalkingReceiverParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewSkywalkingReceiverParser builds a new parser for Skywalking receivers. -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, - name: name, - config: protocols, - } - } - - return &SkywalkingReceiverParser{ - name: name, - config: map[interface{}]interface{}{}, - } -} - -// Ports returns all the service ports for all protocols in this parser. -func (o *SkywalkingReceiverParser) Ports() ([]corev1.ServicePort, error) { - ports := []corev1.ServicePort{} - - for _, protocol := range []struct { - name string - defaultPorts []corev1.ServicePort - }{ - { - name: grpc, - defaultPorts: []corev1.ServicePort{ - { - Name: naming.PortName(fmt.Sprintf("%s-grpc", o.name), defaultSkywalkingGRPCPort), - Port: defaultSkywalkingGRPCPort, - TargetPort: intstr.FromInt(int(defaultSkywalkingGRPCPort)), - AppProtocol: &grpc, - }, - }, - }, - { - name: http, - defaultPorts: []corev1.ServicePort{ - { - Name: naming.PortName(fmt.Sprintf("%s-http", o.name), defaultSkywalkingHTTPPort), - Port: defaultSkywalkingHTTPPort, - TargetPort: intstr.FromInt(int(defaultSkywalkingHTTPPort)), - AppProtocol: &http, - }, - }, - }, - } { - // do we have the protocol specified at all? - if receiverProtocol, ok := o.config[protocol.name]; ok { - // we have the specified protocol, we definitely need a service port - nameWithProtocol := fmt.Sprintf("%s-%s", o.name, protocol.name) - var protocolPort *corev1.ServicePort - - // do we have a configuration block for the protocol? - settings, ok := receiverProtocol.(map[interface{}]interface{}) - if ok { - protocolPort = singlePortFromConfigEndpoint(o.logger, nameWithProtocol, settings) - } - - // have we parsed a port based on the configuration block? - // if not, we use the default port - if protocolPort == nil { - ports = append(ports, protocol.defaultPorts...) - } else { - // infer protocol and appProtocol from protocol.name - if protocol.name == grpc { - protocolPort.Protocol = corev1.ProtocolTCP - protocolPort.AppProtocol = &grpc - } else if protocol.name == http { - protocolPort.Protocol = corev1.ProtocolTCP - protocolPort.AppProtocol = &http - } - ports = append(ports, *protocolPort) - } - } - } - - return ports, nil -} - -// ParserName returns the name of this parser. -func (o *SkywalkingReceiverParser) ParserName() string { - return parserNameSkywalking -} - -func init() { - Register("skywalking", NewSkywalkingReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_skywalking_test.go b/internal/manifests/collector/parser/receiver/receiver_skywalking_test.go deleted file mode 100644 index ab00c852c2..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_skywalking_test.go +++ /dev/null @@ -1,109 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestSkywalkingSelfRegisters(t *testing.T) { - // verify - assert.True(t, IsRegistered("skywalking")) -} - -func TestSkywalkingIsFoundByName(t *testing.T) { - // test - p, err := For(logger, "skywalking", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // verify - assert.Equal(t, "__skywalking", p.ParserName()) -} - -func TestSkywalkingPortsOverridden(t *testing.T) { - // prepare - builder := NewSkywalkingReceiverParser(logger, "skywalking", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1234", - }, - "http": map[interface{}]interface{}{ - "endpoint": "0.0.0.0:1235", - }, - }, - }) - - expectedResults := map[string]struct { - portNumber int32 - seen bool - }{ - "skywalking-grpc": {portNumber: 1234}, - "skywalking-http": {portNumber: 1235}, - } - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, len(expectedResults)) - - for _, port := range ports { - r := expectedResults[port.Name] - r.seen = true - expectedResults[port.Name] = r - assert.EqualValues(t, r.portNumber, port.Port) - } - for k, v := range expectedResults { - assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) - } -} - -func TestSkywalkingExposeDefaultPorts(t *testing.T) { - // prepare - builder := NewSkywalkingReceiverParser(logger, "skywalking", map[interface{}]interface{}{ - "protocols": map[interface{}]interface{}{ - "grpc": map[interface{}]interface{}{}, - "http": map[interface{}]interface{}{}, - }, - }) - - expectedResults := map[string]struct { - portNumber int32 - seen bool - }{ - "skywalking-grpc": {portNumber: 11800}, - "skywalking-http": {portNumber: 12800}, - } - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, len(expectedResults)) - - for _, port := range ports { - r := expectedResults[port.Name] - r.seen = true - expectedResults[port.Name] = r - assert.EqualValues(t, r.portNumber, port.Port) - } - for k, v := range expectedResults { - assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go b/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go deleted file mode 100644 index 676415334b..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_splunk-hec.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 8088, - parserName: parserNameSplunkHec, - } -} - -func init() { - Register("splunk_hec", NewSplunkHecReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_splunk-hec_test.go b/internal/manifests/collector/parser/receiver/receiver_splunk-hec_test.go deleted file mode 100644 index e6f99f7852..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_splunk-hec_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the Splunk Hec parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_statsd.go b/internal/manifests/collector/parser/receiver/receiver_statsd.go deleted file mode 100644 index 0f41520e22..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_statsd.go +++ /dev/null @@ -1,40 +0,0 @@ -// 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 receiver - -import ( - "github.com/go-logr/logr" - corev1 "k8s.io/api/core/v1" - - "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" -) - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 8125, - defaultProtocol: corev1.ProtocolUDP, - parserName: parserNameStatsd, - } -} - -func init() { - Register("statsd", NewStatsdReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_statsd_test.go b/internal/manifests/collector/parser/receiver/receiver_statsd_test.go deleted file mode 100644 index 338971ba44..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_statsd_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the Statsd parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_syslog.go b/internal/manifests/collector/parser/receiver/receiver_syslog.go deleted file mode 100644 index 582cb5c2be..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_syslog.go +++ /dev/null @@ -1,98 +0,0 @@ -// 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 receiver - -import ( - "fmt" - - "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 _ parser.ComponentPortParser = &SyslogReceiverParser{} - -const parserNameSyslog = "__syslog" - -// SyslogReceiverParser parses the configuration for TCP log receivers. -type SyslogReceiverParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewSyslogReceiverParser builds a new parser for TCP log receivers. -func NewSyslogReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { - return &SyslogReceiverParser{ - logger: logger, - name: name, - config: config, - } -} - -func (o *SyslogReceiverParser) Ports() ([]corev1.ServicePort, error) { - var endpoint interface{} - var endpointName string - var protocol corev1.Protocol - var c map[interface{}]interface{} - - // syslog receiver contains the endpoint - // that needs to be exposed one level down inside config - // i.e. either in tcp or udp section with field key - // as `listen_address` - if tcp, isTCP := o.config["tcp"]; isTCP && tcp != nil { - c = tcp.(map[interface{}]interface{}) - endpointName = "tcp" - endpoint = getAddressFromConfig(o.logger, o.name, listenAddressKey, c) - protocol = corev1.ProtocolTCP - } else if udp, isUDP := o.config["udp"]; isUDP && udp != nil { - c = udp.(map[interface{}]interface{}) - endpointName = "udp" - endpoint = getAddressFromConfig(o.logger, o.name, listenAddressKey, c) - protocol = corev1.ProtocolUDP - } - - switch e := endpoint.(type) { - case nil: - break - case string: - port, err := portFromEndpoint(e) - if err != nil { - o.logger.WithValues(listenAddressKey, e).Error(err, fmt.Sprintf("couldn't parse the %s endpoint's port", endpointName)) - return nil, nil - } - - return []corev1.ServicePort{{ - Port: port, - Name: naming.PortName(o.name, port), - Protocol: protocol, - }}, nil - default: - o.logger.WithValues(listenAddressKey, endpoint).Error(fmt.Errorf("unrecognized type %T of %s endpoint", endpoint, endpointName), - "receiver's endpoint isn't a string") - } - - return []corev1.ServicePort{}, nil -} - -func (o *SyslogReceiverParser) ParserName() string { - return parserNameSyslog -} - -func init() { - Register("syslog", NewSyslogReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_syslog_test.go b/internal/manifests/collector/parser/receiver/receiver_syslog_test.go deleted file mode 100644 index fd7ea9daf5..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_syslog_test.go +++ /dev/null @@ -1,64 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" - corev1 "k8s.io/api/core/v1" -) - -func TestSyslogSelfRegisters(t *testing.T) { - // verify - assert.True(t, IsRegistered("syslog")) -} - -func TestSyslogIsFoundByName(t *testing.T) { - // test - p, err := For(logger, "syslog", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // verify - assert.Equal(t, "__syslog", p.ParserName()) -} - -func TestSyslogConfiguration(t *testing.T) { - for _, tt := range []struct { - desc string - config map[interface{}]interface{} - expected []corev1.ServicePort - }{ - {"Empty configuration", map[interface{}]interface{}{}, []corev1.ServicePort{}}, - {"UDP port configuration", - map[interface{}]interface{}{"udp": map[interface{}]interface{}{"listen_address": "0.0.0.0:1234"}}, - []corev1.ServicePort{{Name: "syslog", Port: 1234, Protocol: corev1.ProtocolUDP}}}, - {"TCP port configuration", - map[interface{}]interface{}{"tcp": map[interface{}]interface{}{"listen_address": "0.0.0.0:1234"}}, - []corev1.ServicePort{{Name: "syslog", Port: 1234, Protocol: corev1.ProtocolTCP}}}, - } { - t.Run(tt.desc, func(t *testing.T) { - // prepare - builder := NewSyslogReceiverParser(logger, "syslog", tt.config) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Equal(t, ports, tt.expected) - }) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_tcplog.go b/internal/manifests/collector/parser/receiver/receiver_tcplog.go deleted file mode 100644 index c0232415a9..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_tcplog.go +++ /dev/null @@ -1,79 +0,0 @@ -// 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 receiver - -import ( - "fmt" - - "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 _ parser.ComponentPortParser = &TcpLogReceiverParser{} - -const parserNameTcpLog = "__tcplog" - -// TcpLogReceiverParser parses the configuration for TCP log receivers. -type TcpLogReceiverParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewTcpLogReceiverParser builds a new parser for TCP log receivers. -func NewTcpLogReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { - return &TcpLogReceiverParser{ - logger: logger, - name: name, - config: config, - } -} - -func (o *TcpLogReceiverParser) Ports() ([]corev1.ServicePort, error) { - // tcplog receiver hold the endpoint value in `listen_address` field - var endpoint = getAddressFromConfig(o.logger, o.name, listenAddressKey, o.config) - - switch e := endpoint.(type) { - case nil: - break - case string: - port, err := portFromEndpoint(e) - if err != nil { - o.logger.WithValues(listenAddressKey, e).Error(err, "couldn't parse the endpoint's port") - return nil, nil - } - - return []corev1.ServicePort{{ - Port: port, - Name: naming.PortName(o.name, port), - Protocol: corev1.ProtocolTCP, - }}, nil - default: - o.logger.WithValues(listenAddressKey, endpoint).Error(fmt.Errorf("unrecognized type %T", endpoint), "receiver's endpoint isn't a string") - } - - return []corev1.ServicePort{}, nil -} - -func (o *TcpLogReceiverParser) ParserName() string { - return parserNameTcpLog -} - -func init() { - Register("tcplog", NewTcpLogReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_tcplog_test.go b/internal/manifests/collector/parser/receiver/receiver_tcplog_test.go deleted file mode 100644 index 04b4eb03be..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_tcplog_test.go +++ /dev/null @@ -1,61 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" - corev1 "k8s.io/api/core/v1" -) - -func TestTcpLogSelfRegisters(t *testing.T) { - // verify - assert.True(t, IsRegistered("tcplog")) -} - -func TestTcpLogIsFoundByName(t *testing.T) { - // test - p, err := For(logger, "tcplog", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // verify - assert.Equal(t, "__tcplog", p.ParserName()) -} - -func TestTcpLogConfiguration(t *testing.T) { - for _, tt := range []struct { - desc string - config map[interface{}]interface{} - expected []corev1.ServicePort - }{ - {"Empty configuration", map[interface{}]interface{}{}, []corev1.ServicePort{}}, - {"TCP port configuration", - map[interface{}]interface{}{"listen_address": "0.0.0.0:1234"}, - []corev1.ServicePort{{Name: "tcplog", Port: 1234, Protocol: corev1.ProtocolTCP}}}, - } { - t.Run(tt.desc, func(t *testing.T) { - // prepare - builder := NewTcpLogReceiverParser(logger, "tcplog", tt.config) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Equal(t, ports, tt.expected) - }) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_test.go b/internal/manifests/collector/parser/receiver/receiver_test.go deleted file mode 100644 index 44cb04519d..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_test.go +++ /dev/null @@ -1,164 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/go-logr/logr" - "github.com/stretchr/testify/assert" - 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" -) - -var logger = logf.Log.WithName("unit-tests") - -func TestReceiverPortNames(t *testing.T) { - for _, tt := range []struct { - desc string - candidate string - expected string - port int - }{ - {"regular case", "my-receiver", "my-receiver", 123}, - {"name too long", "long-name-long-name-long-name-long-name-long-name-long-name-long-name-long-name", "port-123", 123}, - {"name with invalid chars", "my-🦄-receiver", "port-123", 123}, - {"name starting with invalid char", "-my-receiver", "port-123", 123}, - } { - t.Run(tt.desc, func(t *testing.T) { - assert.Equal(t, tt.expected, naming.PortName(tt.candidate, int32(tt.port))) - }) - } -} - -func TestReceiverType(t *testing.T) { - for _, tt := range []struct { - desc string - name string - expected string - }{ - {"regular case", "myreceiver", "myreceiver"}, - {"named instance", "myreceiver/custom", "myreceiver"}, - } { - t.Run(tt.desc, func(t *testing.T) { - // test and verify - assert.Equal(t, tt.expected, receiverType(tt.name)) - }) - } -} - -func TestReceiverParsePortFromEndpoint(t *testing.T) { - for _, tt := range []struct { - desc string - endpoint string - expected int - errorExpected bool - }{ - {"regular case", "http://localhost:1234", 1234, false}, - {"absolute with path", "http://localhost:1234/server-status?auto", 1234, false}, - {"no protocol", "0.0.0.0:1234", 1234, false}, - {"just port", ":1234", 1234, false}, - {"no port at all", "http://localhost", 0, true}, - } { - t.Run(tt.desc, func(t *testing.T) { - // test - val, err := portFromEndpoint(tt.endpoint) - if tt.errorExpected { - assert.Error(t, err) - } else { - assert.NoError(t, err) - } - - assert.EqualValues(t, tt.expected, val, "wrong port from endpoint %s: %d", tt.endpoint, val) - }) - } -} - -func TestReceiverFailsWhenPortIsntString(t *testing.T) { - // prepare - config := map[interface{}]interface{}{ - "endpoint": 123, - } - - // test - p := singlePortFromConfigEndpoint(logger, "myreceiver", config) - - // verify - assert.Nil(t, p) -} - -func TestIgnorekubeletstatsEndpoint(t *testing.T) { - // ignore "kubeletstats" receiver endpoint field, this is special case - // as this receiver gets parsed by generic receiver parser - builder := NewGenericReceiverParser(logger, "kubeletstats", map[interface{}]interface{}{ - "endpoint": "0.0.0.0:9000", - }) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Len(t, ports, 0) -} - -func TestReceiverFallbackWhenNotRegistered(t *testing.T) { - // test - p, err := For(logger, "myreceiver", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // test - assert.Equal(t, "__generic", p.ParserName()) -} - -func TestReceiverShouldFindRegisteredParser(t *testing.T) { - // prepare - builderCalled := false - Register("mock", func(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { - builderCalled = true - return &mockParser{} - }) - - // test - _, _ = For(logger, "mock", map[interface{}]interface{}{}) - - // verify - assert.True(t, builderCalled) -} - -type mockParser struct { -} - -func (m *mockParser) Ports() ([]corev1.ServicePort, error) { - return nil, nil -} - -func (m *mockParser) ParserName() string { - return "__mock" -} - -func TestSkipPortsForScrapers(t *testing.T) { - for receiver := range scraperReceivers { - builder := NewGenericReceiverParser(logger, receiver, map[interface{}]interface{}{ - "endpoint": "0.0.0.0:42069", - }) - ports, err := builder.Ports() - assert.NoError(t, err) - assert.Len(t, ports, 0) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_udplog.go b/internal/manifests/collector/parser/receiver/receiver_udplog.go deleted file mode 100644 index 4f55e5b492..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_udplog.go +++ /dev/null @@ -1,79 +0,0 @@ -// 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 receiver - -import ( - "fmt" - - "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 _ parser.ComponentPortParser = &UdpLogReceiverParser{} - -const parserNameUdpLog = "__udplog" - -// UdpLogReceiverParser parses the configuration for UDP log receivers. -type UdpLogReceiverParser struct { - config map[interface{}]interface{} - logger logr.Logger - name string -} - -// NewUdpLogReceiverParser builds a new parser for UDP log receivers. -func NewUdpLogReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { - return &UdpLogReceiverParser{ - logger: logger, - name: name, - config: config, - } -} - -func (o *UdpLogReceiverParser) Ports() ([]corev1.ServicePort, error) { - // udplog receiver hold the endpoint value in `listen_address` field - var endpoint = getAddressFromConfig(o.logger, o.name, listenAddressKey, o.config) - - switch e := endpoint.(type) { - case nil: - break - case string: - port, err := portFromEndpoint(e) - if err != nil { - o.logger.WithValues(listenAddressKey, e).Error(err, "couldn't parse the endpoint's port") - return nil, nil - } - - return []corev1.ServicePort{{ - Port: port, - Name: naming.PortName(o.name, port), - Protocol: corev1.ProtocolUDP, - }}, nil - default: - o.logger.WithValues(listenAddressKey, endpoint).Error(fmt.Errorf("unrecognized type %T", endpoint), "receiver's endpoint isn't a string") - } - - return []corev1.ServicePort{}, nil -} - -func (o *UdpLogReceiverParser) ParserName() string { - return parserNameUdpLog -} - -func init() { - Register("udplog", NewUdpLogReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_udplog_test.go b/internal/manifests/collector/parser/receiver/receiver_udplog_test.go deleted file mode 100644 index 1b12191ed5..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_udplog_test.go +++ /dev/null @@ -1,61 +0,0 @@ -// 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 receiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" - corev1 "k8s.io/api/core/v1" -) - -func TestUdpLogSelfRegisters(t *testing.T) { - // verify - assert.True(t, IsRegistered("udplog")) -} - -func TestUdpLogIsFoundByName(t *testing.T) { - // test - p, err := For(logger, "udplog", map[interface{}]interface{}{}) - assert.NoError(t, err) - - // verify - assert.Equal(t, "__udplog", p.ParserName()) -} - -func TestUdpLogConfiguration(t *testing.T) { - for _, tt := range []struct { - desc string - config map[interface{}]interface{} - expected []corev1.ServicePort - }{ - {"Empty configuration", map[interface{}]interface{}{}, []corev1.ServicePort{}}, - {"UDP port configuration", - map[interface{}]interface{}{"listen_address": "0.0.0.0:1234"}, - []corev1.ServicePort{{Name: "udplog", Port: 1234, Protocol: corev1.ProtocolUDP}}}, - } { - t.Run(tt.desc, func(t *testing.T) { - // prepare - builder := NewUdpLogReceiverParser(logger, "udplog", tt.config) - - // test - ports, err := builder.Ports() - - // verify - assert.NoError(t, err) - assert.Equal(t, ports, tt.expected) - }) - } -} diff --git a/internal/manifests/collector/parser/receiver/receiver_wavefront.go b/internal/manifests/collector/parser/receiver/receiver_wavefront.go deleted file mode 100644 index f2eafb8556..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_wavefront.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 2003, - parserName: parserNameWavefront, - } -} - -func init() { - Register("wavefront", NewWavefrontReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_wavefront_test.go b/internal/manifests/collector/parser/receiver/receiver_wavefront_test.go deleted file mode 100644 index 0dd31b9470..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_wavefront_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the Wavefront parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go b/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go deleted file mode 100644 index 8f8d9fe210..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe.go +++ /dev/null @@ -1,38 +0,0 @@ -// 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 receiver - -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{}) parser.ComponentPortParser { - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 9410, - parserName: parserNameZipkinScribe, - } -} - -func init() { - Register("zipkin-scribe", NewZipkinScribeReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe_test.go b/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe_test.go deleted file mode 100644 index 6475eb02fc..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin-scribe_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the ZipkinScribe parser are currently part of the test TestDownstreamParsers diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin.go b/internal/manifests/collector/parser/receiver/receiver_zipkin.go deleted file mode 100644 index debbf8e9a4..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin.go +++ /dev/null @@ -1,42 +0,0 @@ -// 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 receiver - -import ( - "github.com/go-logr/logr" - corev1 "k8s.io/api/core/v1" - - "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/parser" -) - -const parserNameZipkin = "__zipkin" - -// NewZipkinReceiverParser builds a new parser for Zipkin receivers. -func NewZipkinReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) parser.ComponentPortParser { - http := "http" - return &GenericReceiver{ - logger: logger, - name: name, - config: config, - defaultPort: 9411, - defaultProtocol: corev1.ProtocolTCP, - defaultAppProtocol: &http, - parserName: parserNameZipkin, - } -} - -func init() { - Register("zipkin", NewZipkinReceiverParser) -} diff --git a/internal/manifests/collector/parser/receiver/receiver_zipkin_test.go b/internal/manifests/collector/parser/receiver/receiver_zipkin_test.go deleted file mode 100644 index 8f1af43c5e..0000000000 --- a/internal/manifests/collector/parser/receiver/receiver_zipkin_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// 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 receiver - -// all tests for the Zipkin parser are currently part of the test TestDownstreamParsers