-
Notifications
You must be signed in to change notification settings - Fork 164
helm/metrics: add a new gauge metric to monitor helm releases #579
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ import ( | |
| "github.com/openshift/library-go/pkg/route/routeapihelpers" | ||
|
|
||
| // operator | ||
| helmmetrics "github.com/openshift/console-operator/pkg/helm/metrics" | ||
|
|
||
| customerrors "github.com/openshift/console-operator/pkg/console/errors" | ||
| "github.com/openshift/console-operator/pkg/console/metrics" | ||
| "github.com/openshift/console-operator/pkg/console/status" | ||
|
|
@@ -218,6 +220,7 @@ func (co *consoleOperator) GetActiveRouteInfo(ctx context.Context, activeRouteNa | |
| func (co *consoleOperator) SyncConsoleConfig(ctx context.Context, consoleConfig *configv1.Console, consoleURL string) (*configv1.Console, error) { | ||
| oldURL := consoleConfig.Status.ConsoleURL | ||
| metrics.HandleConsoleURL(oldURL, consoleURL) | ||
| helmmetrics.HandleHelmChartReleaseHealthStatus() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we call the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, will move it to the main |
||
| if oldURL != consoleURL { | ||
| klog.V(4).Infof("updating console.config.openshift.io with url: %v", consoleURL) | ||
| updated := consoleConfig.DeepCopy() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||
| package metrics | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets put this into the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||||||
|
|
||||||
| import ( | ||||||
| "log" | ||||||
| "os" | ||||||
|
|
||||||
| "helm.sh/helm/v3/pkg/action" | ||||||
| "k8s.io/cli-runtime/pkg/genericclioptions" | ||||||
| "k8s.io/client-go/rest" | ||||||
| k8smetrics "k8s.io/component-base/metrics" | ||||||
| "k8s.io/component-base/metrics/legacyregistry" | ||||||
| "k8s.io/klog/v2" | ||||||
| ) | ||||||
|
|
||||||
| var ( | ||||||
| helmChartReleaseHealthStatus = k8smetrics.NewGaugeVec( | ||||||
| &k8smetrics.GaugeOpts{ | ||||||
| Name: "helm_chart_release_health_status", | ||||||
| Help: "Health of the Helm release", | ||||||
| }, | ||||||
| []string{"releaseName", "chartName", "chartVersion"}, | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| func init() { | ||||||
| legacyregistry.MustRegister(helmChartReleaseHealthStatus) | ||||||
| } | ||||||
|
|
||||||
| func HandleHelmChartReleaseHealthStatus() { | ||||||
| defer recoverMetricPanic() | ||||||
|
|
||||||
| if actionConfig, err := getActionConfig(); err != nil { | ||||||
| klog.Errorf("metric helm_chart_release_health_status unhandled: %v", err) | ||||||
| return | ||||||
| } else { | ||||||
| listAction := action.NewList(actionConfig) | ||||||
| releases, err := listAction.Run() | ||||||
| if err != nil { | ||||||
| klog.Errorf("metric helm_chart_release_health_status unhandled: %v", err) | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| for _, release := range releases { | ||||||
| if status := release.Info.Status.String(); status == "deployed" { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So only deploy is healthy, what about the other states. I would say if it is unknown or failed then is 0 then is 1 for all other states
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||
| klog.V(4).Infof("metric helm_chart_release_health_status 1: %s %s %s", release.Name, release.Chart.Metadata.Name, release.Chart.Metadata.Version) | ||||||
| helmChartReleaseHealthStatus.WithLabelValues(release.Name, release.Chart.Metadata.Name, release.Chart.Metadata.Version).Set(1) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the only diff between this and the line below is the 0 or 1. I would do healthStatus := 1 then change to 0 if status unknown or failed. Then make a single call to klog and to helmChartReleaseHealthStatus passing healthStatus
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||
| } else { | ||||||
| klog.V(4).Infof("metric helm_chart_release_health_status 0: %s %s %s", release.Name, release.Chart.Metadata.Name, release.Chart.Metadata.Version) | ||||||
| helmChartReleaseHealthStatus.WithLabelValues(release.Name, release.Chart.Metadata.Name, release.Chart.Metadata.Version).Set(0) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Reference: https://github.com/helm/helm/issues/7430#issuecomment-620489002 | ||||||
| func getActionConfig() (*action.Configuration, error) { | ||||||
| actionConfig := new(action.Configuration) | ||||||
| var kubeConfig *genericclioptions.ConfigFlags | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont think kubeconfig is the right name
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also why do we need to initialize the configFlags, since on line in 72 you are setting it ? cant we jusst set it directly ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated :) |
||||||
| // Create the rest config instance with ServiceAccount values loaded in them | ||||||
| config, err := rest.InClusterConfig() | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| // Create the ConfigFlags struct instance with initialized values from ServiceAccount | ||||||
| kubeConfig = genericclioptions.NewConfigFlags(false) | ||||||
| kubeConfig.APIServer = &config.Host | ||||||
| kubeConfig.BearerToken = &config.BearerToken | ||||||
| kubeConfig.CAFile = &config.CAFile | ||||||
| // Empty string for all namespaces | ||||||
| if err := actionConfig.Init(kubeConfig, "", os.Getenv("HELM_DRIVER"), log.Printf); err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| return actionConfig, nil | ||||||
| } | ||||||
|
|
||||||
| // We will never want to panic our operator because of metric saving. | ||||||
| // Therefore, we will recover our panics here and error log them | ||||||
| // for later diagnosis but will never fail the operator. | ||||||
| func recoverMetricPanic() { | ||||||
| if r := recover(); r != nil { | ||||||
| klog.Errorf("Recovering from metric function - %v", r) | ||||||
| } | ||||||
| } | ||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 required to run
helm list --all-namespaceswith Helm SDK.Error without it:
metric helm_chart_release_health_status unhandled: list: failed to list: secrets is forbidden: User "system:serviceaccount:openshift-console-operator:console-operator" cannot list resource "secrets" in API group "" at the cluster scope