mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 02:02:43 +00:00
Initial Diagnose CLI output (#11583)
* Create helpers which integrate with OpenTelemetry for diagnose collection * Go mod vendor * Comments * Update vault/diagnose/helpers.go Co-authored-by: swayne275 <swayne275@gmail.com> * Add unit test/example * tweak output * More comments * add spot check concept * Get unit tests working on Result structs * wip * Fix unit test * Get unit tests working, and make diagnose sessions local rather than global * Comments * Last comments * No need for init * :| * Fix helpers_test * wip * wip * wip * Revendor otel * Fix merge related problems * imports * Fix unit tests Co-authored-by: swayne275 <swayne275@gmail.com>
This commit is contained in:
@@ -2,9 +2,13 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/hashicorp/consul/api"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/vault/internalshared/listenerutil"
|
||||
@@ -95,6 +99,12 @@ func (c *OperatorDiagnoseCommand) Flags() *FlagSets {
|
||||
Default: false,
|
||||
Usage: "Dump all information collected by Diagnose.",
|
||||
})
|
||||
|
||||
f.StringVar(&StringVar{
|
||||
Name: "format",
|
||||
Target: &c.flagFormat,
|
||||
Usage: "The output format",
|
||||
})
|
||||
return set
|
||||
}
|
||||
|
||||
@@ -130,10 +140,31 @@ func (c *OperatorDiagnoseCommand) RunWithParsedFlags() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
if c.diagnose == nil {
|
||||
if c.flagFormat == "json" {
|
||||
c.diagnose = diagnose.New(&ioutils.NopWriter{})
|
||||
} else {
|
||||
c.UI.Output(version.GetVersion().FullVersionNumber(true))
|
||||
c.diagnose = diagnose.New(os.Stdout)
|
||||
}
|
||||
}
|
||||
c.UI.Output(version.GetVersion().FullVersionNumber(true))
|
||||
ctx := diagnose.Context(context.Background(), c.diagnose)
|
||||
err := c.offlineDiagnostics(ctx)
|
||||
c.diagnose.SetSkipList(c.flagSkips)
|
||||
err := c.offlineDiagnostics(ctx)
|
||||
|
||||
results := c.diagnose.Finalize(ctx)
|
||||
if c.flagFormat == "json" {
|
||||
resultsJS, err := json.MarshalIndent(results, "", " ")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error marshalling results: %v", err)
|
||||
return 2
|
||||
}
|
||||
c.UI.Output(string(resultsJS))
|
||||
} else {
|
||||
c.UI.Output("\nResults:")
|
||||
results.Write(os.Stdout)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return 1
|
||||
@@ -165,7 +196,6 @@ func (c *OperatorDiagnoseCommand) offlineDiagnostics(ctx context.Context) error
|
||||
|
||||
ctx, span := diagnose.StartSpan(ctx, "initialization")
|
||||
defer span.End()
|
||||
|
||||
server.flagConfigs = c.flagConfigs
|
||||
config, err := server.parseConfig()
|
||||
if err != nil {
|
||||
@@ -269,7 +299,7 @@ func (c *OperatorDiagnoseCommand) offlineDiagnostics(ctx context.Context) error
|
||||
return err
|
||||
}
|
||||
|
||||
return diagnose.Test(ctx, "service-discovery", func(ctx context.Context) error {
|
||||
diagnose.Test(ctx, "service-discovery", func(ctx context.Context) error {
|
||||
srConfig := config.ServiceRegistration.Config
|
||||
// Initialize the Service Discovery, if there is one
|
||||
if config.ServiceRegistration != nil && config.ServiceRegistration.Type == "consul" {
|
||||
@@ -281,11 +311,10 @@ func (c *OperatorDiagnoseCommand) offlineDiagnostics(ctx context.Context) error
|
||||
|
||||
// SetupSecureTLS for service discovery uses the same cert and key to set up physical
|
||||
// storage. See the consul package in physical for details.
|
||||
err = srconsul.SetupSecureTLS(api.DefaultConfig(), srConfig, server.logger, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return srconsul.SetupSecureTLS(api.DefaultConfig(), srConfig, server.logger, true)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user