Edge cases in the skipping gathering and output logic (#11752)

* Edge cases in the skipping gathering and output logic

* Fix unit test
This commit is contained in:
Scott Miller
2021-06-03 11:01:14 -05:00
committed by GitHub
parent 9a2fbadd8b
commit 02c2f731ec
4 changed files with 19 additions and 10 deletions

View File

@@ -302,7 +302,8 @@ func (c *OperatorDiagnoseCommand) offlineDiagnostics(ctx context.Context) error
var configSR sr.ServiceRegistration
diagnose.Test(ctx, "service-discovery", func(ctx context.Context) error {
if config.ServiceRegistration == nil || config.ServiceRegistration.Config == nil {
return fmt.Errorf("No service registration config")
diagnose.Skipped(ctx, "no service registration configured")
return nil
}
srConfig := config.ServiceRegistration.Config
@@ -397,9 +398,13 @@ SEALFAIL:
return nil
})
diagnose.Test(ctx, "test-consul-direct-access-storage", func(ctx context.Context) error {
dirAccess := diagnose.ConsulDirectAccess(config.HAStorage.Config)
if dirAccess != "" {
diagnose.Warn(ctx, dirAccess)
if config.HAStorage == nil {
diagnose.Skipped(ctx, "no HA storage configured")
} else {
dirAccess := diagnose.ConsulDirectAccess(config.HAStorage.Config)
if dirAccess != "" {
diagnose.Warn(ctx, dirAccess)
}
}
return nil
})
@@ -430,7 +435,7 @@ SEALFAIL:
var lns []listenerutil.Listener
diagnose.Test(ctx, "init-listeners", func(ctx context.Context) error {
disableClustering := config.HAStorage.DisableClustering
disableClustering := config.HAStorage != nil && config.HAStorage.DisableClustering
infoKeys := make([]string, 0, 10)
info := make(map[string]string)
var listeners []listenerutil.Listener

View File

@@ -127,9 +127,10 @@ func Error(ctx context.Context, err error, options ...trace.EventOption) error {
}
// Skipped marks the current span skipped
func Skipped(ctx context.Context) {
func Skipped(ctx context.Context, message string) {
span := trace.SpanFromContext(ctx)
span.AddEvent(skippedEventName)
span.SetStatus(codes.Error, message)
}
// Warn records a warning on the current span
@@ -227,7 +228,7 @@ func Skippable(skipName string, f testFunction) testFunction {
if !session.IsSkipped(skipName) {
return f(ctx)
} else {
Skipped(ctx)
Skipped(ctx, "skipped as requested")
}
}
return nil

View File

@@ -32,8 +32,9 @@ func TestDiagnoseOtelResults(t *testing.T) {
Message: "no scones",
},
{
Name: "dispose-grounds",
Status: SkippedStatus,
Name: "dispose-grounds",
Status: SkippedStatus,
Message: "skipped as requested",
},
},
}

View File

@@ -301,7 +301,9 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result {
r.Status = OkStatus
}
case codes.Error:
r.Status = ErrorStatus
if r.Status != SkippedStatus {
r.Status = ErrorStatus
}
}
t.results[id] = r
}