canonical / prometheus-scrape-config-k8s-operator

This charmed operator allows operators to fine-tune scrape job configurations before sending them to the Prometheus charmed operator.
https://charmhub.io/prometheus-scrape-config-k8s
Apache License 2.0
1 stars 1 forks source link

Error while using YAML string formatted scrape target relabeling configuration. #32

Open Abuelodelanada opened 10 months ago

Abuelodelanada commented 10 months ago

Bug Description

Most of our config options, for instance relabel_configs, are required to be YAML formatted:

  relabel_configs:
    description: YAML string formatted scrape target relabeling configuration.
    type: string

But if you use YAML it fails.

To Reproduce

  1. Deploy this bundle:
    bundle: kubernetes
    applications:
    prometheus:
    charm: prometheus-k8s
    channel: edge
    series: focal
    resources:
      prometheus-image: 128
    scale: 1
    constraints: arch=amd64
    storage:
      database: kubernetes,1,1024M
    trust: true
    scrape-config:
    charm: prometheus-scrape-config-k8s
    channel: edge
    series: focal
    scale: 1
    options:
      scrape_interval: 12s
      scrape_timeout: 9s
    constraints: arch=amd64
    zinc:
    charm: zinc-k8s
    channel: edge
    resources:
      zinc-image: 120
    scale: 1
    constraints: arch=amd64
    storage:
      data: kubernetes,1,1024M
    relations:
    - - prometheus:metrics-endpoint
    - scrape-config:metrics-endpoint
    - - zinc:metrics-endpoint
    - scrape-config:configurable-scrape-jobs
  2. Create a relabel config like this one.: a. Create a variable with the YAML

      $ relabel="source_labels: [__address__]                                 
      separator: ':'
      regex: '(.*):(.*)'
      replacement: '${1}'
      target_label: instance"

    b. Add this config:

       juju config scrape-config relabel_configs=$relabel
  3. Check error while validating scrape jobs:
    unit-prometheus-0: 16:45:46.874 ERROR unit.prometheus/0.juju-log metrics-endpoint:2: Validating scrape jobs failed: b'time="2023-10-04T19:45:46Z" level=fatal msg="parsing YAML file /tmp/tmpas8qx_44: yaml: unmarshal errors:\\n  line 4: cannot unmarshal !!str `source_...` into []*relabel.Config"\n'

Environment

Model  Controller  Cloud/Region        Version  SLA          Timestamp
cos    microk8s    microk8s/localhost  3.1.5    unsupported  16:46:49-03:00

App            Version  Status  Scale  Charm                         Channel  Rev  Address         Exposed  Message
prometheus     2.46.0   active      1  prometheus-k8s                edge     150  10.152.183.115  no       
scrape-config  n/a      active      1  prometheus-scrape-config-k8s  edge      42  10.152.183.200  no       
zinc           ...      active      1  zinc-k8s                      edge     125  10.152.183.151  no       

Unit              Workload  Agent  Address      Ports  Message
prometheus/0*     active    idle   10.1.38.104         
scrape-config/0*  active    idle   10.1.38.89          
zinc/0*           active    idle   10.1.38.99          

Relation provider               Requirer                                Interface          Type     Message
prometheus:prometheus-peers     prometheus:prometheus-peers             prometheus_peers   peer     
scrape-config:metrics-endpoint  prometheus:metrics-endpoint             prometheus_scrape  regular  
zinc:metrics-endpoint           scrape-config:configurable-scrape-jobs  prometheus_scrape  regular  
zinc:zinc-peers                 zinc:zinc-peers                         zinc_peers         peer   

Relevant log output

unit-prometheus-0: 16:45:46.874 ERROR unit.prometheus/0.juju-log metrics-endpoint:2: Validating scrape jobs failed: b'time="2023-10-04T19:45:46Z" level=fatal msg="parsing YAML file /tmp/tmpas8qx_44: yaml: unmarshal errors:\\n  line 4: cannot unmarshal !!str `source_...` into []*relabel.Config"\n'

Additional context

No response

sed-i commented 10 months ago

This is possibly because the $relabel is not quoted and whitespace breaks up. Can you confirm with juju config that the config value matches the expected?