open-telemetry / opentelemetry-operator

Kubernetes Operator for OpenTelemetry Collector
Apache License 2.0
1.17k stars 417 forks source link

[target allocator] missing http_sd_configs in the collector configuration #2265

Open olehrgf opened 10 months ago

olehrgf commented 10 months ago

Component(s)

operator

What happened?

Description

When the EnableTargetAllocatorRewrite feature flag is enabled, the target allocator used collector's config map has a missing http_sd_configs configuration.

Steps to Reproduce

Otel collector configuration:

apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
  name: otel-collector
spec:
  mode: statefulset
  targetAllocator:
    enabled: true
    prometheusCR:
      enabled: true
  config: |
    receivers:
      prometheus:
        config:
          scrape_configs:
            - job_name: "otel-collector"

    exporters:
      debug:
        verbosity: detailed
        sampling_initial: 5
        sampling_thereafter: 200

    service:
      pipelines:
        metrics:
          exporters:
            - debug
          receivers:
            - prometheus

Operator installed with +operator.collector.rewritetargetallocator feature gate.

Expected Result

apiVersion: v1
kind: ConfigMap
metadata:
  name: otel-collector-collector
  namespace: monitoring
data:
  collector.yaml: |
    exporters:
      debug:
        sampling_initial: 5
        sampling_thereafter: 200
        verbosity: detailed
    receivers:
      prometheus:
        config:
          scrape_configs:
            - http_sd_configs:
                - url: http://otel-collector-targetallocator:80/jobs/otel-collector/targets?collector_id=$POD_NAME
              job_name: otel-collector
              scrape_interval: 15s
        target_allocator:
          collector_id: ${POD_NAME}
          endpoint: http://prometheus-scraper-otel-collector-targetallocator
          interval: 30s
    service:
      extensions:
        - health_check
        - memory_ballast
      pipelines:
        metrics:
          exporters:
            - debug
          receivers:
            - prometheus

Actual Result

apiVersion: v1
kind: ConfigMap
metadata:
  name: otel-collector-collector
  namespace: monitoring
data:
  collector.yaml: |
    exporters:
      debug:
        sampling_initial: 5
        sampling_thereafter: 200
        verbosity: detailed
    receivers:
      prometheus:
        target_allocator:
          collector_id: ${POD_NAME}
          endpoint: http://prometheus-scraper-otel-collector-targetallocator
          interval: 30s
    service:
      pipelines:
        metrics:
          exporters:
            - debug
          receivers:
            - prometheus

Kubernetes Version

1.23.0

Operator version

v0.79.0

Collector version

v0.79.0

Environment information

No response

Log output

No response

Additional context

scrape_configs removed during target allocator rewrite internal/manifests/targetallocator/adapters/config_to_prom_config.go

and then is not added internal/manifests/targetallocator/adapters/config_to_prom_config.go

jaronoff97 commented 10 months ago

Are there any logs from the operator? I'm not positive why you would want a scrape config with no *_config? I'm not positive prometheus would accept that.

olehrgf commented 10 months ago

@jaronoff97 There is nothing special in the logs.

I'm not positive why you would want a scrape config with no *_config?

I'm expecting http_sd_configs to be added automatically by the operator when the feature flag is enabled and the target allocator section is presented in the configuration as it is described in the docs.

cmergenthaler commented 10 months ago

I might be wrong here but from my understading the http_sd_configs is not necessary on the collector since it natively support target-allocator as describe in the upstream docs. What docs are you referring to?