Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to use anchors in YAML config file #1884

Closed
atombender opened this Issue Aug 10, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@atombender
Copy link
Contributor

atombender commented Aug 10, 2016

It's desirable to reuse configuration to avoid duplication (which can lead to drift or copy/paste mistakes). For example, this ought to be possible:

_:
  k8s_tls_config: &k8s_tls_config
    # This TLS & bearer token file config is used to connect to the actual scrape
    # endpoints for cluster components. This is separate to discovery auth
    # configuration (`in_cluster` below) because discovery & scraping are two
    # separate concerns in Prometheus.
    ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
    # FIXME: Kubelet runs with a self-signed cert, so we have to skip verification
    insecure_skip_verify: true

# ...

scrape_configs:
- job_name: 'kubernetes-cluster'
  tls_config: *k8s_tls_config

However, this will cause Prometheus to reject the config file:

time="2016-08-10T17:57:14Z" level=error msg="Couldn't load configuration (-config.file=/var/prometheus/prometheus.yml): unknown fields in config: _" source="main.go:218" 

I don't see any non-schema-validated key where I can attach dummy anchors. In the absence of this, I propose that it ignore keys starting with _, for example.

(Is there a hacky workaround I use in the meantime, however?)

@fabxc

This comment has been minimized.

Copy link
Member

fabxc commented Aug 10, 2016

I never used it myself but could writing it out in the first occurence work and then referencing it in subsequent ones?

Personally, I'd strongly recommend letting configuration management handle that though.

@fabxc fabxc added the kind/question label Aug 10, 2016

@atombender

This comment has been minimized.

Copy link
Contributor Author

atombender commented Aug 10, 2016

Maybe I can define the name in the first job and then refer to the anchor in subsequent jobs (is that what you meant?). Didn't occur to me because I — probably wrongly! — assumed anchors were scoped by nesting level.

I'm using Kubernetes configmaps, which don't have any templating support, and it's nice to be able to write YAML without templating, given that it actually has this kind of macro support.

@atombender

This comment has been minimized.

Copy link
Contributor Author

atombender commented Aug 10, 2016

So that seemed to work:

  - job_name: 'kubernetes-cluster'
    tls_config: &k8s_tls_config
      ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      insecure_skip_verify: true

  - job_name: 'kubernetes-apiserver'
    tls_config: *k8s_tls_config

That doesn't let me use the << syntax anywhere, so I can't do this:

_:
  kubernetes_target: &kubernetes_target
    bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    tls_config:
      ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      insecure_skip_verify: true

# ...

scrape_configs:
- <<: *kubernetes_target
  job_name: 'kubernetes-cluster'

As you probably know, << merges the anchor into the parent key.

@benkeil

This comment has been minimized.

Copy link

benkeil commented Jun 27, 2018

Was there any result?

@shane-axiom

This comment has been minimized.

Copy link

shane-axiom commented Oct 18, 2018

@benkeil It appears there was no resolution, but you may comment on this related thread: #2347

@lock lock bot locked and limited conversation to collaborators Apr 16, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.