Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support thanos integration #98

Merged
merged 6 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/opencost/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords:
- kubecost
- opencost
- monitoring
version: 1.18.0
version: 1.19.0
maintainers:
- name: mattray
url: https://mattray.dev
Expand Down
16 changes: 16 additions & 0 deletions charts/opencost/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,27 @@ Create the name of the controller service account to use
{{- end -}}


{{- define "opencost.thanosServerEndpoint" -}}
{{- if .Values.opencost.prometheus.thanos.external.enabled -}}
{{ .Values.opencost.prometheus.thanos.external.url }}
{{- else -}}
{{- $host := .Values.opencost.prometheus.thanos.internal.serviceName }}
{{- $ns := .Values.opencost.prometheus.thanos.internal.namespaceName }}
{{- $port := .Values.opencost.prometheus.thanos.internal.port | int }}
{{- printf "http://%s.%s.svc:%d" $host $ns $port -}}
{{- end -}}
{{- end -}}

{{/*
Check that either prometheus external or internal is defined
*/}}
{{- define "isPrometheusConfigValid" -}}
{{- if and .Values.opencost.prometheus.external.enabled .Values.opencost.prometheus.internal.enabled -}}
{{- fail "Only use one of the prometheus setups, internal or external" -}}
{{- end -}}
{{- if .Values.opencost.prometheus.thanos.enabled -}}
{{- if and .Values.opencost.prometheus.thanos.external.enabled .Values.opencost.prometheus.thanos.internal.enabled -}}
{{- fail "Only use one of the thanos setups, internal or external" -}}
{{- end -}}
{{- end -}}
{{- end -}}
16 changes: 15 additions & 1 deletion charts/opencost/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,21 @@ spec:
{{- if and .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.csv_path }}
- name: EXPORT_CSV_FILE
value: {{ .Values.opencost.exporter.csv_path | quote }}
{{- end}}
{{- end }}
{{- if .Values.opencost.prometheus.thanos.enabled }}
- name: THANOS_ENABLED
value: 'true'
- name: THANOS_QUERY_URL
value: {{ include "opencost.thanosServerEndpoint" . | quote }}
{{- end }}
{{- if .Values.opencost.prometheus.thanos.queryOffset }}
- name: THANOS_QUERY_OFFSET
value: {{ .Values.opencost.prometheus.thanos.queryOffset | quote }}
{{- end }}
{{- if .Values.opencost.prometheus.thanos.maxSourceResolution }}
- name: THANOS_MAX_SOURCE_RESOLUTION
value: {{ .Values.opencost.prometheus.thanos.maxSourceResolution | quote }}
{{- end }}
{{- with .Values.opencost.exporter.env }}
{{- toYaml . | nindent 12 }}
{{- end }}
Expand Down
12 changes: 12 additions & 0 deletions charts/opencost/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ opencost:
namespaceName: opencost
# -- Service port of in-cluster Prometheus
port: 9090
thanos:
enabled: false
queryOffset: ''
maxSourceResolution: ''
internal:
enabled: true
serviceName: my-thanos-query
namespaceName: opencost
port: 10901
external:
enabled: false
url: 'https://thanos-query.example.com/thanos'

ui:
# -- Enable OpenCost UI
Expand Down
Loading