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

pkg/{porter,tracing}, cmd/porter: add tracing instrumentation for list #1864

Merged
merged 4 commits into from
Jan 26, 2022

Conversation

VinozzZ
Copy link
Contributor

@VinozzZ VinozzZ commented Jan 19, 2022

command

What does this change

This PR adds instrumentation for list command. It also adds support for
automatically setting span name during creation by the caller function
name.
Some fixes for unclosed spans is included as well

What issue does it fix

related to #1857

Notes for the reviewer

Put any questions or notes for the reviewer here.

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

command

This PR adds instrumentation for list command. It also adds support for
automatically setting span name during creation by the caller function
name.

Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
@VinozzZ VinozzZ marked this pull request as ready for review January 19, 2022 21:44
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Looks good, I just have some comments to help improve readability

pkg/porter/apply.go Show resolved Hide resolved
pkg/porter/list_test.go Outdated Show resolved Hide resolved
pkg/tracing/scopedLogger.go Outdated Show resolved Hide resolved
pkg/porter/list.go Outdated Show resolved Hide resolved

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type ScopedLogger interface {
StartSpan(op string, attrs ...attribute.KeyValue) (context.Context, ScopedLogger)
StartSpanNamed(attrs ...attribute.KeyValue) (context.Context, ScopedLogger)
Copy link
Member

Choose a reason for hiding this comment

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

When should someone use StartSpan and explicitly name the op vs. using StartSpanNamed and have the op named after the current function?

Also it's not clear to me what StartSpanNamed will do. How about we tweak the name a bit so it's clear that the span will be named after the function, like StartSpanFromFunction or StartSpanNamedByFunction or something else like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my perspective, a span is for a logical unit that usually contains side affect on a state. That often happens within a function. It also helps to create a trace that easily relate back to the code. We will know exactly which function created a span. I also changed the name to StartSpanNamedByCaller. Let me know what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

When would someone use StartSpan vs StartSpanByCaller? Or should we remove StartSpan and never give a custom name to a span?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking maybe someone would want multiple spans within a complex function and then they will need to manually provide names for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe what we could do is to have this interface instead

type ScopedLogger interface {
  StartSpan(attrs ...attribute.KeyValue) 
  StarSpanByCustomName(op string, attrs ...attribute.KeyValue)
  ...
}

That way the default behavior is to use callerFunc(), and then if someone wants to use a custom name they will use the other one

pkg/tracing/scopedLogger.go Outdated Show resolved Hide resolved
@carolynvs carolynvs self-assigned this Jan 21, 2022
Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Let's think about when a developer would use StartSpan vs StartSpanByCaller and consider if we should just have a single function that uses the callerFunc. Right now I think other devs working on Porter will be unsure when to use each function.

pkg/tracing/logger.go Outdated Show resolved Hide resolved
pkg/tracing/logger.go Outdated Show resolved Hide resolved
pkg/tracing/logger.go Outdated Show resolved Hide resolved
pkg/tracing/logger.go Outdated Show resolved Hide resolved
pkg/tracing/logger.go Outdated Show resolved Hide resolved
pkg/porter/list.go Outdated Show resolved Hide resolved
tests/integration/claim_migration_test.go Outdated Show resolved Hide resolved
@carolynvs
Copy link
Member

I just checked out the failed build, and it's not from your changes. I think it's a flakey test and the next time it runs, it should pass.

Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Everything looks great, I just have one more question (below).

pkg/build/buildkit/buildx.go Outdated Show resolved Hide resolved
Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

This is great thank you for setting up some patterns for us to follow as we instrument the rest of Porter! 💯

pkg/tracing/logger_test.go Show resolved Hide resolved
@carolynvs
Copy link
Member

/azp run porter-integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carolynvs carolynvs merged commit 4d688d2 into getporter:release/v1 Jan 26, 2022
carolynvs added a commit to carolynvs/porter that referenced this pull request Jan 26, 2022
Two pull requests, getporter#1864 and getporter#1851, were merged, and while it didn't cause a merge
conflict, they didn't play well together and it broke the build.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
@carolynvs carolynvs mentioned this pull request Jan 26, 2022
4 tasks
joshuabezaleel pushed a commit to joshuabezaleel/porter that referenced this pull request Feb 8, 2022
getporter#1864)

* pkg/{porter,tracing}, cmd/porter: add tracing instrumentation for list
command

This PR adds instrumentation for list command. It also adds support for
automatically setting span name during creation by the caller function
name.

Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>

* add readability

Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>

* use new interface for creating a span

Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>

* add unit test

Signed-off-by: Yingrong Zhao <yingrong.zhao@gmail.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
joshuabezaleel pushed a commit to joshuabezaleel/porter that referenced this pull request Feb 8, 2022
Two pull requests, getporter#1864 and getporter#1851, were merged, and while it didn't cause a merge
conflict, they didn't play well together and it broke the build.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
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.

2 participants