title: How to relabel scraping jobs on Prometheus-operator?
body: <p>I'm trying the prometheus-operator for the first time, and still struggling with the differences for managing Prometheus through that.</p>
  
  <p>The deployment is pretty straight-forward, and so is editing the rules, however I could not find my way when trying to relabel the exporters using <code>static_configs</code> when using Prometheus-operator.</p>
  
  <p>What I used to do in the past was to customize <code>prometheus.yml</code> and add <code>static_configs</code> to include the labels for each one of the exporter's job names.</p>
  
  <p>I understand that under Prometheus-operator's hood we have the same settings as we usually have,  but I'm not sure how to achieve the same results from the <code>static_config</code> configuration using the operator. </p>
  
  <p>From what I could understand I have to do set the relabelings now on the service monitors related to my exporters, however all the configurations I've tried had no results:</p>
  
  <p>tried with <code>metricRelabelings</code> as descirbed on issue <a href="https://github.com/coreos/prometheus-operator/issues/1166" rel="noreferrer">1166</a>, and <code>StaticConfigs</code> as described on <a href="https://github.com/coreos/prometheus-operator/issues/1086" rel="noreferrer">issue 1086</a> without any luck.</p>
  
  <p>For example this is what I used to do for <code>kubernetes-cadvisor</code> exporter to set a label on <code>static_config</code>, so that my custom label was displayed on all the metrics collected by my exporters on ingestion time:</p>
  
  <pre><code>scrape_configs:
  - job_name: prometheus
  static_configs:
  - targets: ['localhost:9090']
  labels:
  kubernetes_namespace: kube-system
  cluster_name: mycluster01
  </code></pre>
  
  <p>And also add the <code>relabel_configs</code> on each of my exporters job's:</p>
  
  <pre><code>
  - job_name: 'kubernetes-cadvisor'
  scheme: https
  tls_config:
    ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  kubernetes_sd_configs:
  - role: node
  relabel_configs:
    - target_label: cluster_name
      replacement: mycluster01
    - target_label: kubernetes_namespace
      replacement: kube-system
    - action: labelmap
      regex: __meta_kubernetes_node_label_(.+)
    - target_label: __address__
      replacement: kubernetes.default.svc:443
    - source_labels: [__meta_kubernetes_node_name]
      regex: (.+)
      target_label: __metrics_path__
      replacement: /api/v1/nodes/${1}:10250/proxy/metrics
  </code></pre>
  
  <p>And this is an example for achieving the same using <code>metricRelabelings</code>, on Prometheus-operator which is still not working for me:</p>
  
  <pre><code>apiVersion: monitoring.coreos.com/v1
  kind: ServiceMonitor
  metadata:
    labels:
      k8s-app: node-exporter
    name: node-exporter
    namespace: monitoring
  spec:
    endpoints:
    - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
      interval: 30s
      port: https
      scheme: https
      tlsConfig:
        insecureSkipVerify: true
    jobLabel: k8s-app
    selector:
      matchLabels:
        k8s-app: node-exporter
    metricRelabelings:
      sourceLabels: __meta_kubernetes_node_name
      targetLabel: node
  </code></pre>
  
  <p>What I expect to achieve is to create a static label on my exporters so all the metrics carry the custom label that I define at the scraping time instead of having to manually define custom labels to all the deployments in my cluster.</p>
  
  <p>Thanks in advance for any help!</p>