open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.73k stars 2.16k forks source link

receivercreator does not honor target's config validation #33145

Open ChrsMark opened 1 month ago

ChrsMark commented 1 month ago

Component(s)

receiver/receivercreator

Describe the issue you're reporting

At the moment the receivercreator can produce receivers' configurations that would normally fail to get validated.

For example for the following configuration:

receivers:
  apache:
    endpoint: "http://localhost:8080/server-status?manual"

when running the collector I get:

Error: invalid configuration: receivers::apache: query must be 'auto': 'http://localhost:8080/server-status?manual'
2024/05/21 12:21:23 collector server run finished with error: invalid configuration: receivers::apache: query must be 'auto': 'http://localhost:8080/server-status?manual'

However, when the same config is managed by the receivercreator:

receivers:
  receiver_creator/3:
    watch_observers: [ k8s_observer ]
    receivers:
      apache:
        rule: type == "k8s.node"
        config:
          endpoint: "http://localhost:8080/server-status?manual"

no validation errors occur and the apache receiver will start giving constantly scraping errrors:

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"}

I think a better experience here would be to validate each populated configuration, log an error once and do not start the receiver, instead of starting the receiver with an invalid configuration. The latter will flood the logs with errors when it can be avoided.

github-actions[bot] commented 1 month ago

Pinging code owners: