Skip to content

Commit e78139e

Browse files
Reasonablymattray
andauthored
feat: Support thanos integration (#98)
* feat: Support thanos integration * fix: Set default false * fix: bump chart version * fix: trailing space --------- Signed-off-by: Matt Ray <github@mattray.dev> Co-authored-by: Matt Ray <github@mattray.dev>
1 parent fdcc15f commit e78139e

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

charts/opencost/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords:
99
- kubecost
1010
- opencost
1111
- monitoring
12-
version: 1.18.1
12+
version: 1.19.0
1313
maintainers:
1414
- name: mattray
1515
url: https://mattray.dev

charts/opencost/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,27 @@ Create the name of the controller service account to use
9292
{{- end -}}
9393

9494

95+
{{- define "opencost.thanosServerEndpoint" -}}
96+
{{- if .Values.opencost.prometheus.thanos.external.enabled -}}
97+
{{ .Values.opencost.prometheus.thanos.external.url }}
98+
{{- else -}}
99+
{{- $host := .Values.opencost.prometheus.thanos.internal.serviceName }}
100+
{{- $ns := .Values.opencost.prometheus.thanos.internal.namespaceName }}
101+
{{- $port := .Values.opencost.prometheus.thanos.internal.port | int }}
102+
{{- printf "http://%s.%s.svc:%d" $host $ns $port -}}
103+
{{- end -}}
104+
{{- end -}}
105+
95106
{{/*
96107
Check that either prometheus external or internal is defined
97108
*/}}
98109
{{- define "isPrometheusConfigValid" -}}
99110
{{- if and .Values.opencost.prometheus.external.enabled .Values.opencost.prometheus.internal.enabled -}}
100111
{{- fail "Only use one of the prometheus setups, internal or external" -}}
101112
{{- end -}}
113+
{{- if .Values.opencost.prometheus.thanos.enabled -}}
114+
{{- if and .Values.opencost.prometheus.thanos.external.enabled .Values.opencost.prometheus.thanos.internal.enabled -}}
115+
{{- fail "Only use one of the thanos setups, internal or external" -}}
116+
{{- end -}}
117+
{{- end -}}
102118
{{- end -}}

charts/opencost/templates/deployment.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,21 @@ spec:
125125
{{- if and .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.csv_path }}
126126
- name: EXPORT_CSV_FILE
127127
value: {{ .Values.opencost.exporter.csv_path | quote }}
128-
{{- end}}
128+
{{- end }}
129+
{{- if .Values.opencost.prometheus.thanos.enabled }}
130+
- name: THANOS_ENABLED
131+
value: 'true'
132+
- name: THANOS_QUERY_URL
133+
value: {{ include "opencost.thanosServerEndpoint" . | quote }}
134+
{{- end }}
135+
{{- if .Values.opencost.prometheus.thanos.queryOffset }}
136+
- name: THANOS_QUERY_OFFSET
137+
value: {{ .Values.opencost.prometheus.thanos.queryOffset | quote }}
138+
{{- end }}
139+
{{- if .Values.opencost.prometheus.thanos.maxSourceResolution }}
140+
- name: THANOS_MAX_SOURCE_RESOLUTION
141+
value: {{ .Values.opencost.prometheus.thanos.maxSourceResolution | quote }}
142+
{{- end }}
129143
{{- with .Values.opencost.exporter.env }}
130144
{{- toYaml . | nindent 12 }}
131145
{{- end }}

charts/opencost/values.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ opencost:
170170
namespaceName: opencost
171171
# -- Service port of in-cluster Prometheus
172172
port: 9090
173+
thanos:
174+
enabled: false
175+
queryOffset: ''
176+
maxSourceResolution: ''
177+
internal:
178+
enabled: true
179+
serviceName: my-thanos-query
180+
namespaceName: opencost
181+
port: 10901
182+
external:
183+
enabled: false
184+
url: 'https://thanos-query.example.com/thanos'
173185

174186
ui:
175187
# -- Enable OpenCost UI

0 commit comments

Comments
 (0)