-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Conversation
vault/diagnose/output.go
Outdated
for i := 0; i < depth; i++ { | ||
sb.WriteRune('\t') | ||
} | ||
sb.WriteString(" ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm working on visualizing what is going on here.
It looks like general nesting is happening with the \t
parts, and then warnings are further nested under the r.Message
by writing the empty spaces.
Do we want the first of the warning to have a newline between it and the r.Message
? It looks like there will just be spaces, then a warning (on the same line as the message), then more warnings on each line after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, this was quick and dirty. but that does look like a bug as written. Maybe I should throw up a unit test so we can take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Mainly left comments around adding some descriptions for some of the functions, and had a couple clarifying questions. Overall though, makes sense!
tc = NewTelemetryCollector() | ||
//so, _ := stdout.NewExporter(stdout.WithPrettyPrint()) | ||
tp = sdktrace.NewTracerProvider( | ||
sdktrace.WithSampler(sdktrace.AlwaysSample()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs say AlwaysSample returns a Sampler that samples every trace. Be careful about using this sampler in a production application with significant traffic: a new trace will be started and exported for every request.
. Would this be a problem?
https://pkg.go.dev/go.opentelemetry.io/otel/[email protected]/trace#Sampler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd only want to use this in Diagnose runs, likely, yes. Not in general.
|
||
// 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awesome function!
So, say I wanted to call Test a function, but I also wanted that function to have record actions. Would I need 2 different spans -- one for Test, and one within the function itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test introduces a span, so you probably only need the one. You can of course have more spans nested under the Test (started by the function or sub-calls).
|
||
// Warn records a warning on the current span | ||
func Warn(ctx context.Context, msg string) { | ||
span := trace.SpanFromContext(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to use these functions, we need to add a span to our context? Suppose we're in a particular context for a function a, and we want to call Test
on a sub function b -- do we create a new context with a new spanName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These ones yes. Let me throw up a unit test with a working example which may help.
vault/diagnose/helpers.go
Outdated
} | ||
|
||
func Action(actionName string) trace.LifeCycleOption { | ||
return trace.WithAttributes(attribute.String(actionKey, actionName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how Action
ties into a span. Could you add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually from an earlier effort, removing.
vault/diagnose/output.go
Outdated
} | ||
} | ||
|
||
func (t *TelemetryCollector) OnStart(parent context.Context, s sdktrace.ReadWriteSpan) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does parent do here? Could you leave a quick comment?
vault/diagnose/output.go
Outdated
|
||
func (t *TelemetryCollector) OnEnd(e sdktrace.ReadOnlySpan) { | ||
if !e.Parent().HasSpanID() { | ||
// Deep first walk the span structs to construct the top down tree results we want |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused about how this works. Why does this call getOrBuildResult
2 levels deep, as opposed to recursively until p == nil
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need to since the span map is all spans, so all nodes that are parents will be visited once. Some Results will have already been built when they're visited if they're a parent to an earlier span.
vault/diagnose/output.go
Outdated
} | ||
} | ||
|
||
func (t *TelemetryCollector) Shutdown(ctx context.Context) error { |
There was a problem hiding this comment.
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?
Co-authored-by: swayne275 <[email protected]>
…lt into diagnose-otel-integration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me know your thoughts on that comment. it's not that big of a deal, but i'd prefer errors (unless that impl is coming like very shortly so it can't really become a potential issue)
command/operator_diagnose.go
Outdated
_, err = server.setupStorage(config) | ||
return err | ||
}) | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, it looks like you're returning right after another return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this github preview doesn't show enough code to show what i'm pointing out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you take another look? It's tricky because there is an anonymous function there as an argument to diagnose.Test, so you're probably seeing that functions return followed by the other one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically i think the return nil is a noop - and i'm guessing the compiler doesn't complain about that if the tests are running?
…ration # Conflicts: # command/operator_diagnose.go # command/operator_diagnose_test.go
…tion (hashicorp#11454) * Create helpers which integrate with OpenTelemetry for diagnose collection * Go mod vendor * Comments * Update vault/diagnose/helpers.go Co-authored-by: swayne275 <[email protected]> * Add unit test/example * tweak output * More comments * add spot check concept * Get unit tests working on Result structs * 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 Co-authored-by: swayne275 <[email protected]>
…tion (hashicorp#11454) * Create helpers which integrate with OpenTelemetry for diagnose collection * Go mod vendor * Comments * Update vault/diagnose/helpers.go Co-authored-by: swayne275 <[email protected]> * Add unit test/example * tweak output * More comments * add spot check concept * Get unit tests working on Result structs * 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 Co-authored-by: swayne275 <[email protected]>
No description provided.