github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/application/applications/metricspersisting/config/scrapeconfig.go (about)

     1  package config
     2  
     3  import "github.com/caos/orbos/internal/operator/boom/application/applications/metricspersisting/helm"
     4  
     5  func getScrapeConfigs() []*helm.AdditionalScrapeConfig {
     6  
     7  	adconfigs := make([]*helm.AdditionalScrapeConfig, 0)
     8  
     9  	adconfigs = append(adconfigs, getNodes())
    10  	adconfigs = append(adconfigs, getCadvisor())
    11  	adconfigs = append(adconfigs, getEtcd())
    12  
    13  	return adconfigs
    14  
    15  }
    16  
    17  func getNodes() *helm.AdditionalScrapeConfig {
    18  	relabelings := make([]*helm.RelabelConfig, 0)
    19  	relabeling := &helm.RelabelConfig{
    20  		Action: "labelmap",
    21  		Regex:  "__meta_kubernetes_node_label_(.+)",
    22  	}
    23  	relabelings = append(relabelings, relabeling)
    24  	relabeling = &helm.RelabelConfig{
    25  		TargetLabel: "__address__",
    26  		Replacement: "kubernetes.default.svc:443",
    27  	}
    28  	relabelings = append(relabelings, relabeling)
    29  	relabeling = &helm.RelabelConfig{
    30  		SourceLabels: []string{"__meta_kubernetes_node_name"},
    31  		Regex:        "(.+)",
    32  		TargetLabel:  "__metrics_path__",
    33  		Replacement:  "/api/v1/nodes/${1}/proxy/metrics",
    34  	}
    35  	relabelings = append(relabelings, relabeling)
    36  
    37  	relabeling = &helm.RelabelConfig{
    38  		TargetLabel: "metrics_path",
    39  		Replacement: "/metrics",
    40  	}
    41  	relabelings = append(relabelings, relabeling)
    42  
    43  	sdconfig := &helm.KubernetesSdConfig{
    44  		Role: "node",
    45  	}
    46  
    47  	return &helm.AdditionalScrapeConfig{
    48  		JobName:             "kubernetes-nodes",
    49  		Scheme:              "https",
    50  		KubernetesSdConfigs: []*helm.KubernetesSdConfig{sdconfig},
    51  		BearerTokenFile:     "/var/run/secrets/kubernetes.io/serviceaccount/token",
    52  		TLSConfig: &helm.TLSConfig{
    53  			CaFile: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
    54  		},
    55  		RelabelConfigs: relabelings,
    56  	}
    57  }
    58  
    59  func getCadvisor() *helm.AdditionalScrapeConfig {
    60  	relabelings := make([]*helm.RelabelConfig, 0)
    61  	relabeling := &helm.RelabelConfig{
    62  		Action: "labelmap",
    63  		Regex:  "__meta_kubernetes_node_label_(.+)",
    64  	}
    65  	relabelings = append(relabelings, relabeling)
    66  	relabeling = &helm.RelabelConfig{
    67  		TargetLabel: "__address__",
    68  		Replacement: "kubernetes.default.svc:443",
    69  	}
    70  	relabelings = append(relabelings, relabeling)
    71  	relabeling = &helm.RelabelConfig{
    72  		SourceLabels: []string{"__meta_kubernetes_node_name"},
    73  		Regex:        "(.+)",
    74  		TargetLabel:  "__metrics_path__",
    75  		Replacement:  "/api/v1/nodes/${1}/proxy/metrics/cadvisor",
    76  	}
    77  	relabelings = append(relabelings, relabeling)
    78  
    79  	relabeling = &helm.RelabelConfig{
    80  		TargetLabel: "metrics_path",
    81  		Replacement: "/metrics/cadvisor",
    82  	}
    83  	relabelings = append(relabelings, relabeling)
    84  
    85  	sdconfig := &helm.KubernetesSdConfig{
    86  		Role: "node",
    87  	}
    88  
    89  	return &helm.AdditionalScrapeConfig{
    90  		JobName:             "kubelet",
    91  		Scheme:              "https",
    92  		KubernetesSdConfigs: []*helm.KubernetesSdConfig{sdconfig},
    93  		BearerTokenFile:     "/var/run/secrets/kubernetes.io/serviceaccount/token",
    94  		TLSConfig: &helm.TLSConfig{
    95  			CaFile: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
    96  		},
    97  		RelabelConfigs: relabelings,
    98  	}
    99  }
   100  
   101  func getEtcd() *helm.AdditionalScrapeConfig {
   102  
   103  	sdconfig := &helm.KubernetesSdConfig{
   104  		Role: "node",
   105  	}
   106  
   107  	relabelings := []*helm.RelabelConfig{{
   108  		Action:       "replace",
   109  		SourceLabels: []string{"__address__"},
   110  		TargetLabel:  "__address__",
   111  		Regex:        "(.*):.*",
   112  		Replacement:  "${1}:2381",
   113  	}, {
   114  		Action:       "keep",
   115  		Regex:        "true",
   116  		SourceLabels: []string{"__meta_kubernetes_node_labelpresent_node_role_kubernetes_io_master"},
   117  	}}
   118  
   119  	metricRelabelConfigs := []*helm.RelabelConfig{{
   120  		Action:       "keep",
   121  		Regex:        "etcd_server_has_leader",
   122  		SourceLabels: []string{"__name__"},
   123  	}, {
   124  		Action:       "replace",
   125  		SourceLabels: []string{"__name__"},
   126  		TargetLabel:  "__name__",
   127  		Regex:        "etcd_server_has_leader",
   128  		Replacement:  "dist_etcd_server_has_leader",
   129  	}}
   130  
   131  	return &helm.AdditionalScrapeConfig{
   132  		JobName:              "caos_remote_etcd",
   133  		Scheme:               "http",
   134  		KubernetesSdConfigs:  []*helm.KubernetesSdConfig{sdconfig},
   135  		RelabelConfigs:       relabelings,
   136  		MetricRelabelConfigs: metricRelabelConfigs,
   137  	}
   138  }