Skip to content

Commit 74da0b2

Browse files
committed
Add scrapeconfig files
Signed-off-by: Juan Enciso <[email protected]>
1 parent c39e4ef commit 74da0b2

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

Diff for: charts/kube-state-metrics/templates/_helpers.tpl

+19
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ labelValueLengthLimit: {{ . }}
104104
{{- end }}
105105
{{- end -}}
106106

107+
{{/* Sets default scrape limits for scrapeconfig */}}
108+
{{- define "scrapeconfig.scrapeLimits" -}}
109+
{{- with .sampleLimit }}
110+
sampleLimit: {{ . }}
111+
{{- end }}
112+
{{- with .targetLimit }}
113+
targetLimit: {{ . }}
114+
{{- end }}
115+
{{- with .labelLimit }}
116+
labelLimit: {{ . }}
117+
{{- end }}
118+
{{- with .labelNameLengthLimit }}
119+
labelNameLengthLimit: {{ . }}
120+
{{- end }}
121+
{{- with .labelValueLengthLimit }}
122+
labelValueLengthLimit: {{ . }}
123+
{{- end }}
124+
{{- end -}}
125+
107126
{{/*
108127
Formats imagePullSecrets. Input is (dict "Values" .Values "imagePullSecrets" .{specific imagePullSecrets})
109128
*/}}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{{- if .Values.prometheus.scrapeconfig.enabled }}
2+
apiVersion: monitoring.coreos.com/v1alpha1
3+
kind: ScrapeConfig
4+
metadata:
5+
name: {{ template "kube-state-metrics.fullname" . }}
6+
namespace: {{ template "kube-state-metrics.namespace" . }}
7+
labels:
8+
{{- include "kube-state-metrics.labels" . | indent 4 }}
9+
{{- with .Values.prometheus.scrapeconfig.additionalLabels }}
10+
{{- tpl (toYaml . | nindent 4) $ }}
11+
{{- end }}
12+
{{- with .Values.prometheus.scrapeconfig.annotations }}
13+
annotations:
14+
{{- tpl (toYaml . | nindent 4) $ }}
15+
{{- end }}
16+
spec:
17+
jobName: {{ default "app.kubernetes.io/name" .Values.prometheus.scrapeconfig.jobLabel }}
18+
{{- include "scrapeconfig.scrapeLimits" .Values.prometheus.scrapeconfig | indent 2 }}
19+
staticConfigs:
20+
- targets:
21+
- {{ template "kube-state-metrics.fullname" . }}.{{ template "kube-state-metrics.namespace" . }}.svc:{{ .Values.service.port }}
22+
labels:
23+
{{- with .Values.prometheus.scrapeconfig.staticConfigLabels }}
24+
{{- tpl (toYaml . | nindent 8) $ }}
25+
{{- end }}
26+
{{- if .Values.prometheus.scrapeconfig.honorLabels }}
27+
honorLabels: true
28+
{{- end }}
29+
{{- if .Values.prometheus.scrapeconfig.scrapeInterval }}
30+
scrapeInterval: {{ .Values.prometheus.scrapeconfig.scrapeInterval }}
31+
{{- end }}
32+
{{- if .Values.prometheus.scrapeconfig.scrapeTimeout }}
33+
scrapeTimeout: {{ .Values.prometheus.scrapeconfig.scrapeTimeout }}
34+
{{- end }}
35+
{{- if .Values.prometheus.scrapeconfig.proxyUrl }}
36+
proxyUrl: {{ .Values.prometheus.scrapeconfig.proxyUrl }}
37+
{{- end }}
38+
{{- if .Values.prometheus.scrapeconfig.enableHttp2 }}
39+
enableHttp2: {{ .Values.prometheus.scrapeconfig.enableHttp2 }}
40+
{{- end }}
41+
{{- if .Values.prometheus.scrapeconfig.metricRelabelings }}
42+
metricRelabelings:
43+
{{- toYaml (.Values.prometheus.scrapeconfig.metricRelabelings | nindent 4 }}
44+
{{- end }}
45+
{{- if .Values.prometheus.scrapeconfig.relabelings }}
46+
relabelings:
47+
{{- toYaml (.Values.prometheus.scrapeconfig.relabelings ) | nindent 4 }}
48+
{{- end }}
49+
{{- if or .Values.prometheus.scrapeconfig.scheme }}
50+
scheme: {{ .Values.prometheus.scrapeconfig.scheme }}
51+
{{- end }}
52+
{{- if .Values.prometheus.scrapeconfig.tlsConfig }}
53+
tlsConfig:
54+
{{- toYaml (.Values.prometheus.scrapeconfig.tlsConfig ) | nindent 4 }}
55+
{{- end }}
56+
{{- end }}

Diff for: charts/kube-state-metrics/values.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,43 @@ prometheus:
239239
# name: secret-name
240240
# key: key-name
241241
tlsConfig: {}
242+
## Scrapeconfig creates a scrapeConfig resource to scrape the KSM svc instead of use serviceMonitor.
243+
scrapeconfig:
244+
enabled: false
245+
annotations: {}
246+
additionalLabels: {}
247+
## SampleLimit defines per-scrape limit on number of scraped samples that will be accepted.
248+
##
249+
sampleLimit: 0
250+
251+
## TargetLimit defines a limit on the number of scraped targets that will be accepted.
252+
##
253+
targetLimit: 0
254+
255+
## Per-scrape limit on number of labels that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
256+
##
257+
labelLimit: 0
258+
259+
## Per-scrape limit on length of labels name that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
260+
##
261+
labelNameLengthLimit: 0
262+
263+
## Per-scrape limit on length of labels value that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
264+
##
265+
labelValueLengthLimit: 0
266+
267+
## StaticConfigLabels defines the labels to be used in the Prometheus static configuration for scraping.
268+
staticConfigLabels: {}
269+
scrapeInterval: ""
270+
scrapeTimeout: ""
271+
proxyUrl: ""
272+
## Whether to enable HTTP2 for scrapeconfig
273+
enableHttp2: false
274+
honorLabels: false
275+
metricRelabelings: []
276+
relabelings: []
277+
scheme: ""
278+
tlsConfig: {}
242279

243280
## Specify if a Pod Security Policy for kube-state-metrics must be created
244281
## Ref: https://kubernetes.io/docs/concepts/policy/pod-security-policy/

0 commit comments

Comments
 (0)