-
Notifications
You must be signed in to change notification settings - Fork 16
Cleanup stale metrics and event subscriptions #889
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -564,6 +564,20 @@ func (r *BMCReconciler) handleEventSubscriptions(ctx context.Context, bmcClient | |
| log.V(1).Info("Handling event subscriptions for BMC", "bmcName", bmcObj.Name, "bmcIP", bmcObj.Status.IP) | ||
| modified := false | ||
|
|
||
| if bmcObj.Status.MetricsReportSubscriptionLink != "" { | ||
| exists, err := bmcClient.GetEventSubscription(ctx, bmcObj.Status.MetricsReportSubscriptionLink) | ||
| if err != nil { | ||
| return false, fmt.Errorf("failed to check metrics report subscription for BMC %s (%s): %w", bmcObj.Name, bmcObj.Status.IP, err) | ||
| } | ||
|
Comment on lines
+569
to
+571
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. How about logging this error e.g. in case we run into a transient error? Otherwise the subscription logic will block the BMC reconciliation. |
||
| if !exists { | ||
| log.Info("Metrics report subscription no longer exists on BMC, clearing stale link", "bmcName", bmcObj.Name, "bmcIP", bmcObj.Status.IP, "link", bmcObj.Status.MetricsReportSubscriptionLink) | ||
| bmcBase := bmcObj.DeepCopy() | ||
| bmcObj.Status.MetricsReportSubscriptionLink = "" | ||
| if err := r.Status().Patch(ctx, bmcObj, client.MergeFrom(bmcBase)); err != nil { | ||
| return false, fmt.Errorf("failed to patch BMC status to clear stale metrics subscription link: %w", err) | ||
| } | ||
|
Comment on lines
+576
to
+578
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. I would just in memory clear the link but not patch the resource as we are doing later anyway. This will reduce the API calls. |
||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if bmcObj.Status.MetricsReportSubscriptionLink == "" { | ||
| link, err := serverevents.SubscribeMetricsReport(ctx, r.EventURL, bmcObj.Name, bmcClient) | ||
| if err != nil { | ||
|
|
@@ -573,10 +587,25 @@ func (r *BMCReconciler) handleEventSubscriptions(ctx context.Context, bmcClient | |
| bmcObj.Status.MetricsReportSubscriptionLink = link | ||
| modified = true | ||
| if err := r.Status().Patch(ctx, bmcObj, client.MergeFrom(bmcBase)); err != nil { | ||
| return false, fmt.Errorf("failed to patch server status with subscription links: %w", err) | ||
| return false, fmt.Errorf("failed to patch BMC status with metrics subscription link: %w", err) | ||
| } | ||
| log.Info("Event subscription established", "bmcName", bmcObj.Name, "bmcIP", bmcObj.Status.IP, "type", "metrics", "link", link) | ||
| } | ||
|
|
||
| if bmcObj.Status.EventsSubscriptionLink != "" { | ||
| exists, err := bmcClient.GetEventSubscription(ctx, bmcObj.Status.EventsSubscriptionLink) | ||
| if err != nil { | ||
| return false, fmt.Errorf("failed to check events subscription for BMC %s (%s): %w", bmcObj.Name, bmcObj.Status.IP, err) | ||
| } | ||
|
Comment on lines
+596
to
+599
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. How about logging this error e.g. in case we run into a transient error? Otherwise the subscription logic will block the BMC reconciliation. |
||
| if !exists { | ||
| log.Info("Events subscription no longer exists on BMC, clearing stale link", "bmcName", bmcObj.Name, "bmcIP", bmcObj.Status.IP, "link", bmcObj.Status.EventsSubscriptionLink) | ||
| bmcBase := bmcObj.DeepCopy() | ||
| bmcObj.Status.EventsSubscriptionLink = "" | ||
| if err := r.Status().Patch(ctx, bmcObj, client.MergeFrom(bmcBase)); err != nil { | ||
| return false, fmt.Errorf("failed to patch BMC status to clear stale events subscription link: %w", err) | ||
| } | ||
|
Comment on lines
+604
to
+606
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. I would just in memory clear the link but not patch the resource as we are doing later anyway. This will reduce the API calls. |
||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if bmcObj.Status.EventsSubscriptionLink == "" { | ||
| link, err := serverevents.SubscribeEvents(ctx, r.EventURL, bmcObj.Name, bmcClient) | ||
| if err != nil { | ||
|
|
@@ -586,7 +615,7 @@ func (r *BMCReconciler) handleEventSubscriptions(ctx context.Context, bmcClient | |
| bmcObj.Status.EventsSubscriptionLink = link | ||
| modified = true | ||
| if err := r.Status().Patch(ctx, bmcObj, client.MergeFrom(bmcBase)); err != nil { | ||
| return false, fmt.Errorf("failed to patch server status with subscription links: %w", err) | ||
| return false, fmt.Errorf("failed to patch BMC status with events subscription link: %w", err) | ||
| } | ||
| log.Info("Event subscription established", "bmcName", bmcObj.Name, "bmcIP", bmcObj.Status.IP, "type", "events", "link", link) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.