Answers: <blockquote>
  <p>Is there no way to create a default config for all jobs?</p>
  </blockquote>
  <p>No, there is no such way. <code>relabel_configs</code> are specified on the job level.</p>
  <p>On the other hand, if all 20 of your jobs have exactly the same relabeling config, you might consider using a single job and additional labels for distinction (I assume you distinct right now by <code>job</code> label):</p>
  <pre class="lang-yml prettyprint-override"><code>  - job_name: unitedjod
      scheme: 'https'
      metrics_path: '/metrics'
      static_configs:
        - targets:
          - one.example
          - two.example
          labels:
            target_type: alpha
        - targets:
          - three.example
          - four.example
          labels:
            target_type: beta
      relabel_configs:
        - source_labels: [__address__]
          regex: '(.*).example.*'
          replacement: '${1}'
          target_label: 'slug'
  </code></pre>
  <p>Here first group of targets will contain label <code>target_type</code> with value <code>alpha</code>, and second group - with value <code>beta</code>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-10-04T17:07:42.690Z
Answers: 2023-10-04T17:07:42.690Z
Answers: markalex
Answers: <p>Yaml (and Prometheus) supports &quot;references&quot; (<code>&amp;</code> as anchor and <code>*</code> as reference):</p>
  <pre><code>  - job_name: alpha
      relabel_configs: &amp;relabel_configs
        - ...
  
    - job_name: beta
      relabel_configs: *relabel_configs
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-08-05T14:52:55.617Z
Answers: 2024-08-05T14:52:55.617Z
Answers: resnyanskiy
Body: <p>In my prometheus.yml I have several jobs defined like:</p>
  <pre><code>  - job_name: alpha
      scheme: 'https'
      metrics_path: '/metrics'
      static_configs:
        - targets:
          - one.example
          - two.example
      relabel_configs:
        - source_labels: [__address__]
          regex: '(.*).example.*'
          replacement: '${1}'
          target_label: 'slug'
  
    - job_name: beta
      scheme: 'https'
      metrics_path: '/metrics'
      static_configs:
        - targets:
          - three.example
          - four.example
      relabel_configs:
        - source_labels: [__address__]
          regex: '(.*).example.*'
          replacement: '${1}'
          target_label: 'slug'
  </code></pre>
  <p>as you can see, only the targets differ per job, all the other configs like <code>relabel_configs</code> and <code>scheme</code> etc. are the same. Because its not only two jobs but around 20 for now, I don't want to repeat the same settings for each job. Is there no way to create a default config for all jobs?</p>
  
Tags: <prometheus>
Title: Add prometheus config for all jobs
UserDisplayName: Vietna
ThreadText: # Add prometheus config for all jobs
  
  (Asked by: username_0 on 2023-10-02)
  
  In my prometheus.yml I have several jobs defined like:
  
  ```
    - job_name: alpha
      scheme: 'https'
      metrics_path: '/metrics'
      static_configs:
        - targets:
          - one.example
          - two.example
      relabel_configs:
        - source_labels: [__address__]
          regex: '(.*).example.*'
          replacement: '${1}'
          target_label: 'slug'
  
    - job_name: beta
      scheme: 'https'
      metrics_path: '/metrics'
      static_configs:
        - targets:
          - three.example
          - four.example
      relabel_configs:
        - source_labels: [__address__]
          regex: '(.*).example.*'
          replacement: '${1}'
          target_label: 'slug'
  
  ```
  
  as you can see, only the targets differ per job, all the other configs like `relabel_configs` and `scheme` etc. are the same. Because its not only two jobs but around 20 for now, I don't want to repeat the same settings for each job. Is there no way to create a default config for all jobs?
  
  **Tags:** prometheus
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-10-04. Score: 1 | Accepted answer
  
  > Is there no way to create a default config for all jobs?
  
  No, there is no such way. `relabel_configs` are specified on the job level.
  
  On the other hand, if all 20 of your jobs have exactly the same relabeling config, you might consider using a single job and additional labels for distinction (I assume you distinct right now by `job` label):
  
  ```yml
    - job_name: unitedjod
      scheme: 'https'
      metrics_path: '/metrics'
      static_configs:
        - targets:
          - one.example
          - two.example
          labels:
            target_type: alpha
        - targets:
          - three.example
          - four.example
          labels:
            target_type: beta
      relabel_configs:
        - source_labels: [__address__]
          regex: '(.*).example.*'
          replacement: '${1}'
          target_label: 'slug'
  
  ```
  
  Here first group of targets will contain label `target_type` with value `alpha`, and second group - with value `beta`.
  
  
  ---
  
  ### Answer by username_2 on 2024-08-05. Score: 0
  
  Yaml (and Prometheus) supports "references" (`&` as anchor and `*` as reference):
  
  ```
    - job_name: alpha
      relabel_configs: &relabel_configs
        - ...
  
    - job_name: beta
      relabel_configs: *relabel_configs
  
  ```
  
  
  ---
  
  