-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add OpenCost to the ClusterMetrics feature #923
Conversation
c5af60a
to
2042f40
Compare
Signed-off-by: Pete Wall <pete.wall@grafana.com>
2042f40
to
dd4e79d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providing inline review tips.
{{- if ne .Values.cluster.name .Values.clusterMetrics.opencost.opencost.exporter.defaultClusterId }} | ||
{{- $msg := list "" "The OpenCost default cluster id should match the cluster name." }} | ||
{{- $msg = append $msg "Please set:" }} | ||
{{- $msg = append $msg "clusterMetrics:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- $msg = append $msg " exporter:" }} | ||
{{- $msg = append $msg (printf " defaultClusterId: %s" .Values.cluster.name) }} | ||
{{- fail (join "\n" $msg) }} | ||
{{- end -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guides the user to set the default cluster id for OpenCost to the cluster name.
{{- fail (join "\n" $msg) }} | ||
{{- end -}} | ||
|
||
{{- if ne .Values.clusterMetrics.opencost.metricsSource "custom" }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting to custom
will skip all other guidance and validation. This allows a user to set things that we don't expect, like alternative auth types.
{{- if eq .Values.clusterMetrics.opencost.metricsSource "" }} | ||
{{- $msg := list "" "OpenCost requires linking to a Prometheus data source." }} | ||
{{- $msg = append $msg "Please set:" }} | ||
{{- $msg = append $msg "clusterMetrics:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- if eq (len $destinations) 1 }} | ||
{{- $msg = append $msg (printf " metricsSource: %s" (first $destinations)) }} | ||
{{- else }} | ||
{{- $msg = append $msg " metricsSource: <metrics destination name>" }} | ||
{{- $msg = append $msg (printf "Where <metrics destination name> is one of %s" (include "english_list_or" $destinations)) }} | ||
{{- end }} | ||
{{- fail (join "\n" $msg) }} | ||
{{- end -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring a metricSource
is how we tie the rest of the validations to a specific destination.
{{- if regexMatch "/api/prom/push" $destinationUrl }} | ||
{{- $openCostMetricsUrl = (regexReplaceAll "^(.*)/api/prom/push$" $destinationUrl "${1}/api/prom") }} | ||
{{- else if regexMatch "/api/v1/push" $destinationUrl }} | ||
{{- $openCostMetricsUrl = (regexReplaceAll "^(.*)/api/v1/push$" $destinationUrl "${1}/api/v1/query") }} | ||
{{- else if regexMatch "/api/v1/write" $destinationUrl }} | ||
{{- $openCostMetricsUrl = (regexReplaceAll "^(.*)/api/v1/write$" $destinationUrl "${1}/api/v1/query") }} | ||
{{- else }} | ||
{{- $openCostMetricsUrl = (printf "<%s Query URL>" $destinationName)}} | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is attempting to generate a query URL given the push url. The first is for Grafana Cloud, the second for Mimir, the third for OSS prometheus.
{{- if eq $secretType "embedded" }} | ||
{{- $destinationUsername := include "secrets.getSecretValue" (dict "object" $destination "key" ".auth.username") }} | ||
{{- if ne $.Values.clusterMetrics.opencost.opencost.prometheus.username $destinationUsername}} | ||
{{- $msg := list "" (printf "The username for %s and OpenCost do not match." $destinationName) }} | ||
{{- $msg = append $msg "Please set:" }} | ||
{{- $msg = append $msg "clusterMetrics:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- $msg = append $msg " prometheus:" }} | ||
{{- $msg = append $msg (printf " username: %s" $destinationUsername) }} | ||
{{- fail (join "\n" $msg) }} | ||
{{- end }} | ||
|
||
{{- $destinationPassword := include "secrets.getSecretValue" (dict "object" $destination "key" ".auth.password") }} | ||
{{- if ne $.Values.clusterMetrics.opencost.opencost.prometheus.password_key $destinationPassword}} | ||
{{- $msg := list "" (printf "The password for %s and OpenCost do not match." $destinationName) }} | ||
{{- $msg = append $msg "Please set:" }} | ||
{{- $msg = append $msg "clusterMetrics:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- $msg = append $msg " prometheus:" }} | ||
{{- $msg = append $msg (printf " password: %s" $destinationPassword) }} | ||
{{- fail (join "\n" $msg) }} | ||
{{- end }} | ||
{{- else }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the creds are embedded, there is no secret, so set the username and password directly.
{{- else if ne $authType "none" }} | ||
{{- $msg := list "" (printf "Unable to provide guidance for configuring OpenCost to use %s authentication for %s." $authType $destinationName) }} | ||
{{- $msg = append $msg "Please set:" }} | ||
{{- $msg = append $msg "clusterMetrics:" }} | ||
{{- $msg = append $msg " opencost:" }} | ||
{{- $msg = append $msg " metricsSource: custom" }} | ||
{{- $msg = append $msg ("And configure %s authentication for %s using guidance from the OpenCost Helm chart.") }} | ||
{{- $msg = append $msg "Documentation: https://github.com/opencost/opencost-helm-chart/tree/main/charts/opencost" }} | ||
{{- fail (join "\n" $msg) }} | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're using anything other than none
or basic
, I'm not writing guidance for it. The user can look at the docs and figure it out. That's why we have the metricsSource: custom
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There are a ton of guidance steps for setting the required fields for OpenCost.