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

Conversation

sgmiller
Copy link
Collaborator

No description provided.

@vercel vercel bot temporarily deployed to Preview – vault April 23, 2021 19:04 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 23, 2021 19:04 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 26, 2021 16:39 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 26, 2021 16:39 Inactive
@HridoyRoy HridoyRoy self-requested a review April 26, 2021 17:25
vault/diagnose/helpers.go Outdated Show resolved Hide resolved
vault/diagnose/output.go Show resolved Hide resolved
for i := 0; i < depth; i++ {
sb.WriteRune('\t')
}
sb.WriteString(" ")
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

great!

Copy link
Contributor

@HridoyRoy HridoyRoy left a 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()),
Copy link
Contributor

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

Copy link
Collaborator Author

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 {
Copy link
Contributor

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?

Copy link
Collaborator Author

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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

}

func Action(actionName string) trace.LifeCycleOption {
return trace.WithAttributes(attribute.String(actionKey, actionName))
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

}
}

func (t *TelemetryCollector) OnStart(parent context.Context, s sdktrace.ReadWriteSpan) {
Copy link
Contributor

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?


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
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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.

}
}

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?

@vercel vercel bot temporarily deployed to Preview – vault-storybook April 26, 2021 18:25 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 26, 2021 18:25 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 26, 2021 20:30 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 26, 2021 20:30 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 26, 2021 20:39 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 26, 2021 20:39 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 26, 2021 20:43 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 26, 2021 20:43 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 26, 2021 21:11 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 26, 2021 21:11 Inactive
@sgmiller sgmiller requested a review from swayne275 April 27, 2021 15:52
Copy link
Contributor

@swayne275 swayne275 left a 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)

vault/diagnose/output.go Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 28, 2021 14:43 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 28, 2021 14:43 Inactive
_, err = server.setupStorage(config)
return err
})
return nil
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Screen Shot 2021-04-29 at 9 41 55 AM

yeah, this is what i'm seeing. I'm not thinking about the return err bit inside the func(ctx context.Context) error, i'm thinking about the return diagnose.Test... on line 219

thoughts?

Copy link
Contributor

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?

@vercel vercel bot temporarily deployed to Preview – vault April 28, 2021 19:11 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 28, 2021 19:11 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 28, 2021 19:13 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 28, 2021 19:13 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 28, 2021 19:16 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 28, 2021 19:16 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 28, 2021 19:16 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 28, 2021 19:16 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 28, 2021 19:19 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 28, 2021 19:19 Inactive
@sgmiller sgmiller merged commit d60057b into master Apr 29, 2021
@sgmiller sgmiller deleted the diagnose-otel-integration branch April 29, 2021 18:32
AndreyZamyslov pushed a commit to yandex-cloud/vault that referenced this pull request Jun 10, 2021
…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]>
jartek pushed a commit to jartek/vault that referenced this pull request Sep 11, 2021
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants