Repository navigation
Add tracing to activator - #2726
Conversation
knative-prow-robot
left a comment
There was a problem hiding this comment.
@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.
| return tracer, collector, nil | ||
| } | ||
|
|
||
| type Tracer struct { |
There was a problem hiding this comment.
Golint comments: exported type Tracer should have comment or be unexported. More info.
| collector zipkin.Collector | ||
| } | ||
|
|
||
| func CreateTracer(logger *zap.SugaredLogger) (*Tracer, error) { |
There was a problem hiding this comment.
Golint comments: exported function CreateTracer should have comment or be unexported. More info.
| }, nil | ||
| } | ||
|
|
||
| func (t *Tracer) CreateSpanFromRequest(logger *zap.SugaredLogger, r *http.Request, opName string) opentracing.Span { |
There was a problem hiding this comment.
Golint comments: exported method Tracer.CreateSpanFromRequest should have comment or be unexported. More info.
| ext.RPCServerOption(wireContext)) | ||
| } | ||
|
|
||
| func (t *Tracer) Close() { |
There was a problem hiding this comment.
Golint comments: exported method Tracer.Close should have comment or be unexported. More info.
| t.collector.Close() | ||
| } | ||
|
|
||
| type SpanHandler struct { |
There was a problem hiding this comment.
Golint comments: exported type SpanHandler should have comment or be unexported. More info.
db717b9 to
a458973
Compare
dcb02db to
50b2de4
Compare
50b2de4 to
4604da1
Compare
|
Sorry for the huge LOC - its mostly due to vendor deps. Suggestions welcome for ways to reduce that :) |
| cfg := config.FromContext(ctx) | ||
| ref, err := tracerCache.GetTracer(cfg.Tracing) | ||
| if err != nil { | ||
| logger.Errorf("Unable to create tracer from tracer config: %v", err) |
There was a problem hiding this comment.
logger.Errorw(..., zap.Error(err))
| <-stopCh | ||
| a.Shutdown() | ||
| srv.Shutdown(context.TODO()) | ||
| tracerCache.Close() |
There was a problem hiding this comment.
why not just defer tracerCache.Close() right after creation?
| @@ -0,0 +1,84 @@ | |||
| /* | |||
| Copyright 2018 The Knative Authors. | |||
There was a problem hiding this comment.
2019 here and elsewhere.
| 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) |
markusthoemmes
left a comment
There was a problem hiding this comment.
Quite the diff indeed, made a first pass and the general approach looked good. Left a few driveby comments.
| if tc.cfg == nil || !tc.cfg.Equals(cfg) { | ||
| tracer, err := CreateZipkinTracer(cfg) | ||
| if err != nil { | ||
| tc.tracerRef.refs.RLock() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Do we really want to abort all HTTP requests if we fail to get a tracer?
|
|
||
| tracer := tracerRef.Tracer.Tracer | ||
| activateSpan := tracing.CreateChildSpanFromContext(tracer, ctx, "active_endpoint") | ||
| a.Logger.Errorf("Activator: %v", a.Activator) |
| }, | ||
| } | ||
|
|
||
| mt := mocktracer.New() |
There was a problem hiding this comment.
Does this support testing in some way so we can assert that the correct spans are written by the handler?
There was a problem hiding this comment.
Yep: https://github.com/knative/serving/pull/2726/files#diff-7f39da0d0657bca12dc88b4f9c71dcdfR91 does it for the middleware, I can make a similar test for this.
|
|
||
| const ( | ||
| serviceName = "activator" | ||
| myHostPort = "127.0.0.1:61001" |
There was a problem hiding this comment.
Where is this coming from?
| ) | ||
|
|
||
| const ( | ||
| serviceName = "activator" |
There was a problem hiding this comment.
Does this mean we cannot instrument other components? Should this name be passed via CreateZipkinTracer?
4604da1 to
5c1babe
Compare
5c1babe to
248ec29
Compare
3390d18 to
2d6d60b
Compare
|
I think I covered the outstanding comments, LMK if I missed something |
2d6d60b to
ce552a2
Compare
| defer tracerCache.Close() | ||
| trGetter := func(ctx context.Context) *tracing.TracerRef { | ||
| cfg := config.FromContext(ctx) | ||
| return tracerCache.GetTracerRefOrNoop(logger, cfg.Tracing, "activator", "localhost:1234") |
There was a problem hiding this comment.
localhost:1234 looks like a dummy value?
| component = "activator" | ||
|
|
||
| // This is the number of times we will perform network probes to | ||
| // see if the Revision is accessible before forwarding the actual |
There was a problem hiding this comment.
Was this removed by accident?
markusthoemmes
left a comment
There was a problem hiding this comment.
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.
552114d to
d792919
Compare
| } | ||
| } | ||
|
|
||
| // TracingEnabledForContext returns true if tracing is enabled in the Configuration injected in to ctx |
There was a problem hiding this comment.
You return two booleans, so comment needs to be updated.
| attempts int | ||
| ) | ||
|
|
||
| probeSpan, reqCtx := tracer.StartSpanFromContext(r.Context(), "probe") |
There was a problem hiding this comment.
what if move this into its own function then
- this function will become more readable
- we can do
probespan, ... defer probespan.finish()
| zipkinhttp "github.com/openzipkin/zipkin-go/middleware/http" | ||
| ) | ||
|
|
||
| // TracerRefGetter retrurns a tracer gien a context containing a tracer config |
There was a problem hiding this comment.
| // TracerRefGetter retrurns a tracer gien a context containing a tracer config | |
| // TracerRefGetter retrurns a tracer given a context containing a tracer config |
| type spanHandler struct { | ||
| opName string | ||
| next http.Handler | ||
| TRGetter TracerRefGetter |
There was a problem hiding this comment.
Is there a reason for this to be public?
| TRGetter TracerRefGetter | ||
| } | ||
|
|
||
| // ServeHTTP is an http handler which injects a tracing span using a TracerRefGetter |
There was a problem hiding this comment.
| // 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
left a comment
There was a problem hiding this comment.
Just saw another PR that fixed some of those and remembered I'd seen something odd here 😂
cbbf698 to
b322caf
Compare
|
/test pull-knative-serving-upgrade-tests |
|
@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. |
92d8d0f to
81540c9
Compare
|
@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. |
9179afc to
03f6372
Compare
In order to track cold-start progress we should record tracing data for this codepath
03f6372 to
d41c421
Compare
|
The following is the coverage report on pkg/.
|
|
/lgtm |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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