From 08815b2f67f9fe8b13d17b35b36bc58344d5829c Mon Sep 17 00:00:00 2001 From: Bernard Kim Date: Fri, 21 Jun 2024 16:52:54 -0700 Subject: [PATCH 1/4] List alert ttl --- tool/tctl/common/alert_command.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tool/tctl/common/alert_command.go b/tool/tctl/common/alert_command.go index 163ca10569ae1..21c4d4e85ceeb 100644 --- a/tool/tctl/common/alert_command.go +++ b/tool/tctl/common/alert_command.go @@ -205,7 +205,7 @@ func (c *AlertCommand) List(ctx context.Context, client *authclient.Client) erro func displayAlertsText(alerts []types.ClusterAlert, verbose bool) { if verbose { - table := asciitable.MakeTable([]string{"ID", "Severity", "Message", "Created", "Labels"}) + table := asciitable.MakeTable([]string{"ID", "Severity", "TTL", "Message", "Created", "Labels"}) for _, alert := range alerts { var labelPairs []string for key, val := range alert.Metadata.Labels { @@ -216,6 +216,7 @@ func displayAlertsText(alerts []types.ClusterAlert, verbose bool) { table.AddRow([]string{ alert.GetName(), alert.Spec.Severity.String(), + calculateTTL(alert.GetMetadata().Expires).String(), fmt.Sprintf("%q", alert.Spec.Message), alert.Spec.Created.Format(time.RFC822), strings.Join(labelPairs, ", "), @@ -223,14 +224,32 @@ func displayAlertsText(alerts []types.ClusterAlert, verbose bool) { } fmt.Println(table.AsBuffer().String()) } else { - table := asciitable.MakeTable([]string{"ID", "Severity", "Message"}) + table := asciitable.MakeTable([]string{"ID", "Severity", "TTL", "Message"}) for _, alert := range alerts { - table.AddRow([]string{alert.GetName(), alert.Spec.Severity.String(), fmt.Sprintf("%q", alert.Spec.Message)}) + table.AddRow([]string{ + alert.GetName(), + alert.Spec.Severity.String(), + calculateTTL(alert.GetMetadata().Expires).String(), + fmt.Sprintf("%q", alert.Spec.Message), + }) } fmt.Println(table.AsBuffer().String()) } } +// calculateTTL returns the remaining TTL of the alert. +func calculateTTL(expiration *time.Time) time.Duration { + if expiration == nil { + return time.Duration(0) + } + remainingDuration := time.Until(*expiration) + if remainingDuration < 0 { + return time.Duration(0) + } + + return remainingDuration.Round(time.Minute) +} + func displayAlertsJSON(alerts []types.ClusterAlert) error { out, err := json.MarshalIndent(alerts, "", " ") if err != nil { From f15052ec1bdc304aeb5a7efad9e843c37c04c5d8 Mon Sep 17 00:00:00 2001 From: Bernard Kim Date: Mon, 24 Jun 2024 10:16:05 -0700 Subject: [PATCH 2/4] TTL -> Expires In --- tool/tctl/common/alert_command.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tool/tctl/common/alert_command.go b/tool/tctl/common/alert_command.go index 21c4d4e85ceeb..30638816b49a5 100644 --- a/tool/tctl/common/alert_command.go +++ b/tool/tctl/common/alert_command.go @@ -205,7 +205,7 @@ func (c *AlertCommand) List(ctx context.Context, client *authclient.Client) erro func displayAlertsText(alerts []types.ClusterAlert, verbose bool) { if verbose { - table := asciitable.MakeTable([]string{"ID", "Severity", "TTL", "Message", "Created", "Labels"}) + table := asciitable.MakeTable([]string{"ID", "Severity", "Expires In", "Message", "Created", "Labels"}) for _, alert := range alerts { var labelPairs []string for key, val := range alert.Metadata.Labels { @@ -224,7 +224,7 @@ func displayAlertsText(alerts []types.ClusterAlert, verbose bool) { } fmt.Println(table.AsBuffer().String()) } else { - table := asciitable.MakeTable([]string{"ID", "Severity", "TTL", "Message"}) + table := asciitable.MakeTable([]string{"ID", "Severity", "Expires In", "Message"}) for _, alert := range alerts { table.AddRow([]string{ alert.GetName(), From 7c82e90b4e0d2f1934b9373f8b6e5266b6bf2c88 Mon Sep 17 00:00:00 2001 From: Bernard Kim Date: Mon, 24 Jun 2024 10:17:16 -0700 Subject: [PATCH 3/4] Add usage docs --- docs/pages/reference/cli/tctl.mdx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/pages/reference/cli/tctl.mdx b/docs/pages/reference/cli/tctl.mdx index e0bdd3823f7c0..d9cc41e5afdb8 100644 --- a/docs/pages/reference/cli/tctl.mdx +++ b/docs/pages/reference/cli/tctl.mdx @@ -242,6 +242,15 @@ Lists cluster alerts. This command can also be invoked as `tctl alerts ls`. | `--verbose` (`-v`) | false |boolean | If set, display detailed alert info (including acknowledged alerts) | | `--labels` | none | Comma-separated strings | A list of labels to filter by | +### Examples + +```code +$ tctl alerts list +ID Severity TTL Message +------------------------------------ -------- ------ ---------------------------------------------------------------- +da36b401-5688-426f-95b8-d0dd1ef27785 LOW 1h0m0s "The system is under maintenance, functionality may be limited." +``` + ## tctl auth export Exports public cluster CA certificates. This is useful for configuring From 593fae7cb430c0984c0e1cee29043f7bbe488428 Mon Sep 17 00:00:00 2001 From: Bernard Kim Date: Mon, 24 Jun 2024 10:19:03 -0700 Subject: [PATCH 4/4] TTL -> Expires In --- docs/pages/reference/cli/tctl.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/pages/reference/cli/tctl.mdx b/docs/pages/reference/cli/tctl.mdx index d9cc41e5afdb8..e562c81818624 100644 --- a/docs/pages/reference/cli/tctl.mdx +++ b/docs/pages/reference/cli/tctl.mdx @@ -246,9 +246,9 @@ Lists cluster alerts. This command can also be invoked as `tctl alerts ls`. ```code $ tctl alerts list -ID Severity TTL Message ------------------------------------- -------- ------ ---------------------------------------------------------------- -da36b401-5688-426f-95b8-d0dd1ef27785 LOW 1h0m0s "The system is under maintenance, functionality may be limited." +ID Severity Expires In Message +------------------------------------ -------- ---------- ---------------------------------------------------------------- +da36b401-5688-426f-95b8-d0dd1ef27785 LOW 57m0s "The system is under maintenance, functionality may be limited." ``` ## tctl auth export