VictoriaMetrics / helm-charts

Helm charts for VictoriaMetrics, VictoriaLogs and ecosystem
https://victoriametrics.github.io/helm-charts/
Apache License 2.0
340 stars 331 forks source link

extraScrapeConfigs hard to set #251

Closed sjtindell closed 2 months ago

sjtindell commented 3 years ago

Using the victoria-metrics-single helm chart

https://github.com/VictoriaMetrics/helm-charts/tree/master/charts/victoria-metrics-single

I am trying to set extraScrapeConfigs.

I would like to be able to use a values file vmetrics-single-values.yaml like

server:

  scrape:
    enabled: true

    extraScrapeConfigs: |
      - job_name: 'node-exporter'
      kubernetes_sd_configs:
        - role: endpoints
      relabel_configs:
      - source_labels: [__meta_kubernetes_endpoints_name]
        regex: 'node-exporter-prometheus-node-exporter'
        action: keep

and

helm template vmsingle -f vmetrics-single-values.yaml vm/victoria-metrics-single

or set this on the command line with a file like extraScrapeConfigs.yaml contents

- job_name: 'node-exporter'
  kubernetes_sd_configs:
    - role: endpoints
  relabel_configs:
  - source_labels: [__meta_kubernetes_endpoints_name]
    regex: 'node-exporter-prometheus-node-exporter'
    action: keep

and

helm upgrade --install vmsingle vm/victoria-metrics-single  \
    --set server.scrape.enabled=true \
    --set-file server.scrape.extraScrapeConfigs=extraScrapeConfigs.yaml

But the way the code is written and was just merged at

https://github.com/VictoriaMetrics/helm-charts/commit/1badd2ac5c0f8d68bf7efe56f4a1be8818b22651

this expects a list and throws an error

Error: template: victoria-metrics-single/templates/scrape-configmap.yaml:12:16: executing "victoria-metrics-single/templates/scrape-configmap.yaml" at <concat $v $.Values.server.scrape.extraScrapeConfigs>: error calling concat: Cannot concat type string as list

ISSUE: I am not sure how to pass a list to this value. I need to pass a list of multiline strings via the helm values file or --set-file.

In the prometheus chart they appear to do so as follows

https://github.com/prometheus-community/helm-charts/blob/b610168cb735070dc75cb5d4d27b65f1ddfcec24/charts/prometheus/templates/server/cm.yaml#L42

# adds additional scrape configs to prometheus.yml
# must be a string so you have to add a | after extraScrapeConfigs:
# example adds prometheus-blackbox-exporter scrape config
extraScrapeConfigs:
  # - job_name: 'prometheus-blackbox-exporter'
  #   metrics_path: /probe
  #   params:
  #     module: [http_2xx]
  #   static_configs:
  #     - targets:
  #       - https://example.com
  #   relabel_configs:
  #     - source_labels: [__address__]
  #       target_label: __param_target
  #     - source_labels: [__param_target]
  #       target_label: instance
  #     - target_label: __address__
  #       replacement: prometheus-blackbox-exporter:9115

using the Helm tpl function

https://helm.sh/docs/howto/charts_tips_and_tricks/

like so

https://github.com/prometheus-community/helm-charts/blob/b610168cb735070dc75cb5d4d27b65f1ddfcec24/charts/prometheus/templates/server/cm.yaml#L42

{{ tpl $root.Values.extraScrapeConfigs $root | indent 4 }}
sjtindell commented 3 years ago

Banged my head on this and then realized if it is doing a concat of two lists before converting to yaml I can just add a straight yaml list. No need to pass in an array of multiline strings in the values file. My mistake.

values.yaml

server:

  scrape:
    enabled: true

    extraScrapeConfigs:
      - job_name: 'node-exporter'
        kubernetes_sd_configs:
          - role: endpoints
        relabel_configs:
        - source_labels: [__meta_kubernetes_endpoints_name]
          regex: 'node-exporter-prometheus-node-exporter'
          action: keep

and

helm template vmsingle -f vmetrics-single-values.yaml vm/victoria-metrics-single

works as expected.

sjtindell commented 3 years ago

Can we use --set-file with this implementation?

Haleygo commented 1 year ago

Can we use --set-file with this implementation?

Hello! I think using -promscrape.config to file mounted by configmap should work, no? https://github.com/VictoriaMetrics/VictoriaMetrics/blob/70773f53d75fc7f0589f464381c37826ed1b0912/README.md?plain=1#L2407

AndrewChubatiuk commented 2 months ago

Closing this issue, as it's answered here