From 6a5938f69f81da2becacbc10e3e8224e9a2dd2b7 Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Fri, 27 Sep 2024 19:20:11 +0200 Subject: [PATCH] fix(upgradeinsights): calculate upgrade insight status based on client stats (#287) * calculate upgrade insight status based on client stats * nit: change duration var name * use the same base for comparison * fix lint --- internal/controller/upgradeinsights_cloudprovider.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/controller/upgradeinsights_cloudprovider.go b/internal/controller/upgradeinsights_cloudprovider.go index 76c964aa..b4db4f68 100644 --- a/internal/controller/upgradeinsights_cloudprovider.go +++ b/internal/controller/upgradeinsights_cloudprovider.go @@ -125,6 +125,17 @@ func (in *EKSCloudProvider) fromInsightStatus(status *types.InsightStatus) *cons return nil } +func (in *EKSCloudProvider) fromClientStats(stats []types.ClientStat) *console.UpgradeInsightStatus { + const failedBeforeDuration = 24.0 // in hours + for _, stat := range stats { + if stat.LastRequestTime != nil && time.Since(*stat.LastRequestTime).Hours() < failedBeforeDuration { + return lo.ToPtr(console.UpgradeInsightStatusFailed) + } + } + + return lo.ToPtr(console.UpgradeInsightStatusPassing) +} + func (in *EKSCloudProvider) toInsightDetails(insight *types.Insight) []*console.UpgradeInsightDetailAttributes { if insight.CategorySpecificSummary == nil { return nil @@ -137,6 +148,7 @@ func (in *EKSCloudProvider) toInsightDetails(insight *types.Insight) []*console. Replacement: r.ReplacedWith, ReplacedIn: r.StartServingReplacementVersion, RemovedIn: r.StopServingVersion, + Status: in.fromClientStats(r.ClientStats), }) }