From a0b957898e8645c6e9178ea0ddeb539f08b7dc00 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 26 Jul 2023 11:23:25 +0200 Subject: [PATCH] Do not show sync errors longer than 7 days ago. (#201) --- cmd/switch_test.go | 14 +++++++------- cmd/tableprinters/switch.go | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/switch_test.go b/cmd/switch_test.go index 9b76baa..71edeae 100644 --- a/cmd/switch_test.go +++ b/cmd/switch_test.go @@ -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(` @@ -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(` @@ -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(` diff --git a/cmd/tableprinters/switch.go b/cmd/tableprinters/switch.go index c695d9e..d90ee98 100644 --- a/cmd/tableprinters/switch.go +++ b/cmd/tableprinters/switch.go @@ -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" ) @@ -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 { @@ -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 @@ -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 {