Prometheus write_relabel_configs with both keep and replace action not working

Hi, I am trying to send metrics from Prometheus to Grafana cloud with below config.

remote_write:
- url: https://prometheus-us-central1.grafana.net/api/prom/push
  write_relabel_configs:
  - source_labels: [__name__]
    separator: ;
    regex: (container_.*|jvm_.*)
    replacement: $1
    action: keep
  - source_labels: [__name__]
    separator: ;
    regex: workload:(.*)
    target_label: __name__
    replacement: $1
    action: replace

I see metrics only from keep but not from replace relabel config in Grafana cloud.
The requirement is to send some metrics without any changes and other metrics with renaming. For example, workload:istio_requests_total to istio_requests_total

1 Like

Below config worked. First select metric using keep and then rename using replace.

remote_write:
- url: https://prometheus-us-central1.grafana.net/api/prom/push
  write_relabel_configs:
  - source_labels: [__name__]
    separator: ;
    regex: (jvm_.*|workload:.*)
    replacement: $1
    action: keep
  - source_labels: [__name__]
    separator: ;
    regex: workload:(.*)
    target_label: __name__
    replacement: $1
    action: replace