Community Patterns

Community Library Entry

0

Regular Expression
Created·2023-04-26 23:44
Updated·2023-04-26 23:48
Flavor·PCRE2 (PHP)

/
^([^:;\n]*)(:\d+)?;([^;\n]*)(;.*\b\3\b=|;.*;|;)(\d+)(,.*|;)?$
/
gm
Open regex in editor

Description

 relabel_configs: 
  # allow override of default port, by matching with or without default ports, both of the following annotations are supported:
  #   prometheus.io/port: 9090
  #   metrics.agent.grafana.com/port: 9090
  #   or
  #   prometheus.io/port: http-port=9090,http-metrics=9000
  #   metrics.agent.grafana.com/port: http-port=9090,http-metrics=9000
  - action: replace
    regex: ^([^:;\n]*)(:\d+)?;([^;\n]*)(;.*\b\3\b=|;.*;|;)(\d+)(,.*|;)?$
    replacement: $1:$5
    source_labels:
      - __address__
      - __meta_kubernetes_service_port_name
      - __meta_kubernetes_service_annotation_prometheus_io_port
      - __meta_kubernetes_service_annotation_metrics_agent_grafana_com_port
Submitted by AaronB