forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape_config.libsonnet
187 lines (166 loc) · 6.05 KB
/
scrape_config.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
local config = import 'config.libsonnet';
config {
local gen_scrape_config(job_name, pod_uid) = {
job_name: job_name,
pipeline_stages: $._config.promtail_config.pipeline_stages,
kubernetes_sd_configs: [{
role: 'pod',
}],
relabel_configs: self.prelabel_config + [
// Only scrape local pods; Promtail will drop targets with a __host__ label
// that does not match the current host name.
{
source_labels: ['__meta_kubernetes_pod_node_name'],
target_label: '__host__',
},
// Drop pods without a __service__ label.
{
source_labels: ['__service__'],
action: 'drop',
regex: '',
},
// Include all the other labels on the pod.
// Perform this mapping before applying additional label replacement rules
// to prevent a supplied label from overwriting any of the following labels.
{
action: 'labelmap',
regex: '__meta_kubernetes_pod_label_(.+)',
},
// Rename jobs to be <namespace>/<name, from pod name label>
{
source_labels: ['__meta_kubernetes_namespace', '__service__'],
action: 'replace',
separator: '/',
target_label: 'job',
replacement: '$1',
},
// But also include the namespace as a separate label, for routing alerts
{
source_labels: ['__meta_kubernetes_namespace'],
action: 'replace',
target_label: 'namespace',
},
// Rename instances to be the pod name
{
source_labels: ['__meta_kubernetes_pod_name'],
action: 'replace',
target_label: 'instance',
},
// Include container_name label
{
source_labels: ['__meta_kubernetes_pod_container_name'],
action: 'replace',
target_label: 'container_name',
},
// Kubernetes puts logs under subdirectories keyed pod UID and container_name.
{
source_labels: [pod_uid, '__meta_kubernetes_pod_container_name'],
target_label: '__path__',
separator: '/',
replacement: '/var/log/pods/*$1/*.log',
},
],
},
promtail_config:: {
scrape_configs: [
// Scrape config to scrape any pods with a 'name' label.
gen_scrape_config('kubernetes-pods-name', '__meta_kubernetes_pod_uid') {
prelabel_config:: [
// Use name label as __service__.
{
source_labels: ['__meta_kubernetes_pod_label_name'],
target_label: '__service__',
},
],
},
// Scrape config to scrape any pods with a 'app' label.
gen_scrape_config('kubernetes-pods-app', '__meta_kubernetes_pod_uid') {
prelabel_config:: [
// Drop pods with a 'name' label. They will have already been added by
// the scrape_config that matches on the 'name' label
{
source_labels: ['__meta_kubernetes_pod_label_name'],
action: 'drop',
regex: '.+',
},
// Use app label as the __service__.
{
source_labels: ['__meta_kubernetes_pod_label_app'],
target_label: '__service__',
},
],
},
// Scrape config to scrape any pods with a direct controller (eg
// StatefulSets).
gen_scrape_config('kubernetes-pods-direct-controllers', '__meta_kubernetes_pod_uid') {
prelabel_config:: [
// Drop pods with a 'name' or 'app' label. They will have already been added by
// the scrape_config that matches above.
{
source_labels: ['__meta_kubernetes_pod_label_name', '__meta_kubernetes_pod_label_app'],
separator: '',
action: 'drop',
regex: '.+',
},
// Drop pods with an indirect controller. eg Deployments create replicaSets
// which then create pods.
{
source_labels: ['__meta_kubernetes_pod_controller_name'],
action: 'drop',
regex: '[0-9a-z-.]+-[0-9a-f]{8,10}',
},
// Use controller name as __service__.
{
source_labels: ['__meta_kubernetes_pod_controller_name'],
target_label: '__service__',
},
],
},
// Scrape config to scrape any pods with an indirect controller (eg
// Deployments).
gen_scrape_config('kubernetes-pods-indirect-controller', '__meta_kubernetes_pod_uid') {
prelabel_config:: [
// Drop pods with a 'name' or 'app' label. They will have already been added by
// the scrape_config that matches above.
{
source_labels: ['__meta_kubernetes_pod_label_name', '__meta_kubernetes_pod_label_app'],
separator: '',
action: 'drop',
regex: '.+',
},
// Drop pods not from an indirect controller. eg StatefulSets, DaemonSets
{
source_labels: ['__meta_kubernetes_pod_controller_name'],
regex: '[0-9a-z-.]+-[0-9a-f]{8,10}',
action: 'keep',
},
// Put the indirect controller name into a temp label.
{
source_labels: ['__meta_kubernetes_pod_controller_name'],
action: 'replace',
regex: '([0-9a-z-.]+)-[0-9a-f]{8,10}',
target_label: '__service__',
},
],
},
// Scrape config to scrape any control plane static pods (e.g. kube-apiserver
// etcd, kube-controller-manager & kube-scheduler)
gen_scrape_config('kubernetes-pods-static', '__meta_kubernetes_pod_annotation_kubernetes_io_config_mirror') {
prelabel_config:: [
// Ignore pods that aren't mirror pods
{
action: 'drop',
source_labels: ['__meta_kubernetes_pod_annotation_kubernetes_io_config_mirror'],
regex: '',
},
// Static control plane pods usually have a component label that identifies them
{
action: 'replace',
source_labels: ['__meta_kubernetes_pod_label_component'],
target_label: '__service__',
},
],
},
],
},
}