Skip to content

Add tracing to activator - #2726

Merged
knative-prow-robot merged 2 commits into
knative:masterfrom
greghaynes:autoscaler-tracing
Apr 19, 2019
Merged

knative-prow-robot merged 2 commits into
knative:masterfrom
greghaynes:autoscaler-tracing

Conversation

@greghaynes

@greghaynes greghaynes commented Dec 14, 2018 •

Copy link
Copy Markdown
Contributor

In oder to get more detailed and persistently measured perf. data for activator lets add tracing spans. This also adds a general tracing pkg useful elsewhere.

Related-to: #2495
Fixes #1276

NONE

@knative-prow-robot knative-prow-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 14, 2018

@knative-prow-robot knative-prow-robot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@greghaynes: 6 warnings.

Details

In response to this:

In oder to get more detailed and persistently measured
perf. data for autoscaler lets add tracing spans to
autoscaler operations.

Fixes #

Proposed Changes

Release Note


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.

Comment thread pkg/tracing/tracer.go Outdated
return tracer, collector, nil
}

type Tracer struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Golint comments: exported type Tracer should have comment or be unexported. More info.

Comment thread pkg/tracing/tracer.go Outdated
collector zipkin.Collector
}

func CreateTracer(logger *zap.SugaredLogger) (*Tracer, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Golint comments: exported function CreateTracer should have comment or be unexported. More info.

Comment thread pkg/tracing/tracer.go Outdated
}, nil
}

func (t *Tracer) CreateSpanFromRequest(logger *zap.SugaredLogger, r *http.Request, opName string) opentracing.Span {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Golint comments: exported method Tracer.CreateSpanFromRequest should have comment or be unexported. More info.

Comment thread pkg/tracing/tracer.go Outdated
ext.RPCServerOption(wireContext))
}

func (t *Tracer) Close() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Golint comments: exported method Tracer.Close should have comment or be unexported. More info.

Comment thread pkg/tracing/tracer.go Outdated
t.collector.Close()
}

type SpanHandler struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Golint comments: exported type SpanHandler should have comment or be unexported. More info.

Comment thread pkg/tracing/tracer.go Resolved
@greghaynes
greghaynes force-pushed the autoscaler-tracing branch 4 times, most recently from db717b9 to a458973 Compare December 20, 2018 21:03
@greghaynes greghaynes changed the title [WIP] Add tracing to autoscaler [WIP] Add tracing to activator Dec 20, 2018
@greghaynes
greghaynes force-pushed the autoscaler-tracing branch 2 times, most recently from dcb02db to 50b2de4 Compare January 16, 2019 21:12
@greghaynes greghaynes changed the title [WIP] Add tracing to activator Add tracing to activator Jan 16, 2019
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 16, 2019
@greghaynes

Copy link
Copy Markdown
Contributor Author

Sorry for the huge LOC - its mostly due to vendor deps. Suggestions welcome for ways to reduce that :)

/cc @mdemirhan @josephburnett

