Skip to content

Commit

Permalink
Show red dot when switch sync errors are currently happening. (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Aug 1, 2023
1 parent a0b9578 commit 663fde7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 8 additions & 8 deletions cmd/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func Test_SwitchCmd_MultiResult(t *testing.T) {
},
wantTable: pointer.Pointer(`
ID PARTITION RACK OS STATUS
1 1 rack-1 πŸ¦”  ●
2 1 rack-1 🐒  ●
1 1 rack-1 πŸ¦” ●
2 1 rack-1 🐒 ●
`),
wantWideTable: pointer.Pointer(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
Expand All @@ -157,8 +157,8 @@ ID PARTITION RACK OS METALCORE IP MODE LAST
wantMarkdown: pointer.Pointer(`
| ID | PARTITION | RACK | OS | STATUS |
|----|-----------|--------|----|--------|
| 1 | 1 | rack-1 | πŸ¦” |  ● |
| 2 | 1 | rack-1 | 🐒 |  ● |
| 1 | 1 | rack-1 | πŸ¦” | ● |
| 2 | 1 | rack-1 | 🐒 | ● |
`),
},
{
Expand Down Expand Up @@ -189,7 +189,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST
},
wantTable: pointer.Pointer(`
ID PARTITION RACK OS STATUS
1 1 rack-1 πŸ¦”  ●
1 1 rack-1 πŸ¦” ●
`),
wantWideTable: pointer.Pointer(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
Expand All @@ -202,7 +202,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST S
wantMarkdown: pointer.Pointer(`
| ID | PARTITION | RACK | OS | STATUS |
|----|-----------|--------|----|--------|
| 1 | 1 | rack-1 | πŸ¦” |  ● |
| 1 | 1 | rack-1 | πŸ¦” | ● |
`),
},
{
Expand Down Expand Up @@ -353,7 +353,7 @@ func Test_SwitchCmd_SingleResult(t *testing.T) {
want: switch1,
wantTable: pointer.Pointer(`
ID PARTITION RACK OS STATUS
1 1 rack-1 πŸ¦”  ●
1 1 rack-1 πŸ¦” ●
`),
wantWideTable: pointer.Pointer(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
Expand All @@ -366,7 +366,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST S
wantMarkdown: pointer.Pointer(`
| ID | PARTITION | RACK | OS | STATUS |
|----|-----------|--------|----|--------|
| 1 | 1 | rack-1 | πŸ¦” |  ● |
| 1 | 1 | rack-1 | πŸ¦” | ● |
`),
},
{
Expand Down
10 changes: 7 additions & 3 deletions cmd/tableprinters/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (t *TablePrinter) SwitchTable(data []*models.V1SwitchResponse, wide bool) (
syncAge := time.Since(syncTime)
syncDur := time.Duration(*s.LastSync.Duration).Round(time.Millisecond)
if syncAge >= time.Minute*10 || syncDur >= 30*time.Second {
shortStatus += color.RedString(dot)
shortStatus = color.RedString(dot)
} else if syncAge >= time.Minute*1 || syncDur >= 20*time.Second {
shortStatus += color.YellowString(dot)
shortStatus = color.YellowString(dot)
} else {
shortStatus += color.GreenString(dot)
shortStatus = color.GreenString(dot)
}

syncAgeStr = humanizeDuration(syncAge)
Expand All @@ -60,6 +60,10 @@ func (t *TablePrinter) SwitchTable(data []*models.V1SwitchResponse, wide bool) (
// after 7 days we do not show sync errors anymore
if !errorTime.IsZero() && time.Since(errorTime) < 7*24*time.Hour {
syncError = fmt.Sprintf("%s ago: %s", humanizeDuration(time.Since(errorTime)), s.LastSyncError.Error)

if errorTime.After(time.Time(pointer.SafeDeref(s.LastSync.Time))) {
shortStatus = color.RedString(dot)
}
}
}

Expand Down

0 comments on commit 663fde7

Please sign in to comment.