From 0f2fea60e36e9951a3caf4884a8264473a8204c5 Mon Sep 17 00:00:00 2001 From: Christos Markou Date: Thu, 26 Sep 2024 22:41:55 +0300 Subject: [PATCH] [receivercreator] Validate endpoint's configuration before starting receivers (#35416) **Description:** The `receivercreator` should validate the runtime configurations before starting a receiver. This PR adds this validation. **Link to tracking Issue:** Fixes https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33145 **Testing:** Using the following helm chart's values: ```yaml mode: daemonset config: extensions: k8s_observer: auth_type: serviceAccount node: ${env:K8S_NODE_NAME} observe_nodes: true exporters: debug: verbosity: basic receivers: receiver_creator/3: watch_observers: [ k8s_observer ] receivers: apache: rule: type == "k8s.node" config: endpoint: "http://localhost:8080/server-status?manual" service: extensions: [health_check, k8s_observer] pipelines: metrics: receivers: [receiver_creator/3] processors: [batch] exporters: [debug] ``` Expect to see an error after the config's validation: ```console 2024-09-25T10:46:56.778Z error receivercreator@v0.110.0/observerhandler.go:159 failed to start receiver {"kind": "receiver", "name": "receiver_creator/3", "data_type": "metrics", "receiver": "apache", "error": "invalid runtime receiver config: receivers::apache: query must be 'auto': 'http://localhost:8080/server-status?manual'"} github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator.(*observerHandler).OnAdd github.com/open-telemetry/opentelemetry-collector-contrib/receiver/receivercreator@v0.110.0/observerhandler.go:159 github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer.(*EndpointsWatcher).updateAndNotifyOfEndpoints github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer@v0.110.0/endpointswatcher.go:111 ``` This stops the execution of the receiver which would lead to fetch errors (as described in the respective issue https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33145): ```console 2024-05-21T09:17:46.749Z error apachereceiver@v0.100.0/scraper.go:67 failed to fetch Apache Httpd stats {"kind": "receiver", "name": "receiver_creator/3", "data_type": "metrics", "name": "apache//receiver_creator/3{endpoint=\"http://localhost:8080/server-status?manual\"}/k8s_observer/kind-control-plane-b75cdcf9-ee9d-4cb8-aa53-1ceb030d898d", "error": "Get \"http://localhost:8080/server-status?manual\": dial tcp [::1]:8080: connect: connection refused"} github.com/open-telemetry/opentelemetry-collector-contrib/receiver/apachereceiver.(*apacheScraper).scrape github.com/open-telemetry/opentelemetry-collector-contrib/receiver/apachereceiver@v0.100.0/scraper.go:67 go.opentelemetry.io/collector/receiver/scraperhelper.ScrapeFunc.Scrape go.opentelemetry.io/collector/receiver@v0.100.1-0.20240509190532-c555005fcc80/scraperhelper/scraper.go:20 go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).scrapeMetricsAndReport go.opentelemetry.io/collector/receiver@v0.100.1-0.20240509190532-c555005fcc80/scraperhelper/scrapercontroller.go:194 go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).startScraping.func1 go.opentelemetry.io/collector/receiver@v0.100.1-0.20240509190532-c555005fcc80/scraperhelper/scrapercontroller.go:169 2024-05-21T09:17:46.750Z error scraperhelper/scrapercontroller.go:197 Error scraping metrics {"kind": "receiver", "name": "receiver_creator/3", "data_type": "metrics", "name": "apache//receiver_creator/3{endpoint=\"http://localhost:8080/server-status?manual\"}/k8s_observer/kind-control-plane-b75cdcf9-ee9d-4cb8-aa53-1ceb030d898d", "error": "Get \"http://localhost:8080/server-status?manual\": dial tcp [::1]:8080: connect: connection refused", "scraper": "apache"} ``` **Documentation:** Signed-off-by: ChrsMark --- ...add_receivercreator_config_validation.yaml | 27 +++++++++++++++++++ receiver/receivercreator/runner.go | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 .chloggen/add_receivercreator_config_validation.yaml diff --git a/.chloggen/add_receivercreator_config_validation.yaml b/.chloggen/add_receivercreator_config_validation.yaml new file mode 100644 index 000000000000..12b82dd5a400 --- /dev/null +++ b/.chloggen/add_receivercreator_config_validation.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: receivercreator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Validate endpoint's configuration before starting receivers + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [33145] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/receivercreator/runner.go b/receiver/receivercreator/runner.go index 08542a5365c8..a0995a18af31 100644 --- a/receiver/receivercreator/runner.go +++ b/receiver/receivercreator/runner.go @@ -137,6 +137,9 @@ func (run *receiverRunner) loadRuntimeReceiverConfig( if err := mergedConfig.Unmarshal(receiverCfg); err != nil { return nil, "", fmt.Errorf("failed to load %q template config: %w", receiver.id.String(), err) } + if err := component.ValidateConfig(receiverCfg); err != nil { + return nil, "", fmt.Errorf("invalid runtime receiver config: receivers::%s: %w", receiver.id, err) + } return receiverCfg, targetEndpoint, nil }