Repository navigation
Add tracing to activator #2726
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
Add tracing to activator #2726
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright 2019 The Knative Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: config-tracing | ||
| namespace: knative-serving | ||
| labels: | ||
| serving.knative.dev/release: devel | ||
|
|
||
| data: | ||
| _example: | | ||
| ################################ | ||
| # # | ||
| # EXAMPLE CONFIGURATION # | ||
| # # | ||
| ################################ | ||
|
|
||
| # This block is not actually functional configuration, | ||
| # but serves to illustrate the available configuration | ||
| # options and document them in a way that is accessible | ||
| # to users that `kubectl edit` this config map. | ||
| # | ||
| # These sample configuration options may be copied out of | ||
| # this block and unindented to actually change the configuration. | ||
| # | ||
| # If true we enable adding spans within our applications. | ||
| enable: "false" | ||
|
|
||
| # URL to zipkin collector where traces are sent. | ||
| zipkin-endpoint: "http://zipkin.istio-system.svc.cluster.local:9411/api/v2/spans" | ||
|
|
||
| # Enable zipkin debug mode. This allows all spans to be sent to the server | ||
| # bypassing sampling. | ||
| debug: "false" | ||
|
|
||
| # Percentage (0-1) of requests to trace | ||
| sample-rate: "0.1" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| Copyright 2019 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // +k8s:deepcopy-gen=package | ||
|
|
||
| package config |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| Copyright 2019 The Knative Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package config | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
|
|
||
| "github.com/knative/pkg/configmap" | ||
| tracingconfig "github.com/knative/serving/pkg/tracing/config" | ||
| ) | ||
|
|
||
| type cfgKey struct{} | ||
|
|
||
| // Config is a configuration for the activator | ||
| type Config struct { | ||
|
greghaynes marked this conversation as resolved.
Resolved
|
||
| Tracing *tracingconfig.Config | ||
| } | ||
|
|
||
| // FromContext obtains a Config injected into the passed context | ||
| func FromContext(ctx context.Context) *Config { | ||
|
greghaynes marked this conversation as resolved.
Resolved
|
||
| return ctx.Value(cfgKey{}).(*Config) | ||
| } | ||
|
|
||
| func toContext(ctx context.Context, c *Config) context.Context { | ||
| return context.WithValue(ctx, cfgKey{}, c) | ||
| } | ||
|
|
||
| // +k8s:deepcopy-gen=false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: comment on exported type Store should be of the form "Store ..." (with optional leading article). More info. |
||
| // Store loads/unloads our untyped configuration | ||
| type Store struct { | ||
| *configmap.UntypedStore | ||
| } | ||
|
|
||
| // NewStore creates a configuration Store | ||
| func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value interface{})) *Store { | ||
| return &Store{ | ||
| UntypedStore: configmap.NewUntypedStore( | ||
| "activator", | ||
| logger, | ||
| configmap.Constructors{ | ||
| tracingconfig.ConfigName: tracingconfig.NewTracingConfigFromConfigMap, | ||
| }, | ||
| onAfterStore..., | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| // ToContext stores the configuration Store in the passed context | ||
| func (s *Store) ToContext(ctx context.Context) context.Context { | ||
| return toContext(ctx, s.Load()) | ||
| } | ||
|
|
||
| // Load creates a Config for this store | ||
| func (s *Store) Load() *Config { | ||
| return &Config{ | ||
| Tracing: s.UntypedLoad(tracingconfig.ConfigName).(*tracingconfig.Config).DeepCopy(), | ||
| } | ||
| } | ||
|
|
||
| type storeMiddleware struct { | ||
| store *Store | ||
| next http.Handler | ||
| } | ||
|
|
||
| // ServeHTTP injects Config in to the context of the http request r | ||
| func (mw *storeMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
| ctx := mw.store.ToContext(r.Context()) | ||
| mw.next.ServeHTTP(w, r.WithContext(ctx)) | ||
| } | ||
|
|
||
| // HTTPMiddleware is a middlewhere which stores the current config store in the request context | ||
| func (s *Store) HTTPMiddleware(next http.Handler) http.Handler { | ||
| return &storeMiddleware{ | ||
| store: s, | ||
| next: next, | ||
| } | ||
| } | ||
|
|
||
| // TracingEnabledForContext returns true if tracing is enabled in the Configuration and ok if configuration | ||
| // was able to be found in context | ||
| func TracingEnabledForContext(ctx context.Context) (bool, bool) { | ||
|
greghaynes marked this conversation as resolved.
Resolved
|
||
| cfg := FromContext(ctx) | ||
| if cfg == nil { | ||
| return false, false | ||
| } | ||
|
|
||
| return cfg.Tracing.Enable, true | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.