Skip to content

Commit

Permalink
feat(upgradeinsights): add support for warning status (#296)
Browse files Browse the repository at this point in the history
* feat(upgradeinsights): add support for warning status

* fix lint
  • Loading branch information
floreks authored Oct 4, 2024
1 parent 04a4274 commit e5b2955
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/open-policy-agent/gatekeeper/v3 v3.17.1
github.com/orcaman/concurrent-map/v2 v2.0.1
github.com/pkg/errors v0.9.1
github.com/pluralsh/console/go/client v1.19.0
github.com/pluralsh/console/go/client v1.20.0
github.com/pluralsh/controller-reconcile-helper v0.1.0
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
github.com/pluralsh/polly v0.1.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rK
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pluralsh/console/go/client v1.19.0 h1:x5JQWYtxr5S/PVUJS4Jiiir2IYAqMruONXydu9NSliM=
github.com/pluralsh/console/go/client v1.19.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
github.com/pluralsh/console/go/client v1.20.0 h1:XZ9GcNAcEXRXtcyHZdA1dpi/GovMdHbC+obJgD+RnzE=
github.com/pluralsh/console/go/client v1.20.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
github.com/pluralsh/controller-reconcile-helper v0.1.0 h1:BV3dYZFH5rn8ZvZjtpkACSv/GmLEtRftNQj/Y4ddHEo=
github.com/pluralsh/controller-reconcile-helper v0.1.0/go.mod h1:RxAbvSB4/jkvx616krCdNQXPbpGJXW3J1L3rASxeFOA=
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw=
Expand Down
15 changes: 11 additions & 4 deletions internal/controller/upgradeinsights_cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (in *EKSCloudProvider) UpgradeInsights(ctx context.Context, ui v1alpha1.Upg
return nil, err
}

insights, err := in.listInsights(ctx, client, ui)
insights, err := in.listInsights(ctx, client)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -63,7 +63,7 @@ func (in *EKSCloudProvider) UpgradeInsights(ctx context.Context, ui v1alpha1.Upg
}), nil
}

func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client, ui v1alpha1.UpgradeInsights) ([]*types.Insight, error) {
func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client) ([]*types.Insight, error) {
logger := log.FromContext(ctx)
var result []types.InsightSummary

Expand Down Expand Up @@ -116,8 +116,9 @@ func (in *EKSCloudProvider) fromInsightStatus(status *types.InsightStatus) *cons
case types.InsightStatusValuePassing:
return lo.ToPtr(console.UpgradeInsightStatusPassing)
case types.InsightStatusValueError:
case types.InsightStatusValueWarning:
return lo.ToPtr(console.UpgradeInsightStatusFailed)
case types.InsightStatusValueWarning:
return lo.ToPtr(console.UpgradeInsightStatusWarning)
case types.InsightStatusValueUnknown:
return lo.ToPtr(console.UpgradeInsightStatusUnknown)
}
Expand All @@ -126,11 +127,17 @@ func (in *EKSCloudProvider) fromInsightStatus(status *types.InsightStatus) *cons
}

func (in *EKSCloudProvider) fromClientStats(stats []types.ClientStat) *console.UpgradeInsightStatus {
const failedBeforeDuration = 24.0 // in hours
const failedBeforeDuration = 24.0 // 24 hours
const warningBeforeDuration = 24.0 * 30 // 30 days

for _, stat := range stats {
if stat.LastRequestTime != nil && time.Since(*stat.LastRequestTime).Hours() < failedBeforeDuration {
return lo.ToPtr(console.UpgradeInsightStatusFailed)
}

if stat.LastRequestTime != nil && time.Since(*stat.LastRequestTime).Hours() < warningBeforeDuration {
return lo.ToPtr(console.UpgradeInsightStatusWarning)
}
}

return lo.ToPtr(console.UpgradeInsightStatusPassing)
Expand Down

0 comments on commit e5b2955

Please sign in to comment.