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

Add OpenCost to the ClusterMetrics feature #923

Merged
merged 1 commit into from
Nov 19, 2024
Merged

Add OpenCost to the ClusterMetrics feature #923

merged 1 commit into from
Nov 19, 2024

Conversation

petewall
Copy link
Collaborator

@petewall petewall commented Nov 19, 2024

There are a ton of guidance steps for setting the required fields for OpenCost.

@petewall petewall self-assigned this Nov 19, 2024
@petewall petewall requested a review from a team as a code owner November 19, 2024 01:34
@petewall petewall linked an issue Nov 19, 2024 that may be closed by this pull request
@petewall petewall force-pushed the feat/v2-cost branch 2 times, most recently from c5af60a to 2042f40 Compare November 19, 2024 01:48
Signed-off-by: Pete Wall <pete.wall@grafana.com>
Copy link
Collaborator Author

@petewall petewall left a 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.

Comment on lines +38 to +47
{{- 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 -}}
Copy link
Collaborator Author

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" }}
Copy link
Collaborator Author

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.

Comment on lines +50 to +62
{{- 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 -}}
Copy link
Collaborator Author

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.

Comment on lines +71 to +79
{{- 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 }}
Copy link
Collaborator Author

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.

Comment on lines +96 to +120
{{- 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 }}
Copy link
Collaborator Author

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.

Comment on lines +157 to +166
{{- 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 }}
Copy link
Collaborator Author

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.

Copy link
Member

@skl skl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@petewall petewall merged commit 7f7241a into main Nov 19, 2024
25 checks passed
@petewall petewall deleted the feat/v2-cost branch November 19, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2.0: Add cost feature
2 participants