From 1a771e55dc637775a819db71d45f5c536600939c Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Thu, 15 Jul 2021 16:54:59 -0500 Subject: [PATCH 1/2] Suppress logging during a diagnose run (#12101) * Suppress logging during a diagnose run * remove debugging --- command/operator_diagnose.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/command/operator_diagnose.go b/command/operator_diagnose.go index 16884263f4bd8..6ca59bbc8f2b1 100644 --- a/command/operator_diagnose.go +++ b/command/operator_diagnose.go @@ -217,7 +217,9 @@ func (c *OperatorDiagnoseCommand) offlineDiagnostics(ctx context.Context) error // TODO: other ServerCommand options? - logger: log.NewInterceptLogger(nil), + logger: log.NewInterceptLogger(&log.LoggerOptions{ + Level: log.Off, + }), allLoggers: []log.Logger{}, reloadFuncs: &rloadFuncs, reloadFuncsLock: new(sync.RWMutex), From 33237008caaf861201f31737b56f061eb654a61b Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Thu, 15 Jul 2021 18:01:51 -0500 Subject: [PATCH 2/2] Add advice as a trace option to spot checks (#12105) * Add advice as a trace option to spot checks * typo * Collect advice when forming the tree --- command/operator_diagnose.go | 4 ++-- vault/diagnose/os_common.go | 8 ++++---- vault/diagnose/os_unix.go | 4 ++-- vault/diagnose/output.go | 13 +++++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/command/operator_diagnose.go b/command/operator_diagnose.go index 6ca59bbc8f2b1..bfba8afd49c2b 100644 --- a/command/operator_diagnose.go +++ b/command/operator_diagnose.go @@ -552,8 +552,8 @@ SEALFAIL: err = findClusterAddress(server, &coreConfig, config, disableClustering) if err != nil { - diagnose.Advise(ctx, "Please check that the API and Cluster addresses are different, and that the API, Cluster and Redirect addresses have both a host and port.") - return diagnose.SpotError(ctx, "Check Cluster Address", fmt.Errorf("Cluster Address could not be determined or was invalid: %w.", err)) + return diagnose.SpotError(ctx, "Check Cluster Address", fmt.Errorf("Cluster Address could not be determined or was invalid: %w.", err), + diagnose.Advice("Please check that the API and Cluster addresses are different, and that the API, Cluster and Redirect addresses have both a host and port.")) } diagnose.SpotOk(ctx, "Check Cluster Address", "Cluster address is logically valid and can be found.") diff --git a/vault/diagnose/os_common.go b/vault/diagnose/os_common.go index 292fd7fe536dc..6d4658c006629 100644 --- a/vault/diagnose/os_common.go +++ b/vault/diagnose/os_common.go @@ -31,11 +31,11 @@ partLoop: Warn(ctx, fmt.Sprintf("Could not obtain partition usage for %s: %v.", partition.Mountpoint, err)) } else { if usage.UsedPercent > 95 { - SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %d percent full.", usage.UsedPercent)) - Advise(ctx, "It is recommended to have more than five percent of the partition free.") + SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %d percent full.", usage.UsedPercent), + Advice("It is recommended to have more than five percent of the partition free.")) } else if usage.Free < 2<<30 { - SpotWarn(ctx, testName, partition.Mountpoint+" has %d bytes full.") - Advise(ctx, "It is recommended to have at least 1 GB of space free per partition.") + SpotWarn(ctx, testName, partition.Mountpoint+" has %d bytes full.", + Advice("It is recommended to have at least 1 GB of space free per partition.")) } else { SpotOk(ctx, testName, partition.Mountpoint+" usage ok.") } diff --git a/vault/diagnose/os_unix.go b/vault/diagnose/os_unix.go index 436d611ff127a..904a4ad6434b9 100644 --- a/vault/diagnose/os_unix.go +++ b/vault/diagnose/os_unix.go @@ -24,8 +24,8 @@ func OSChecks(ctx context.Context) { min = limit.Max } if min <= 1024 { - SpotWarn(ctx, fileLimitsName, fmt.Sprintf("Open file limits are set to %d", min)) - Advise(ctx, "These limits may be insufficient. We recommend raising the soft and hard limits to 1024768.") + SpotWarn(ctx, fileLimitsName, fmt.Sprintf("Open file limits are set to %d", min), + Advice("These limits may be insufficient. We recommend raising the soft and hard limits to 1024768.")) } else { SpotOk(ctx, fileLimitsName, fmt.Sprintf("Open file limits are set to %d.", min)) } diff --git a/vault/diagnose/output.go b/vault/diagnose/output.go index 3eca7a066987c..ab789783b0782 100644 --- a/vault/diagnose/output.go +++ b/vault/diagnose/output.go @@ -210,6 +210,7 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result { Status: OkStatus, Message: message, Time: e.Time, + Advice: findAttribute(e, adviceKey), }) } case spotCheckWarnEventName: @@ -221,6 +222,7 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result { Status: WarningStatus, Message: message, Time: e.Time, + Advice: findAttribute(e, adviceKey), }) } case spotCheckErrorEventName: @@ -232,6 +234,7 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result { Status: ErrorStatus, Message: message, Time: e.Time, + Advice: findAttribute(e, adviceKey), }) } case spotCheckSkippedEventName: @@ -243,6 +246,7 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result { Status: SkippedStatus, Message: message, Time: e.Time, + Advice: findAttribute(e, adviceKey), }) } case adviceEventName: @@ -274,6 +278,15 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result { return r } +func findAttribute(e trace.Event, attr attribute.Key) string { + for _, a := range e.Attributes { + if a.Key == attr { + return a.Value.AsString() + } + } + return "" +} + func findAttributes(e trace.Event, attr1, attr2 attribute.Key) (string, string) { var av1, av2 string for _, a := range e.Attributes {