From 09ad83709c7e06d8e64a6dc77fc93a8410ea98e2 Mon Sep 17 00:00:00 2001 From: Jacob Aronoff Date: Fri, 30 Aug 2024 15:45:27 -0400 Subject: [PATCH] Delete more --- .../collector/adapters/config_to_ports.go | 27 ----- .../collector/adapters/config_validate.go | 110 ------------------ .../adapters/config_validate_test.go | 103 ---------------- 3 files changed, 240 deletions(-) delete mode 100644 internal/manifests/collector/adapters/config_to_ports.go delete mode 100644 internal/manifests/collector/adapters/config_validate.go delete mode 100644 internal/manifests/collector/adapters/config_validate_test.go 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_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) -}