Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
switch table colors to reflect risk & efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
pnickolov committed Oct 14, 2021
1 parent f14ccac commit ad8c67e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func analyzeApp(app *appmodel.App) {
} else {
o.Flags[appmodel.F_RESOURCE_SPEC] = false
o.Blockers = append(o.Blockers, msg)
o.Opportunities = append(o.Opportunities, "Define resource levels to improve reliability")
}

// analyze resource utilization
Expand Down
39 changes: 30 additions & 9 deletions cmd/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func getDisplayMethods() map[string]DisplayMethods {
func appOpportunityAndColor(app *appmodel.App) (oppty string, color int) {
// note: color is among tablewriter colors

// handle unqualified apps
if !isQualifiedApp(app) {
color = 0 // keep default color (neutral); alt: tablewriter.FgRedColor
return
}

// list opportunities (usually one but allow for multiple)
if len(app.Analysis.Opportunities) > 0 {
oppty = strings.Join(app.Analysis.Opportunities, "\n")
Expand All @@ -57,7 +51,33 @@ func appOpportunityAndColor(app *appmodel.App) (oppty string, color int) {
}

// choose color depending on rating
if app.Analysis.Rating >= 50 {
if !isQualifiedApp(app) {
color = 0 // keep default color (neutral); alt: tablewriter.FgRedColor
} else if app.Analysis.Rating >= 50 {
color = tablewriter.FgGreenColor
} else {
color = tablewriter.FgYellowColor
}

return
}

func appTableColor(app *appmodel.App) (color int) {
// note: color is among tablewriter colors

var risk appmodel.RiskLevel
if app.Analysis.ReliabilityRisk != nil {
risk = *app.Analysis.ReliabilityRisk
} else {
risk = appmodel.RISK_UNKNOWN
}

// choose color depending on efficiency and risk
if risk == appmodel.RISK_MEDIUM {
color = tablewriter.FgRedColor //tablewriter.FgYellowColor
} else if risk > appmodel.RISK_MEDIUM {
color = tablewriter.FgRedColor
} else if app.Analysis.EfficiencyScore != nil && *app.Analysis.EfficiencyScore >= 60 {
color = tablewriter.FgGreenColor
} else {
color = tablewriter.FgYellowColor
Expand Down Expand Up @@ -120,7 +140,7 @@ func getHeadersInfo() []HeaderInfo {
{"Deployment", LEFT},
{"Efficiency\nScore", RIGHT},
{"Reliability\nRisk", CENTER},
{"Instances", RIGHT},
{"Replicas", RIGHT},
{"CPU", RIGHT},
{"Mem", RIGHT},
{"Opportunity", LEFT},
Expand All @@ -146,7 +166,8 @@ func (table *AppTable) outputTableHeader() {
}

func (table *AppTable) outputTableApp(app *appmodel.App) {
reason, color := appOpportunityAndColor(app)
reason, _ := appOpportunityAndColor(app)
color := appTableColor(app)
rowValues := []string{
app.Metadata.Namespace,
app.Metadata.Workload,
Expand Down

0 comments on commit ad8c67e

Please sign in to comment.