Comment thread cmd/activator/main.go Outdated
cfg := config.FromContext(ctx)
ref, err := tracerCache.GetTracer(cfg.Tracing)
if err != nil {
logger.Errorf("Unable to create tracer from tracer config: %v", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logger.Errorw(..., zap.Error(err))

Comment thread cmd/activator/main.go Outdated
<-stopCh
a.Shutdown()
srv.Shutdown(context.TODO())
tracerCache.Close()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not just defer tracerCache.Close() right after creation?

Comment thread pkg/activator/config/store.go Outdated
@@ -0,0 +1,84 @@
/*
Copyright 2018 The Knative Authors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2019 here and elsewhere.

Comment thread pkg/tracing/tracer_test.go Outdated
tracer := mocktracer.New()
span := CreateChildSpanFromContext(tracer, context.TODO(), "test").(*mocktracer.MockSpan)
if pid := span.BaggageItem("parentID"); pid != "" {
t.Errorf("Expected \"\" span parentID, got: %q", pid)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expected empty span...?

@markusthoemmes markusthoemmes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Quite the diff indeed, made a first pass and the general approach looked good. Left a few driveby comments.

Comment thread pkg/tracing/cache.go Outdated
if tc.cfg == nil || !tc.cfg.Equals(cfg) {
tracer, err := CreateZipkinTracer(cfg)
if err != nil {
tc.tracerRef.refs.RLock()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this also be tc.tracerRef.Ref()?

tracerRef := a.TRGetter(ctx)
if tracerRef == nil {
a.Logger.Error("Unable to get tracer from request context")
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really want to abort all HTTP requests if we fail to get a tracer?

Comment thread pkg/activator/handler/handler.go Outdated

tracer := tracerRef.Tracer.Tracer
activateSpan := tracing.CreateChildSpanFromContext(tracer, ctx, "active_endpoint")
a.Logger.Errorf("Activator: %v", a.Activator)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leftover logging?

Comment thread pkg/activator/handler/handler_test.go Outdated
},
}

mt := mocktracer.New()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this support testing in some way so we can assert that the correct spans are written by the handler?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread pkg/tracing/tracer.go Outdated

const (
serviceName = "activator"
myHostPort = "127.0.0.1:61001"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is this coming from?

Comment thread pkg/tracing/tracer.go Outdated
)

const (
serviceName = "activator"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this mean we cannot instrument other components? Should this name be passed via CreateZipkinTracer?

@greghaynes greghaynes changed the title Add tracing to activator [WIP] Add tracing to activator Feb 26, 2019
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 26, 2019
@greghaynes
greghaynes force-pushed the autoscaler-tracing branch from 5c1babe to 248ec29 Compare March 1, 2019 04:24
@greghaynes
greghaynes force-pushed the autoscaler-tracing branch from 3390d18 to 2d6d60b Compare April 2, 2019 18:43
@greghaynes

Copy link
Copy Markdown
Contributor Author

I think I covered the outstanding comments, LMK if I missed something

Comment thread config/config-tracing.yaml Resolved
@greghaynes
greghaynes force-pushed the autoscaler-tracing branch from 2d6d60b to ce552a2 Compare April 3, 2019 15:36
Comment thread cmd/activator/main.go Outdated
defer tracerCache.Close()
trGetter := func(ctx context.Context) *tracing.TracerRef {
cfg := config.FromContext(ctx)
return tracerCache.GetTracerRefOrNoop(logger, cfg.Tracing, "activator", "localhost:1234")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

localhost:1234 looks like a dummy value?

Comment thread cmd/activator/main.go
component = "activator"

// This is the number of times we will perform network probes to
// see if the Revision is accessible before forwarding the actual

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was this removed by accident?

@markusthoemmes markusthoemmes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've looked too many times at this to still find bugs by more looking. I think this is good to go in modulo the comments I left.

@greghaynes
greghaynes force-pushed the autoscaler-tracing branch 3 times, most recently from 552114d to d792919 Compare April 3, 2019 20:11
Comment thread pkg/activator/config/store.go Outdated
}
}

// TracingEnabledForContext returns true if tracing is enabled in the Configuration injected in to ctx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You return two booleans, so comment needs to be updated.

Comment thread pkg/activator/handler/handler.go Outdated
attempts int
)

probeSpan, reqCtx := tracer.StartSpanFromContext(r.Context(), "probe")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what if move this into its own function then

  1. this function will become more readable
  2. we can do probespan, ... defer probespan.finish()

Comment thread pkg/tracing/config/tracing.go Resolved
Comment thread pkg/tracing/http.go Outdated
zipkinhttp "github.com/openzipkin/zipkin-go/middleware/http"
)

// TracerRefGetter retrurns a tracer gien a context containing a tracer config

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TracerRefGetter retrurns a tracer gien a context containing a tracer config
// TracerRefGetter retrurns a tracer given a context containing a tracer config

Comment thread pkg/tracing/http.go Outdated
type spanHandler struct {
opName string
next http.Handler
TRGetter TracerRefGetter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason for this to be public?

Comment thread pkg/tracing/http.go Outdated
TRGetter TracerRefGetter
}

// ServeHTTP is an http handler which injects a tracing span using a TracerRefGetter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ServeHTTP is an http handler which injects a tracing span using a TracerRefGetter
// ServeHTTP is an HTTP handler which injects a tracing span using a TracerRefGetter

@markusthoemmes markusthoemmes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just saw another PR that fixed some of those and remembered I'd seen something odd here 😂

Comment thread pkg/tracing/cache.go Resolved
Comment thread pkg/tracing/cache_test.go Resolved
Comment thread pkg/tracing/http.go Resolved
Comment thread pkg/tracing/http_test.go Resolved
Comment thread pkg/tracing/tracer.go Resolved
Comment thread pkg/tracing/tracer_test.go Resolved
@greghaynes
greghaynes force-pushed the autoscaler-tracing branch 2 times, most recently from cbbf698 to b322caf Compare April 4, 2019 18:47
@greghaynes

Copy link
Copy Markdown
Contributor Author

/test pull-knative-serving-upgrade-tests

@mdemirhan

Copy link
Copy Markdown
Contributor

@greghaynes sorry that this one took really long to review and get in. I have one more concern regarding the user of openzipkin library rather than opencensus: we use opencensus everywhere else and using openzipkin library here in favor of opencensus will limit our ability to support backends other than zipkin in the future. I would much prefer if we can use OpenCensus here and have the ability to support other backends easily in the future.

@greghaynes
greghaynes force-pushed the autoscaler-tracing branch 2 times, most recently from 92d8d0f to 81540c9 Compare April 15, 2019 21:40
@greghaynes

Copy link
Copy Markdown
Contributor Author

@mdemirhan PTAL - I reworked to be based on open census. It does make use of Zipkin directly for setup, I'm thinking once someone wants to add support for $other_backend we can do the work to generalize that.

@greghaynes
greghaynes force-pushed the autoscaler-tracing branch 2 times, most recently from 9179afc to 03f6372 Compare April 18, 2019 21:24
In order to track cold-start progress we should record tracing data for
this codepath
@knative-metrics-robot

Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/tracing/config/tracing.go Do not exist 82.6%
pkg/tracing/http.go Do not exist 100.0%
pkg/tracing/opencensus.go Do not exist 89.4%
pkg/tracing/zipkin.go Do not exist 100.0%

@mdemirhan

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: greghaynes, markusthoemmes, mdemirhan

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

The pull request process is described here

Details 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

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. area/networking area/test-and-release It flags unit/e2e/conformance/perf test issues for product features cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activator should report progress to end to end traces