Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnoses Consul Direct Access Check #11505

Merged
merged 32 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ac1cb11
Create helpers which integrate with OpenTelemetry for diagnose collec…
sgmiller Apr 23, 2021
9ecc19a
Go mod vendor
sgmiller Apr 23, 2021
b0bdaca
consul tls checks
Apr 26, 2021
2d65d6c
fix merge conflicts
Apr 26, 2021
5f32206
draft for storage end to end check
Apr 26, 2021
11224d9
Comments
sgmiller Apr 26, 2021
5a3570e
Update vault/diagnose/helpers.go
sgmiller Apr 26, 2021
112f217
Add unit test/example
sgmiller Apr 26, 2021
e0c3a86
Merge branch 'diagnose-otel-integration' of github.com:/hashicorp/vau…
sgmiller Apr 26, 2021
29be762
tweak output
sgmiller Apr 26, 2021
8d5122d
More comments
sgmiller Apr 26, 2021
b2c1f7f
add spot check concept
sgmiller Apr 26, 2021
76dc535
Get unit tests working on Result structs
sgmiller Apr 28, 2021
bc10247
Fix unit test
sgmiller Apr 28, 2021
f1fea38
Merge remote-tracking branch 'origin/master' into diagnose-otel-integ…
sgmiller Apr 28, 2021
4a6bc9e
Get unit tests working, and make diagnose sessions local rather than …
sgmiller Apr 28, 2021
0682a4f
Comments
sgmiller Apr 28, 2021
14abc7f
Last comments
sgmiller Apr 28, 2021
3286135
No need for init
sgmiller Apr 28, 2021
4d26609
:|
sgmiller Apr 28, 2021
5063844
Fix helpers_test
sgmiller Apr 28, 2021
e6f7c6c
merge master
Apr 29, 2021
7d5e722
merge with otel integration branch
Apr 29, 2021
412a01c
cleaned up chan logic. Tests next.
Apr 29, 2021
f68f7dd
fix tests
Apr 29, 2021
357b192
merge master
Apr 29, 2021
45201c4
remove a comment
Apr 29, 2021
70835e6
tests
Apr 30, 2021
dd15e1e
remove a comment
Apr 30, 2021
ec94304
run direct access checks in diagnose command
Apr 30, 2021
6562cf4
merge master
May 2, 2021
4c0c565
review comments
May 2, 2021
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
Prev Previous commit
Next Next commit
add spot check concept
  • Loading branch information
sgmiller committed Apr 26, 2021
commit b2c1f7f9b04eaf5ee03b7ac6636b8173109c23ce
46 changes: 42 additions & 4 deletions vault/diagnose/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
)

const (
warningEventName = "warning"
actionKey = "actionKey"
errorMessageKey = attribute.Key("error.message")
warningEventName = "warning"
actionKey = "actionKey"
spotCheckOkEventName = "spot-check-ok"
spotCheckWarnEventName = "spot-check-warn"
spotCheckErrorEventName = "spot-check-error"
errorMessageKey = attribute.Key("error.message")
)

var tp *sdktrace.TracerProvider
Expand Down Expand Up @@ -61,10 +64,45 @@ func Error(ctx context.Context, err error, options ...trace.EventOption) error {
// Warn records a warning on the current span
func Warn(ctx context.Context, msg string) {
span := trace.SpanFromContext(ctx)

span.AddEvent(warningEventName, trace.WithAttributes(attribute.String("message", msg)))
}

func SpotOk(ctx context.Context, checkName, message string) {
addSpotCheckResult(ctx, spotCheckOkEventName, checkName, message)
}

func SpotWarn(ctx context.Context, checkName, message string) {
addSpotCheckResult(ctx, spotCheckWarnEventName, checkName, message)
}

func SpotError(ctx context.Context, checkName string, err error) {
var message string
if err != nil {
message = err.Error()
}
addSpotCheckResult(ctx, spotCheckErrorEventName, checkName, message)
}

func addSpotCheckResult(ctx context.Context, eventName, checkName, message string) {
span := trace.SpanFromContext(ctx)
attrs := []trace.EventOption{trace.WithAttributes(attribute.String("name", checkName))}
if message != "" {
attrs = append(attrs, trace.WithAttributes(attribute.String("message", message)))
}
span.AddEvent(eventName, attrs...)
}

func SpotCheck(ctx context.Context, checkName string, f func() error) error {
err := f()
if err != nil {
SpotError(ctx, checkName, err)
return err
} else {
SpotOk(ctx, checkName, "")
}
return nil
}

// Test creates a new named span, and executes the provided function within it. If the function returns an error,
// the span is considered to have failed.
func Test(ctx context.Context, spanName string, function func(context.Context) error, options ...trace.SpanOption) error {
Expand Down
7 changes: 2 additions & 5 deletions vault/diagnose/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ func makeCoffee(ctx context.Context) error {
return err
}

err = pickScone(ctx)
if err != nil {
Warn(ctx, err.Error())
}
SpotCheck(ctx, "pick-scone", pickScone)

return nil
}
Expand All @@ -81,6 +78,6 @@ func brewCoffee(ctx context.Context) error {
return nil
}

func pickScone(ctx context.Context) error {
func pickScone() error {
return errors.New("no scones")
}
62 changes: 60 additions & 2 deletions vault/diagnose/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result {
Message: s.StatusMessage(),
}
for _, e := range s.Events() {
if e.Name == warningEventName {
switch e.Name {
case warningEventName:
for _, a := range e.Attributes {
if a.Key == "message" {
r.Warnings = append(r.Warnings, a.Value.AsString())
}
}
} else if e.Name == errorStatus {
case errorStatus:
var message string
var action string
for _, a := range e.Attributes {
Expand All @@ -119,6 +120,63 @@ func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result {
})

}
case spotCheckOkEventName:
var checkName string
var message string
for _, a := range e.Attributes {
switch a.Key {
case "name":
checkName = a.Value.AsString()
case "message":
message = a.Value.AsString()
}
}
if checkName != "" {
r.Children = append(r.Children,
&Result{
Name: checkName,
Status: okStatus,
Message: message,
})
}
case spotCheckWarnEventName:
var checkName string
var message string
for _, a := range e.Attributes {
switch a.Key {
case "name":
checkName = a.Value.AsString()
case "message":
message = a.Value.AsString()
}
}
if checkName != "" {
r.Children = append(r.Children,
&Result{
Name: checkName,
Status: warnStatus,
Message: message,
})
}
case spotCheckErrorEventName:
var checkName string
var message string
for _, a := range e.Attributes {
switch a.Key {
case "name":
checkName = a.Value.AsString()
case "error":
message = a.Value.AsString()
}
}
if checkName != "" {
r.Children = append(r.Children,
&Result{
Name: checkName,
Status: errorStatus,
Message: message,
})
}
}
}
switch s.StatusCode() {
Expand Down