Skip to content

Conversation

@hsmatulis
Copy link
Contributor

Clear EndPointStatuses when PodMonitoring does not have an endpoint.

This fixes a bug where PodMonitorings without any endpoints have a stale list of endpoints.

@hsmatulis hsmatulis requested a review from pintohutch December 3, 2024 23:04
@hsmatulis hsmatulis force-pushed the hmatulis-target-status-dropping branch 2 times, most recently from a76eb6e to 6134c5e Compare December 3, 2024 23:08
@hsmatulis
Copy link
Contributor Author

Note that this PR also fixes a misconfigured test that was silently failing (#1097 adds support for a nodepool format with caadvisor)

@hsmatulis hsmatulis force-pushed the hmatulis-target-status-dropping branch from 6134c5e to 59c0c2e Compare December 4, 2024 15:53
Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Nice! This is great and definitely one way of doing this.

I wonder if it wouldn't be better to do this on reconcile PodMonitoring loop - because the moment PodMonitoring changes, it triggers reconcile so we could automatically clear the status there. This would avoid extra API calls essentially

Actually I think I misunderstood the intention. I thought you are solving case of empty endpoint field. I think it's about no target situation (e.g. pods not selected). Let me re-review.

podMonitorings, err := getPodMonitoringCRDs(ctx, kubeClient)
if err != nil {
return err
} else if len(podMonitorings) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
} else if len(podMonitorings) == 0 {
}
if len(podMonitorings) == 0 {

}
}

// Any pod monitorings that exist but dont have endpoints should also be updated
Copy link
Collaborator

@bwplotka bwplotka Dec 4, 2024

Choose a reason for hiding this comment

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

Suggested change
// Any pod monitorings that exist but dont have endpoints should also be updated
// Any pod monitorings that exist but don't have endpoints should also be updated.

Comment on lines 355 to 356
_, exists := hasEndpoints[pm.GetName()]
if !exists {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
_, exists := hasEndpoints[pm.GetName()]
if !exists {
if _, exists := hasEndpoints[pm.GetName()]; !exists {

if !exists {
pm.GetPodMonitoringStatus().EndpointStatuses = []monitoringv1.ScrapeEndpointStatus{}
if err := patchPodMonitoringStatus(ctx, kubeClient, pm, pm.GetPodMonitoringStatus()); err != nil {
// Same reasoning as above for error handling
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Same reasoning as above for error handling
// Same reasoning as above for error handling.

Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

LGTM, some ideas for a bit more efficiency and readable, otherwise LGTM, thanks!

@hsmatulis hsmatulis force-pushed the hmatulis-target-status-dropping branch from 59c0c2e to 35d70b2 Compare December 16, 2024 22:37
@hsmatulis hsmatulis force-pushed the hmatulis-target-status-dropping branch from 35d70b2 to a342d9b Compare December 16, 2024 22:41
@hsmatulis hsmatulis merged commit 903f7ec into main Dec 17, 2024
27 checks passed
@hsmatulis hsmatulis deleted the hmatulis-target-status-dropping branch December 17, 2024 19:29
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.

3 participants