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

SetupStaticPublishing and SetupDynamicPublishing returns Tracer with Shutdown function #2566

Merged
merged 8 commits into from
Aug 15, 2022

Conversation

mgencur
Copy link
Contributor

@mgencur mgencur commented Aug 3, 2022

…acer

  • The caller can then call Shutdown() to properly flush buffered Spans
    before shutdown

This is incompatible change that will require updates in many repositories. I can either prepare those PRs so that they can be merged when this change propagates to those repositories or I can keep the old implementation and also provide a new impl that returns the OpenCensusTracer. Whatever works best.
Initially, I will provide an example PR for knative/eventing that will show the required updates.

Changes

/kind enhancement

Fixes #2475

Release Note


Docs


@knative-prow
Copy link

knative-prow bot commented Aug 3, 2022

@mgencur: The label(s) kind/<kind> cannot be applied, because the repository doesn't have them.

In response to this:

…acer

  • The caller can then call Finish() to properly flush buffered Spans
    before shutdown

This is incompatible change that will require updates in many repositories. I can either prepare those PRs so that they can be merged when this change propagates to those repositories or I can keep the old implementation and also provide a new impl that returns the OpenCensusTracer. Whatever works best.
Initially, I will provide an example PR for knative/eventing that will shows the required updates.

Changes

/kind

Fixes #

Release Note


Docs


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 3, 2022
tracing/opencensus.go Outdated Show resolved Hide resolved
@mgencur
Copy link
Contributor Author

mgencur commented Aug 3, 2022

/retest-required

@codecov
Copy link

codecov bot commented Aug 3, 2022

Codecov Report

Merging #2566 (2b37ebd) into main (7b8b060) will decrease coverage by 0.08%.
The diff coverage is 13.04%.

@@            Coverage Diff             @@
##             main    #2566      +/-   ##
==========================================
- Coverage   81.40%   81.31%   -0.09%     
==========================================
  Files         163      163              
  Lines        9740     9753      +13     
==========================================
+ Hits         7929     7931       +2     
- Misses       1574     1585      +11     
  Partials      237      237              
Impacted Files Coverage Δ
tracing/setup.go 0.00% <0.00%> (ø)
tracing/opencensus.go 48.11% <19.35%> (-1.39%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 3, 2022
@dprotaso
Copy link
Member

dprotaso commented Aug 3, 2022

We want to move away from OpenCensus - I don't think we should be returning the concrete type.

See: #2561 (comment)

@mgencur
Copy link
Contributor Author

mgencur commented Aug 3, 2022

@dprotaso The downstream repositories are still using OpenCensus.
Looks like opentelemetry mostly uses something like this: Shutdown(ctx context.Context) error, E.g. here. Would it sound better to return a type that implements this function? Not sure what other options we have.
Something like this:

type Shutdowner interface {
	Shutdown(ctx context.Context) error
}

func SetupStaticPublishing(logger *zap.SugaredLogger, serviceName string, cfg *config.Config) (Shutdowner, error) {
	...
}

Anyways, we might end up with different needs. Its hard to predict future.
Edit: We might call the type "Tracer" with the option to add more functions later if needed:

type Tracer interface {
	Shutdown(ctx context.Context) error
}

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 4, 2022
@mgencur
Copy link
Contributor Author

mgencur commented Aug 4, 2022

@dprotaso I've pushed a new commit and provided the Tracer type with the generic Shutdown function. WDYT?

@mgencur mgencur force-pushed the opencensus_finish branch 2 times, most recently from 05c76b0 to 94a40f4 Compare August 4, 2022 11:01
@mgencur mgencur changed the title [WIP] SetupStaticPublishing and SetupDynamicPublishing returns OpenCensusTr… [WIP] SetupStaticPublishing and SetupDynamicPublishing returns Tracer with Shutdown function Aug 5, 2022
}
return nil
return oct, nil
Copy link
Member

@daisy-ycguo daisy-ycguo Aug 5, 2022

