Skip to content

Commit

Permalink
Do not show sync errors longer than 7 days ago. (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Jul 26, 2023
1 parent ae20485 commit a0b9578
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
14 changes: 7 additions & 7 deletions cmd/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ ID PARTITION RACK OS STATUS
2 1 rack-1 🐢  ●
`),
wantWideTable: pointer.Pointer(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
1 1 rack-1 SONiC/1 1.2.3 1.2.3.4 operational 0s 1s 5m ago: error
2 1 rack-1 Cumulus/2 operational 0s 1s 5m ago: error
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
1 1 rack-1 SONiC (1) 1.2.3 1.2.3.4 operational 0s 1s 5m ago: error
2 1 rack-1 Cumulus (2) operational 0s 1s 5m ago: error
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
Expand Down Expand Up @@ -192,8 +192,8 @@ ID PARTITION RACK OS STATUS
1 1 rack-1 🦔  ●
`),
wantWideTable: pointer.Pointer(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
1 1 rack-1 SONiC/1 1.2.3 1.2.3.4 operational 0s 1s 5m ago: error
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
1 1 rack-1 SONiC (1) 1.2.3 1.2.3.4 operational 0s 1s 5m ago: error
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
Expand Down Expand Up @@ -356,8 +356,8 @@ ID PARTITION RACK OS STATUS
1 1 rack-1 🦔  ●
`),
wantWideTable: pointer.Pointer(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
1 1 rack-1 SONiC/1 1.2.3 1.2.3.4 operational 0s 1s 5m ago: error
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST SYNC ERROR
1 1 rack-1 SONiC (1) 1.2.3 1.2.3.4 operational 0s 1s 5m ago: error
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
Expand Down
15 changes: 12 additions & 3 deletions cmd/tableprinters/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/fatih/color"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/olekukonko/tablewriter"
"github.com/spf13/viper"
)

Expand All @@ -22,6 +23,10 @@ func (t *TablePrinter) SwitchTable(data []*models.V1SwitchResponse, wide bool) (
header := []string{"ID", "Partition", "Rack", "OS", "Status"}
if wide {
header = []string{"ID", "Partition", "Rack", "OS", "MetalCore", "IP", "Mode", "Last Sync", "Sync Duration", "Last Sync Error"}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
}

for _, s := range data {
Expand Down Expand Up @@ -52,7 +57,10 @@ func (t *TablePrinter) SwitchTable(data []*models.V1SwitchResponse, wide bool) (

if s.LastSyncError != nil {
errorTime := time.Time(*s.LastSyncError.Time)
syncError = fmt.Sprintf("%s ago: %s", humanizeDuration(time.Since(errorTime)), s.LastSyncError.Error)
// 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)
}
}

var mode string
Expand All @@ -79,9 +87,10 @@ func (t *TablePrinter) SwitchTable(data []*models.V1SwitchResponse, wide bool) (

os = s.Os.Vendor
if s.Os.Version != "" {
os = os + "/" + s.Os.Version
os = fmt.Sprintf("%s (%s)", os, s.Os.Version)
}
metalCore = s.Os.MetalCoreVersion
// metal core version is very long: v0.9.1 (1d5e42ea), tags/v0.9.1-0-g1d5e42e, go1.20.5
metalCore = strings.Split(s.Os.MetalCoreVersion, ",")[0]
}

if wide {
Expand Down

0 comments on commit a0b9578

Please sign in to comment.