Skip to content

fix: remove metric series of deleted profiles and ClusterSummaries - #2031

Open
Kitio-Tek wants to merge 1 commit into
projectsveltos:mainfrom
Kitio-Tek:remove-stale-metric-series
Open

Kitio-Tek wants to merge 1 commit into
projectsveltos:mainfrom
Kitio-Tek:remove-stale-metric-series

Conversation

@Kitio-Tek

Copy link
Copy Markdown

Fixes #2029

The series labeled by profile and by ClusterSummary are only ever set or incremented, so they outlive the objects they describe. After a ClusterProfile is deleted, projectsveltos_matching_clusters keeps its last count. A deleted ClusterSummary keeps its reconcile_consecutive_failures and reconcile_last_success_timestamp_seconds, and when its cluster is gone the undeploy is skipped, so a feature that was failing keeps reporting failures that never clear.

This adds clearMatchingClusters and clearClusterSummaryMetrics to metrics.go:

  • The ClusterProfile and Profile reconcilers call clearMatchingClusters once reconcileDeleteCommon succeeded, next to cleanMaps. It is the counterpart of the trackMatchingClusters call in reconcileNormal.
  • postFinalizerCleanup calls clearClusterSummaryMetrics, so it runs once the finalizer is removed. The undeploy records a last Removed outcome before that, and a ClusterSummary whose deletion is blocked (cluster paused or not ready) keeps its series.

clearClusterSummaryMetrics gets the profile labels from getProfileLabels, like the recording side, and calls DeletePartialMatch without the feature and status labels, so every feature and both outcomes go. The match includes the cluster labels, which keeps the series of the same profile on other clusters and of other profiles on the same cluster. DeletePartialMatch walks every series of the metric, but only on a delete.

I left reconcile_duration_seconds and reconcile_operations_total alone. They are not labeled by profile and are shared by all the ClusterSummaries of a cluster, so they would have to go with the cluster, and an undeploy still running when the cluster goes could record them again. @gianlucam76 do you want them removed too, in a follow-up? I also didn't touch the shard handover: when a ClusterSummary moves to another shard, the old shard's addon-controller keeps its series. outdated_helm_chart is left to its checker, which has its own gap: #2030.

Tests, next to the existing reconcileDelete specs:

  • A ClusterSummary's series are gone from all four metrics once its finalizer is removed, while those of a Profile with the same name on the same cluster, and of the same ClusterProfile on another cluster, stay.
  • A ClusterSummary whose finalizer cannot be removed (cluster present but not ready) keeps its series.
  • The matching_clusters series of a ClusterProfile, and of a Profile, is gone once the finalizer is removed, while the series of the other kind with the same name, and of a Profile with the same name in another namespace, stay.

The three removal specs fail on main and pass here. make test and make lint pass. On kind, make fv and make new-fv pass, and so does make fv-agentless on a fresh cluster. With the reproduction steps from the issue, /metrics has no series left for the deleted profiles and ClusterSummaries. Only reconcile_duration_seconds and reconcile_operations_total of the deleted SveltosCluster remain, as said above.

Nothing changes while the objects exist: same metrics, labels and values.

The series labeled by profile and by ClusterSummary are only ever set or
incremented, so they outlive the objects they describe. After a delete,
matching_clusters keeps the last count of the profile, and
reconcile_consecutive_failures and
reconcile_last_success_timestamp_seconds keep the last value of the
ClusterSummary until the addon-controller restarts. When a cluster is
deleted the undeploy is skipped, so a failing feature keeps reporting
its failures.

Remove the matching_clusters series of a ClusterProfile/Profile once
its finalizer is removed, and the series of a ClusterSummary in
postFinalizerCleanup, after the undeploy recorded its last outcome.
reconcile_duration_seconds and reconcile_operations_total are shared by
all the ClusterSummaries of a cluster and are left alone.
@Kitio-Tek

Copy link
Copy Markdown
Author

@gianlucam76 could you review this when you have a moment? It does for ClusterProfiles, Profiles and ClusterSummaries what deleteClusterMetrics from projectsveltos/sveltoscluster-manager#372 does for a deleted SveltosCluster.

@gianlucam76

Copy link
Copy Markdown
Member

Thank you @Kitio-Tek

Will review it tomorrow morning. thank you again for pushing this!

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.

BUG: metrics keep reporting deleted ClusterProfiles, Profiles and ClusterSummaries

2 participants