Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ const (

const (
// TimeoutGetClusterAlerts is the timeout for grabbing cluster alerts from tctl and tsh
TimeoutGetClusterAlerts = time.Millisecond * 500
TimeoutGetClusterAlerts = time.Millisecond * 750
)

const (
Expand Down
5 changes: 1 addition & 4 deletions tool/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ type ClusterAlertGetter interface {
// ShowClusterAlerts shows cluster alerts with the given labels and severity.
func ShowClusterAlerts(ctx context.Context, client ClusterAlertGetter, w io.Writer, labels map[string]string, minSeverity, maxSeverity types.AlertSeverity) error {
// get any "on login" alerts
alertCtx, cancelAlertCtx := context.WithTimeout(ctx, constants.TimeoutGetClusterAlerts)
defer cancelAlertCtx()

alerts, err := client.GetClusterAlerts(alertCtx, types.GetClusterAlertsRequest{
alerts, err := client.GetClusterAlerts(ctx, types.GetClusterAlertsRequest{
Labels: labels,
Severity: minSeverity,
})
Expand Down
3 changes: 3 additions & 0 deletions tool/tctl/common/tctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/breaker"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/auth/authclient"
Expand Down Expand Up @@ -215,6 +216,8 @@ func TryRun(commands []CLICommand, args []string) error {
}
}

ctx, cancel := context.WithTimeout(ctx, constants.TimeoutGetClusterAlerts)
defer cancel()
if err := common.ShowClusterAlerts(ctx, client, os.Stderr, nil,
types.AlertSeverity_HIGH, types.AlertSeverity_HIGH); err != nil {
log.WithError(err).Warn("Failed to display cluster alerts.")
Expand Down
7 changes: 7 additions & 0 deletions tool/tsh/tsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,13 @@ func Run(ctx context.Context, args []string, opts ...cliOption) error {
case show.FullCommand():
err = onShow(&cf)
case status.FullCommand():
// onStatus can be invoked directly with `tsh status` but is also
// invoked from other commands. When invoked directly, we use a
// context with a short timeout to prevent the command from taking
// too long due to fetching alerts on slow networks.
var cancel context.CancelFunc
cf.Context, cancel = context.WithTimeout(cf.Context, constants.TimeoutGetClusterAlerts)
defer cancel()
err = onStatus(&cf)
case lsApps.FullCommand():
err = onApps(&cf)
Expand Down