Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 29 additions & 3 deletions cmd/activator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/knative/pkg/websocket"
"github.com/knative/serving/cmd/util"
"github.com/knative/serving/pkg/activator"
activatorconfig "github.com/knative/serving/pkg/activator/config"
activatorhandler "github.com/knative/serving/pkg/activator/handler"
activatorutil "github.com/knative/serving/pkg/activator/util"
"github.com/knative/serving/pkg/apis/networking"
Expand All @@ -52,7 +53,10 @@ import (
"github.com/knative/serving/pkg/queue"
"github.com/knative/serving/pkg/reconciler"
"github.com/knative/serving/pkg/resources"
"github.com/knative/serving/pkg/tracing"
tracingconfig "github.com/knative/serving/pkg/tracing/config"

"github.com/openzipkin/zipkin-go"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/wait"
kubeinformers "k8s.io/client-go/informers"
Expand Down Expand Up @@ -124,11 +128,11 @@ func main() {
if err != nil {
log.Fatalf("Error loading logging configuration: %v", err)
}
config, err := logging.NewConfigFromMap(cm)
logConfig, err := logging.NewConfigFromMap(cm)
if err != nil {
log.Fatalf("Error parsing logging configuration: %v", err)
}
createdLogger, atomicLevel := logging.NewLoggerFromConfig(config, component)
createdLogger, atomicLevel := logging.NewLoggerFromConfig(logConfig, component)
logger := createdLogger.With(zap.String(logkey.ControllerType, "activator"))
defer logger.Sync()

Expand Down Expand Up @@ -240,6 +244,27 @@ func main() {
Handler: handler,
})

activatorL3 := fmt.Sprintf("%s:%d", activator.K8sServiceName, activator.ServicePortHTTP1)
zipkinEndpoint, err := zipkin.NewEndpoint("activator", activatorL3)
if err != nil {
logger.Error("Unable to create tracing endpoint")
return
}
oct := tracing.NewOpenCensusTracer(
tracing.WithZipkinExporter(tracing.CreateZipkinReporter, zipkinEndpoint),
)
tracerUpdater := func(name string, value interface{}) {
if name == tracingconfig.ConfigName {
cfg := value.(*tracingconfig.Config)
oct.ApplyConfig(cfg)
}
}

// Set up our config store
configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace())
configStore := activatorconfig.NewStore(createdLogger, tracerUpdater)
configStore.WatchConfigs(configMapWatcher)

// Open a websocket connection to the autoscaler
autoscalerEndpoint := fmt.Sprintf("ws://%s.%s.svc.%s:%d", "autoscaler", system.Namespace(), network.GetClusterDomainName(), autoscalerPort)
logger.Info("Connecting to autoscaler at", autoscalerEndpoint)
Expand Down Expand Up @@ -267,11 +292,12 @@ func main() {
GetService: serviceGetter,
}
ah = activatorhandler.NewRequestEventHandler(reqChan, ah)
ah = tracing.HTTPSpanMiddleware("handle_request", ah)
ah = configStore.HTTPMiddleware(ah)
ah = &activatorhandler.HealthHandler{HealthCheck: statSink.Status, NextHandler: ah}
ah = &activatorhandler.ProbeHandler{NextHandler: ah}

// Watch the logging config map and dynamically update logging levels.
configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace())
configMapWatcher.Watch(logging.ConfigMapName(), logging.UpdateLevelFromConfigMap(logger, atomicLevel, component))
// Watch the observability config map and dynamically update metrics exporter.
configMapWatcher.Watch(metrics.ObservabilityConfigName, metrics.UpdateExporterFromConfigMap(component, logger))
Expand Down
50 changes: 50 additions & 0 deletions config/config-tracing.yaml
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
Comment thread
greghaynes marked this conversation as resolved.
Resolved
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"
2 changes: 2 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ ${GOPATH}/bin/deepcopy-gen \
-i github.com/knative/serving/pkg/reconciler/v1alpha1/configuration/config \
-i github.com/knative/serving/pkg/reconciler/v1alpha1/revision/config \
-i github.com/knative/serving/pkg/reconciler/v1alpha1/route/config \
-i github.com/knative/serving/pkg/tracing/config \
-i github.com/knative/serving/pkg/activator/config \
-i github.com/knative/serving/pkg/autoscaler \
-i github.com/knative/serving/pkg/gc \
-i github.com/knative/serving/pkg/logging \
Expand Down
19 changes: 19 additions & 0 deletions pkg/activator/config/doc.go
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
103 changes: 103 additions & 0 deletions pkg/activator/config/store.go
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 {
Comment thread
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 {
Comment thread
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

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: 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) {
Comment thread
greghaynes marked this conversation as resolved.
Resolved
cfg := FromContext(ctx)
if cfg == nil {
return false, false
}

return cfg.Tracing.Enable, true
}
46 changes: 46 additions & 0 deletions pkg/activator/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading