-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tracing support to in-memory dispatcher. (#1199)
* Add tracing support to in-memory dispatcher. * Remove ClusterRole configmaps.
- Loading branch information
1 parent
fd45b55
commit 64df1c3
Showing
38 changed files
with
3,005 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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-eventing | ||
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 example block and unindented to be in the data block | ||
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
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 tracing | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/knative/pkg/configmap" | ||
"github.com/knative/pkg/tracing" | ||
tracingconfig "github.com/knative/pkg/tracing/config" | ||
"github.com/openzipkin/zipkin-go" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// TODO Move this to knative/pkg. | ||
|
||
var ( | ||
// DebugCfg is a configuration to use to record all traces. | ||
DebugCfg = &tracingconfig.Config{ | ||
Enable: true, | ||
Debug: true, | ||
SampleRate: 1, | ||
ZipkinEndpoint: "http://zipkin.istio-system.svc.cluster.local:9411/api/v2/spans", | ||
} | ||
// EnabledZeroSampling is a configuration that enables tracing, but has a sampling rate of zero. | ||
// The intention is that this allows this to record traces that other components started, but | ||
// will not start traces itself. | ||
EnabledZeroSampling = &tracingconfig.Config{ | ||
Enable: true, | ||
Debug: false, | ||
SampleRate: 0, | ||
ZipkinEndpoint: "http://zipkin.istio-system.svc.cluster.local:9411/api/v2/spans", | ||
} | ||
) | ||
|
||
// setupZipkinPublishing sets up Zipkin trace publishing for the process. Note that other pieces | ||
// still need to generate the traces, this just ensures that if generated, they are collected | ||
// appropriately. This is normally done by using tracing.HTTPSpanMiddleware as a middleware HTTP | ||
// handler. | ||
func setupZipkinPublishing(serviceName string) (*tracing.OpenCensusTracer, error) { | ||
// TODO Should we fill in the hostPort? | ||
zipkinEndpoint, err := zipkin.NewEndpoint(serviceName, "") | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to create tracing endpoint: %v", err) | ||
} | ||
oct := tracing.NewOpenCensusTracer(tracing.WithZipkinExporter(tracing.CreateZipkinReporter, zipkinEndpoint)) | ||
return oct, nil | ||
} | ||
|
||
// SetupStaticZipkinPublishing sets up Zipkin trace publishing for the process. Note that other | ||
// pieces still need to generate the traces, this 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 not be dynamically updated. | ||
func SetupStaticZipkinPublishing(serviceName string, cfg *tracingconfig.Config) error { | ||
oct, err := setupZipkinPublishing(serviceName) | ||
if err != nil { | ||
return err | ||
} | ||
err = oct.ApplyConfig(cfg) | ||
if err != nil { | ||
return fmt.Errorf("unable to set OpenCensusTracing config: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
// SetupDynamicZipkinPublishing sets up Zipkin trace publishing for the process, by watching a | ||
// ConfigMap for the configuration. Note that other pieces still need to generate the traces, this | ||
// 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 SetupDynamicZipkinPublishing(logger *zap.SugaredLogger, configMapWatcher configmap.Watcher, serviceName string) error { | ||
oct, err := setupZipkinPublishing(serviceName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tracerUpdater := func(name string, value interface{}) { | ||
if name == tracingconfig.ConfigName { | ||
cfg := value.(*tracingconfig.Config) | ||
logger.Debugw("Updating tracing config", zap.Any("cfg", cfg)) | ||
err = oct.ApplyConfig(cfg) | ||
if err != nil { | ||
logger.Errorw("Unable to apply open census tracer config", zap.Error(err)) | ||
return | ||
} | ||
} | ||
} | ||
|
||
// Set up our config store. | ||
configStore := configmap.NewUntypedStore( | ||
"tracing-config", | ||
logger, | ||
configmap.Constructors{ | ||
tracingconfig.ConfigName: tracingconfig.NewTracingConfigFromConfigMap, | ||
}, | ||
tracerUpdater) | ||
configStore.WatchConfigs(configMapWatcher) | ||
return nil | ||
} |
Oops, something went wrong.