Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

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

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 - 2 years ago (Last modified 2 years ago)