Skip to content

Commit

Permalink
optional sampling value
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubdyszkiewicz committed Feb 21, 2020
1 parent 7317306 commit ae11c40
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
83 changes: 43 additions & 40 deletions api/mesh/v1alpha1/mesh.pb.go

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

6 changes: 4 additions & 2 deletions api/mesh/v1alpha1/mesh.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package kuma.mesh.v1alpha1;
option go_package = "v1alpha1";

import "mesh/v1alpha1/metrics.proto";
import "google/protobuf/wrappers.proto";

// Mesh defines configuration of a single mesh.
message Mesh {
Expand Down Expand Up @@ -81,8 +82,9 @@ message TracingBackend {
// TrafficTrace
string name = 1;

// Percentage of traces that will be sent to the backend (range 0.0 - 100.0)
double sampling = 2;
// Percentage of traces that will be sent to the backend (range 0.0 - 100.0).
// Empty value defaults to 100.0%
google.protobuf.DoubleValue sampling = 2;

// Zipkin defined configuration of Zipkin tracer.
message Zipkin {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/resources/apis/mesh/mesh_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func validateTracingBackend(backend *mesh_proto.TracingBackend) validators.Valid
if backend.Name == "" {
verr.AddViolation("name", "cannot be empty")
}
if backend.Sampling < 0.0 || backend.Sampling > 100.0 {
if backend.Sampling.GetValue() < 0.0 || backend.Sampling.GetValue() > 100.0 {
verr.AddViolation("sampling", "has to be in [0.0 - 100.0] range")
}
if zipkin, ok := backend.GetType().(*mesh_proto.TracingBackend_Zipkin_); ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/xds/envoy/listeners/tracing_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (c *TracingConfigurer) Configure(filterChain *envoy_listener.FilterChain) e

return UpdateHTTPConnectionManager(filterChain, func(hcm *envoy_hcm.HttpConnectionManager) error {
hcm.Tracing = &envoy_hcm.HttpConnectionManager_Tracing{}
if c.backend.Sampling != 0.0 {
if c.backend.Sampling != nil {
hcm.Tracing.OverallSampling = &envoy_type.Percent{
Value: c.backend.Sampling,
Value: c.backend.Sampling.Value,
}
}
return nil
Expand Down
10 changes: 6 additions & 4 deletions pkg/xds/envoy/listeners/tracing_configurer_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package listeners

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
"github.com/golang/protobuf/ptypes/wrappers"

mesh_proto "github.com/Kong/kuma/api/mesh/v1alpha1"
util_proto "github.com/Kong/kuma/pkg/util/proto"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)

var _ = Describe("TracingConfigurer", func() {
Expand Down Expand Up @@ -37,7 +39,7 @@ var _ = Describe("TracingConfigurer", func() {
Entry("backend specified with sampling", testCase{
backend: &mesh_proto.TracingBackend{
Name: "zipkin",
Sampling: 30.5,
Sampling: &wrappers.DoubleValue{Value: 30.5},
Type: &mesh_proto.TracingBackend_Zipkin_{
Zipkin: &mesh_proto.TracingBackend_Zipkin{
Url: "http://zipkin.us:9090/v2/spans",
Expand Down

0 comments on commit ae11c40

Please sign in to comment.