/
podmonitor_types.go
310 lines (270 loc) · 10.2 KB
/
podmonitor_types.go
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Copyright 2018 The prometheus-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
)
const (
PodMonitorsKind = "PodMonitor"
PodMonitorName = "podmonitors"
PodMonitorKindKey = "podmonitor"
)
// +genclient
// +k8s:openapi-gen=true
// +kubebuilder:resource:categories="prometheus-operator",shortName="pmon"
// PodMonitor defines monitoring for a set of pods.
type PodMonitor struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of desired Pod selection for target discovery by Prometheus.
Spec PodMonitorSpec `json:"spec"`
}
// DeepCopyObject implements the runtime.Object interface.
func (l *PodMonitor) DeepCopyObject() runtime.Object {
return l.DeepCopy()
}
// PodMonitorSpec contains specification parameters for a PodMonitor.
// +k8s:openapi-gen=true
type PodMonitorSpec struct {
// The label to use to retrieve the job name from.
// `jobLabel` selects the label from the associated Kubernetes `Pod`
// object which will be used as the `job` label for all metrics.
//
// For example if `jobLabel` is set to `foo` and the Kubernetes `Pod`
// object is labeled with `foo: bar`, then Prometheus adds the `job="bar"`
// label to all ingested metrics.
//
// If the value of this field is empty, the `job` label of the metrics
// defaults to the namespace and name of the PodMonitor object (e.g. `<namespace>/<name>`).
JobLabel string `json:"jobLabel,omitempty"`
// `podTargetLabels` defines the labels which are transferred from the
// associated Kubernetes `Pod` object onto the ingested metrics.
//
PodTargetLabels []string `json:"podTargetLabels,omitempty"`
// List of endpoints part of this PodMonitor.
//
// +optional
PodMetricsEndpoints []PodMetricsEndpoint `json:"podMetricsEndpoints"`
// Label selector to select the Kubernetes `Pod` objects.
Selector metav1.LabelSelector `json:"selector"`
// Selector to select which namespaces the Kubernetes `Pods` objects
// are discovered from.
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
// `sampleLimit` defines a per-scrape limit on the number of scraped samples
// that will be accepted.
//
// +optional
SampleLimit *uint64 `json:"sampleLimit,omitempty"`
// `targetLimit` defines a limit on the number of scraped targets that will
// be accepted.
//
// +optional
TargetLimit *uint64 `json:"targetLimit,omitempty"`
// `scrapeProtocols` defines the protocols to negotiate during a scrape. It tells clients the
// protocols supported by Prometheus in order of preference (from most to least preferred).
//
// If unset, Prometheus uses its default value.
//
// It requires Prometheus >= v2.49.0.
//
// +listType=set
// +optional
ScrapeProtocols []ScrapeProtocol `json:"scrapeProtocols,omitempty"`
// Per-scrape limit on number of labels that will be accepted for a sample.
//
// It requires Prometheus >= v2.27.0.
//
// +optional
LabelLimit *uint64 `json:"labelLimit,omitempty"`
// Per-scrape limit on length of labels name that will be accepted for a sample.
//
// It requires Prometheus >= v2.27.0.
//
// +optional
LabelNameLengthLimit *uint64 `json:"labelNameLengthLimit,omitempty"`
// Per-scrape limit on length of labels value that will be accepted for a sample.
//
// It requires Prometheus >= v2.27.0.
//
// +optional
LabelValueLengthLimit *uint64 `json:"labelValueLengthLimit,omitempty"`
// Per-scrape limit on the number of targets dropped by relabeling
// that will be kept in memory. 0 means no limit.
//
// It requires Prometheus >= v2.47.0.
//
// +optional
KeepDroppedTargets *uint64 `json:"keepDroppedTargets,omitempty"`
// `attachMetadata` defines additional metadata which is added to the
// discovered targets.
//
// It requires Prometheus >= v2.37.0.
//
// +optional
AttachMetadata *AttachMetadata `json:"attachMetadata,omitempty"`
// The scrape class to apply.
// +optional
// +kubebuilder:validation:MinLength=1
ScrapeClassName *string `json:"scrapeClass,omitempty"`
}
// PodMonitorList is a list of PodMonitors.
// +k8s:openapi-gen=true
type PodMonitorList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata
// More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
metav1.ListMeta `json:"metadata,omitempty"`
// List of PodMonitors
Items []*PodMonitor `json:"items"`
}
// DeepCopyObject implements the runtime.Object interface.
func (l *PodMonitorList) DeepCopyObject() runtime.Object {
return l.DeepCopy()
}
// PodMetricsEndpoint defines an endpoint serving Prometheus metrics to be scraped by
// Prometheus.
//
// +k8s:openapi-gen=true
type PodMetricsEndpoint struct {
// Name of the Pod port which this endpoint refers to.
//
// It takes precedence over `targetPort`.
Port string `json:"port,omitempty"`
// Name or number of the target port of the `Pod` object behind the Service, the
// port must be specified with container port property.
//
// Deprecated: use 'port' instead.
TargetPort *intstr.IntOrString `json:"targetPort,omitempty"`
// HTTP path from which to scrape for metrics.
//
// If empty, Prometheus uses the default value (e.g. `/metrics`).
Path string `json:"path,omitempty"`
// HTTP scheme to use for scraping.
//
// `http` and `https` are the expected values unless you rewrite the
// `__scheme__` label via relabeling.
//
// If empty, Prometheus uses the default value `http`.
//
// +kubebuilder:validation:Enum=http;https
Scheme string `json:"scheme,omitempty"`
// `params` define optional HTTP URL parameters.
Params map[string][]string `json:"params,omitempty"`
// Interval at which Prometheus scrapes the metrics from the target.
//
// If empty, Prometheus uses the global scrape interval.
Interval Duration `json:"interval,omitempty"`
// Timeout after which Prometheus considers the scrape to be failed.
//
// If empty, Prometheus uses the global scrape timeout unless it is less
// than the target's scrape interval value in which the latter is used.
ScrapeTimeout Duration `json:"scrapeTimeout,omitempty"`
// TLS configuration to use when scraping the target.
//
// +optional
TLSConfig *PodMetricsEndpointTLSConfig `json:"tlsConfig,omitempty"`
// `bearerTokenSecret` specifies a key of a Secret containing the bearer
// token for scraping targets. The secret needs to be in the same namespace
// as the PodMonitor object and readable by the Prometheus Operator.
//
// +optional
//
// Deprecated: use `authorization` instead.
BearerTokenSecret v1.SecretKeySelector `json:"bearerTokenSecret,omitempty"`
// When true, `honorLabels` preserves the metric's labels when they collide
// with the target's labels.
HonorLabels bool `json:"honorLabels,omitempty"`
// `honorTimestamps` controls whether Prometheus preserves the timestamps
// when exposed by the target.
//
// +optional
HonorTimestamps *bool `json:"honorTimestamps,omitempty"`
// `trackTimestampsStaleness` defines whether Prometheus tracks staleness of
// the metrics that have an explicit timestamp present in scraped data.
// Has no effect if `honorTimestamps` is false.
//
// It requires Prometheus >= v2.48.0.
//
// +optional
TrackTimestampsStaleness *bool `json:"trackTimestampsStaleness,omitempty"`
// `basicAuth` configures the Basic Authentication credentials to use when
// scraping the target.
//
// Cannot be set at the same time as `authorization`, or `oauth2`.
//
// +optional
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
// `oauth2` configures the OAuth2 settings to use when scraping the target.
//
// It requires Prometheus >= 2.27.0.
//
// Cannot be set at the same time as `authorization`, or `basicAuth`.
//
// +optional
OAuth2 *OAuth2 `json:"oauth2,omitempty"`
// `authorization` configures the Authorization header credentials to use when
// scraping the target.
//
// Cannot be set at the same time as `basicAuth`, or `oauth2`.
//
// +optional
Authorization *SafeAuthorization `json:"authorization,omitempty"`
// `metricRelabelings` configures the relabeling rules to apply to the
// samples before ingestion.
//
// +optional
MetricRelabelConfigs []*RelabelConfig `json:"metricRelabelings,omitempty"`
// `relabelings` configures the relabeling rules to apply the target's
// metadata labels.
//
// The Operator automatically adds relabelings for a few standard Kubernetes fields.
//
// The original scrape job's name is available via the `__tmp_prometheus_job_name` label.
//
// More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
//
// +optional
RelabelConfigs []*RelabelConfig `json:"relabelings,omitempty"`
// `proxyURL` configures the HTTP Proxy URL (e.g.
// "http://proxyserver:2195") to go through when scraping the target.
//
// +optional
ProxyURL *string `json:"proxyUrl,omitempty"`
// `followRedirects` defines whether the scrape requests should follow HTTP
// 3xx redirects.
//
// +optional
FollowRedirects *bool `json:"followRedirects,omitempty"`
// `enableHttp2` can be used to disable HTTP2 when scraping the target.
//
// +optional
EnableHttp2 *bool `json:"enableHttp2,omitempty"`
// When true, the pods which are not running (e.g. either in Failed or
// Succeeded state) are dropped during the target discovery.
//
// If unset, the filtering is enabled.
//
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase
//
// +optional
FilterRunning *bool `json:"filterRunning,omitempty"`
}
// PodMetricsEndpointTLSConfig specifies TLS configuration parameters.
// +k8s:openapi-gen=true
type PodMetricsEndpointTLSConfig struct {
SafeTLSConfig `json:",inline"`
}