Skip to content

Commit

Permalink
Backport recent diagnose fixes to 1.8.x (#12108)
Browse files Browse the repository at this point in the history
* Suppress logging during a diagnose run (#12101)

* Suppress logging during a diagnose run

* remove debugging

* 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
  • Loading branch information
sgmiller committed Jul 16, 2021
1 parent dbc2f57 commit df0c8d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
8 changes: 5 additions & 3 deletions command/operator_diagnose.go
Expand Up @@ -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),
Expand Down Expand Up @@ -550,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.")

Expand Down
8 changes: 4 additions & 4 deletions vault/diagnose/os_common.go
Expand Up @@ -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.")
}
Expand Down
4 changes: 2 additions & 2 deletions vault/diagnose/os_unix.go
Expand Up @@ -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))
}
Expand Down
13 changes: 13 additions & 0 deletions vault/diagnose/output.go
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit df0c8d3

Please sign in to comment.