Skip to content

Commit c2c907e

Browse files
committed
config file support
Signed-off-by: Muxian Wu <muxianw@twitter.com>
1 parent 9957099 commit c2c907e

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Allow configurable client_sampling and random_sampling for tracing
2+
3+
Added support for configuring client_sampling and random_sampling in Contour's tracing configuration, allowing more granular control over trace sampling rates as per Envoy's tracing documentation.

cmd/contour/servecontext.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_v1alpha1.Co
413413
IncludePodDetail: ctx.Config.Tracing.IncludePodDetail,
414414
ServiceName: ctx.Config.Tracing.ServiceName,
415415
OverallSampling: ctx.Config.Tracing.OverallSampling,
416+
ClientSampling: ctx.Config.Tracing.ClientSampling,
417+
RandomSampling: ctx.Config.Tracing.RandomSampling,
416418
MaxPathTagLength: ctx.Config.Tracing.MaxPathTagLength,
417419
CustomTags: customTags,
418420
ExtensionService: &contour_v1alpha1.NamespacedName{

cmd/contour/servecontext_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ func TestConvertServeContext(t *testing.T) {
833833
IncludePodDetail: ptr.To(false),
834834
ServiceName: ptr.To("contour"),
835835
OverallSampling: ptr.To("100"),
836+
ClientSampling: ptr.To("100"),
837+
RandomSampling: ptr.To("100"),
836838
MaxPathTagLength: ptr.To(uint32(256)),
837839
CustomTags: []config.CustomTag{
838840
{
@@ -853,6 +855,8 @@ func TestConvertServeContext(t *testing.T) {
853855
IncludePodDetail: ptr.To(false),
854856
ServiceName: ptr.To("contour"),
855857
OverallSampling: ptr.To("100"),
858+
ClientSampling: ptr.To("100"),
859+
RandomSampling: ptr.To("100"),
856860
MaxPathTagLength: ptr.To(uint32(256)),
857861
CustomTags: []*contour_v1alpha1.CustomTag{
858862
{

pkg/config/parameters.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"io"
2020
"os"
2121
"path/filepath"
22+
"strconv"
2223
"strings"
2324
"time"
2425

@@ -727,6 +728,14 @@ type Tracing struct {
727728
// the default value is 100.
728729
OverallSampling *string `yaml:"overallSampling,omitempty"`
729730

731+
// ClientSampling defines the client sampling rate of trace data.
732+
// the default value is 100.
733+
ClientSampling *string `yaml:"clientSampling,omitempty"`
734+
735+
// RandomSampling defines the random sampling rate of trace data.
736+
// the default value is 100.
737+
RandomSampling *string `yaml:"randomSampling,omitempty"`
738+
730739
// MaxPathTagLength defines maximum length of the request path
731740
// to extract and include in the HttpUrl tag.
732741
// the default value is 256.
@@ -908,6 +917,20 @@ func (t *Tracing) Validate() error {
908917
return errors.New("tracing.extensionService must be defined")
909918
}
910919

920+
if t.ClientSampling != nil {
921+
_, err := strconv.ParseFloat(*t.ClientSampling, 64)
922+
if err != nil {
923+
return fmt.Errorf("invalid tracing client sampling: %v", err)
924+
}
925+
}
926+
927+
if t.RandomSampling != nil {
928+
_, err := strconv.ParseFloat(*t.RandomSampling, 64)
929+
if err != nil {
930+
return fmt.Errorf("invalid tracing random sampling: %v", err)
931+
}
932+
}
933+
911934
var customTagNames []string
912935

913936
for _, customTag := range t.CustomTags {

pkg/config/parameters_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ func TestTracingConfigValidation(t *testing.T) {
682682
IncludePodDetail: ptr.To(false),
683683
ServiceName: ptr.To("contour"),
684684
OverallSampling: ptr.To("100"),
685+
ClientSampling: ptr.To("100"),
686+
RandomSampling: ptr.To("100"),
685687
MaxPathTagLength: ptr.To(uint32(256)),
686688
CustomTags: nil,
687689
ExtensionService: "projectcontour/otel-collector",
@@ -692,6 +694,8 @@ func TestTracingConfigValidation(t *testing.T) {
692694
IncludePodDetail: ptr.To(false),
693695
ServiceName: ptr.To("contour"),
694696
OverallSampling: ptr.To("100"),
697+
ClientSampling: ptr.To("100"),
698+
RandomSampling: ptr.To("100"),
695699
MaxPathTagLength: ptr.To(uint32(256)),
696700
CustomTags: nil,
697701
}
@@ -700,6 +704,8 @@ func TestTracingConfigValidation(t *testing.T) {
700704
trace = &Tracing{
701705
IncludePodDetail: ptr.To(false),
702706
OverallSampling: ptr.To("100"),
707+
ClientSampling: ptr.To("100"),
708+
RandomSampling: ptr.To("100"),
703709
MaxPathTagLength: ptr.To(uint32(256)),
704710
CustomTags: nil,
705711
ExtensionService: "projectcontour/otel-collector",
@@ -708,6 +714,8 @@ func TestTracingConfigValidation(t *testing.T) {
708714

709715
trace = &Tracing{
710716
OverallSampling: ptr.To("100"),
717+
ClientSampling: ptr.To("100"),
718+
RandomSampling: ptr.To("100"),
711719
MaxPathTagLength: ptr.To(uint32(256)),
712720
CustomTags: []CustomTag{
713721
{
@@ -722,6 +730,8 @@ func TestTracingConfigValidation(t *testing.T) {
722730

723731
trace = &Tracing{
724732
OverallSampling: ptr.To("100"),
733+
ClientSampling: ptr.To("100"),
734+
RandomSampling: ptr.To("100"),
725735
MaxPathTagLength: ptr.To(uint32(256)),
726736
CustomTags: []CustomTag{
727737
{
@@ -735,6 +745,8 @@ func TestTracingConfigValidation(t *testing.T) {
735745
trace = &Tracing{
736746
IncludePodDetail: ptr.To(true),
737747
OverallSampling: ptr.To("100"),
748+
ClientSampling: ptr.To("100"),
749+
RandomSampling: ptr.To("100"),
738750
MaxPathTagLength: ptr.To(uint32(256)),
739751
CustomTags: []CustomTag{
740752
{

0 commit comments

Comments
 (0)