Choose a reason for hiding this comment

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

Is it possible to wrap the created object oct and hide the life cycle management in pkg/tracing other than returning it and delegating the management to other components?

Copy link
Contributor Author

@mgencur mgencur Aug 5, 2022

Choose a reason for hiding this comment

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

I don't think so. Components that are creating the tracer will do some work and they need to shutdown the tracer at the end (before their own shutdown). And they do it by calling Shutdown throught the tracing.Tracer interface. So the components will now depend only on the pkg/tracing package.
If you have other thoughts how this could be done please let me know.
There's now knative/eventing#6474 which shows how this would be used.

tracing/setup.go Show resolved Hide resolved
Comment on lines +99 to +100
case <-ctx.Done():
return ctx.Err()
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason why we skip performing the shutdown when the context is cancelled?

Copy link
Contributor Author

@mgencur mgencur Aug 6, 2022

Choose a reason for hiding this comment

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

It's a common way to allow for interrupting a long running functions through the context. OpenTelemetry uses this approach as well for interrupting the Shutdown function. I don't have a strong opionion about this - we could also keep continuing the shutdown until the end. The context would not be used in this implementation then.

tracing/opencensus.go Show resolved Hide resolved
tracing/setup.go Show resolved Hide resolved
tracing/setup.go Outdated Show resolved Hide resolved
// just ensures that if generated, they are collected appropriately. This is normally done by using
// tracing.HTTPSpanMiddleware as a middleware HTTP handler. The configuration will be dynamically
// updated when the ConfigMap is updated.
func SetupDynamicPublishing(logger *zap.SugaredLogger, configMapWatcher configmap.Watcher, serviceName, tracingConfigName string) error {
func SetupPublishingWithDynamicConfig(logger *zap.SugaredLogger, configMapWatcher configmap.Watcher, serviceName, tracingConfigName string) (Tracer, error) {
Copy link
Member

@daisy-ycguo daisy-ycguo Aug 8, 2022

Choose a reason for hiding this comment

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

Since we are changing the interface and we want to change all the invocation of SetupDynamicPublishing to SetupPublishingWithDynamicConfig, could we change to SetupPublishingWithDynamicConfigAndInitialValue directly? As I reported in issue #2557, SetupDynamicPublishing does not work properly since it doesn't call oct.ApplyConfig(cfg) at the first time.

If you agree, I think we don't need method SetupPublishingWithDynamicConfig because we will not use it any more. We just need method SetupPublishingWithDynamicConfigAndInitialValue.

@dprotaso your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since knative/eventing#6456 is not yet implemented and SetupDynamicPublishingWithInitialValue is not referenced yet I think it makes sense to do this:

  • Keep the current PR as it is and only have the latest/newest SetupPublishingWithDynamicConfigAndInitialValue
  • If the current PR is merged soon enough the new function can be used directly in a PR for knative/eventing
  • If there is a PR for knative/eventing merged before the current one I will put back the backwards-compatible function here so as to not break downstream

@mgencur mgencur changed the title [WIP] SetupStaticPublishing and SetupDynamicPublishing returns Tracer with Shutdown function SetupStaticPublishing and SetupDynamicPublishing returns Tracer with Shutdown function Aug 15, 2022
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 15, 2022
@dprotaso
Copy link
Member

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Aug 15, 2022
@knative-prow
Copy link

knative-prow bot commented Aug 15, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, mgencur

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 15, 2022
@dprotaso
Copy link
Member

FYI - knative.dev/pkg cut is tomorrow - if you plan on making any more edits tomorrow let me know and I can wait as long as it's straight forward

@knative-prow knative-prow bot merged commit 894c2f2 into knative:main Aug 15, 2022
@mgencur
Copy link
Contributor Author

mgencur commented Aug 16, 2022

@dprotaso @daisy-ycguo Thanks for reviews and merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sure OpenCensusTracer from tracing package can be correctly shut down (flushed)
3 participants