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

Create helpers which integrate with OpenTelemetry for diagnose collection #11454

Merged
merged 18 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
tweak output
  • Loading branch information
sgmiller committed Apr 26, 2021
commit 29be762e8f472e97116eae5c5427b999351ac689
2 changes: 2 additions & 0 deletions vault/diagnose/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package diagnose
import (
"context"
"errors"
"os"
"reflect"
"testing"
)
Expand Down Expand Up @@ -39,6 +40,7 @@ func TestDiagnoseOtelResults(t *testing.T) {
if !reflect.DeepEqual(results, expected) {
t.Fail()
}
results.Write(os.Stdout)
}

const coffeeLeft = 3
Expand Down
45 changes: 26 additions & 19 deletions vault/diagnose/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package diagnose

import (
"context"
"errors"
"io"
"strings"

Expand All @@ -21,6 +22,8 @@ const (
okStatus = "ok"
)

var errUnimplemented = errors.New("unimplemented")

type Result struct {
Name string
Warnings []string
Expand Down Expand Up @@ -70,11 +73,11 @@ func (t *TelemetryCollector) OnEnd(e sdktrace.ReadOnlySpan) {
}

func (t *TelemetryCollector) Shutdown(ctx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave some quick comments on these stub methods detailing what we'd want them to do?

return nil
return errUnimplemented
}

func (t *TelemetryCollector) ForceFlush(ctx context.Context) error {
return nil
return errUnimplemented
}

func (t *TelemetryCollector) getOrBuildResult(id trace.SpanID) *Result {
Expand Down Expand Up @@ -142,30 +145,34 @@ func (r *Result) Write(writer io.Writer) error {
}

func (r *Result) write(sb *strings.Builder, depth int) {
for i := 0; i < depth; i++ {
sb.WriteRune('\t')
}
switch r.Status {
case okStatus:
sb.WriteString(status_ok)
case warnStatus:
sb.WriteString(status_warn)
case errorStatus:
sb.WriteString(status_failed)
}
sb.WriteString(r.Name)
if r.Status != warnStatus || (len(r.Warnings) == 0 && r.Message != "") {
for i := 0; i < depth; i++ {
sb.WriteRune('\t')
}
switch r.Status {
case okStatus:
sb.WriteString(status_ok)
case warnStatus:
sb.WriteString(status_warn)
case errorStatus:
sb.WriteString(status_failed)
}
sb.WriteString(r.Name)

if r.Message != "" || len(r.Warnings) > 0 {
sb.WriteString(": ")
if r.Message != "" || len(r.Warnings) > 0 {
sb.WriteString(": ")
}
sb.WriteString(r.Message)
}
sb.WriteString(r.Message)
for _, w := range r.Warnings {
sb.WriteRune('\n')
for i := 0; i < depth; i++ {
sb.WriteRune('\t')
}
sb.WriteString(" ")
sb.WriteString(status_warn)
sb.WriteString(r.Name)
sb.WriteString(": ")
sb.WriteString(w)
sb.WriteRune('\n')
}
sb.WriteRune('\n')
for _, c := range r.Children {
Expand Down