From 38fbc129254ba45233f0aa411e3f20a75ee22e8f Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Wed, 27 Jan 2021 16:13:44 +0800 Subject: [PATCH] Tidbmonitor add `tidb_cluster `target label . (#3750) (#3753) * cherry pick #3750 to release-1.1 Signed-off-by: ti-srebot * fix conflict Co-authored-by: Mike <842725815@qq.com> Co-authored-by: BinChen Co-authored-by: Ti Chi Robot <71242396+ti-chi-bot@users.noreply.github.com> --- pkg/monitor/monitor/template.go | 8 ++++ pkg/monitor/monitor/template_test.go | 60 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/pkg/monitor/monitor/template.go b/pkg/monitor/monitor/template.go index e180a75a92b..cf7c0bc17cf 100644 --- a/pkg/monitor/monitor/template.go +++ b/pkg/monitor/monitor/template.go @@ -371,6 +371,14 @@ func scrapeJob(jobName string, componentPattern config.Regexp, cmodel *MonitorCo Action: config.RelabelReplace, TargetLabel: "component", }, + { + SourceLabels: model.LabelNames{ + namespaceLabel, + instanceLabel, + }, + Separator: "-", + TargetLabel: "tidb_cluster", + }, }, } if cmodel.EnableTLSCluster { diff --git a/pkg/monitor/monitor/template_test.go b/pkg/monitor/monitor/template_test.go index d34f386c2dc..d67f7a45ab9 100644 --- a/pkg/monitor/monitor/template_test.go +++ b/pkg/monitor/monitor/template_test.go @@ -84,6 +84,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tidb honor_labels: true scrape_interval: 15s @@ -131,6 +134,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tikv honor_labels: true scrape_interval: 15s @@ -178,6 +184,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tiflash honor_labels: true scrape_interval: 15s @@ -225,6 +234,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tiflash-proxy honor_labels: true scrape_interval: 15s @@ -272,6 +284,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-pump honor_labels: true scrape_interval: 15s @@ -319,6 +334,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-drainer honor_labels: true scrape_interval: 15s @@ -366,6 +384,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-ticdc honor_labels: true scrape_interval: 15s @@ -413,6 +434,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-importer honor_labels: true scrape_interval: 15s @@ -460,6 +484,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-lightning honor_labels: true scrape_interval: 15s @@ -507,6 +534,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster remote_write: - url: http://localhost:1234 remote_timeout: 15s @@ -609,6 +639,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tidb honor_labels: true scrape_interval: 15s @@ -659,6 +692,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tikv honor_labels: true scrape_interval: 15s @@ -709,6 +745,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tiflash honor_labels: true scrape_interval: 15s @@ -759,6 +798,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-tiflash-proxy honor_labels: true scrape_interval: 15s @@ -809,6 +851,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-pump honor_labels: true scrape_interval: 15s @@ -859,6 +904,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-drainer honor_labels: true scrape_interval: 15s @@ -909,6 +957,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-ticdc honor_labels: true scrape_interval: 15s @@ -959,6 +1010,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-importer honor_labels: true scrape_interval: 15s @@ -1009,6 +1063,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster - job_name: ns1-target-lightning honor_labels: true scrape_interval: 15s @@ -1056,6 +1113,9 @@ scrape_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component] target_label: component action: replace + - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance] + separator: '-' + target_label: tidb_cluster ` model := &MonitorConfigModel{ ClusterInfos: []ClusterRegexInfo{