Skip to content

Commit

Permalink
feat: Support thanos integration (#98)
Browse files Browse the repository at this point in the history
* feat: Support thanos integration

* fix: Set default false

* fix: bump chart version

* fix: trailing space

---------

Signed-off-by: Matt Ray <[email protected]>
Co-authored-by: Matt Ray <[email protected]>
  • Loading branch information
Reasonably and mattray authored Aug 28, 2023
1 parent fdcc15f commit e78139e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
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.1
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

0 comments on commit e78139e

Please sign in to comment.