Skip to content

Commit

Permalink
apis/v1alpha1: rename instrumentation sampler config
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <[email protected]>
  • Loading branch information
frzifus committed Sep 11, 2024
1 parent e203cbc commit 86a975c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ type InstrumentationSpec struct {
// +optional
Propagators []Propagator `json:"propagators,omitempty"`

// Sampler defines sampling configuration.
// SamplerConfig defines sampling configuration.
// +optional
Sampler `json:"sampler,omitempty"`
SamplerConfig `json:"sampler,omitempty"`

// Env defines common env vars. There are four layers for env vars' definitions and
// the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`.
Expand Down Expand Up @@ -98,8 +98,8 @@ type Exporter struct {
Endpoint string `json:"endpoint,omitempty"`
}

// Sampler defines sampling configuration.
type Sampler struct {
// SamplerConfig defines sampling configuration.
type SamplerConfig struct {
// Type defines sampler type.
// The value will be set in the OTEL_TRACES_SAMPLER env var.
// The value can be for instance parentbased_always_on, parentbased_always_off, parentbased_traceidratio...
Expand Down
18 changes: 9 additions & 9 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,32 +209,32 @@ func (w InstrumentationWebhook) defaulter(r *Instrumentation) error {

func (w InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings, error) {
var warnings []string
switch r.Spec.Sampler.Type {
switch r.Spec.SamplerConfig.Type {
case "":
warnings = append(warnings, "sampler type not set")
case TraceIDRatio, ParentBasedTraceIDRatio:
if r.Spec.Sampler.Argument != "" {
rate, err := strconv.ParseFloat(r.Spec.Sampler.Argument, 64)
if r.Spec.SamplerConfig.Argument != "" {
rate, err := strconv.ParseFloat(r.Spec.SamplerConfig.Argument, 64)
if err != nil {
return warnings, fmt.Errorf("spec.sampler.argument is not a number: %s", r.Spec.Sampler.Argument)
return warnings, fmt.Errorf("spec.sampler.argument is not a number: %s", r.Spec.SamplerConfig.Argument)
}
if rate < 0 || rate > 1 {
return warnings, fmt.Errorf("spec.sampler.argument should be in rage [0..1]: %s", r.Spec.Sampler.Argument)
return warnings, fmt.Errorf("spec.sampler.argument should be in rage [0..1]: %s", r.Spec.SamplerConfig.Argument)
}
}
case JaegerRemote, ParentBasedJaegerRemote:
// value is a comma separated list of endpoint, pollingIntervalMs, initialSamplingRate
// Example: `endpoint=http://localhost:14250,pollingIntervalMs=5000,initialSamplingRate=0.25`
if r.Spec.Sampler.Argument != "" {
err := validateJaegerRemoteSamplerArgument(r.Spec.Sampler.Argument)
if r.Spec.SamplerConfig.Argument != "" {
err := validateJaegerRemoteSamplerArgument(r.Spec.SamplerConfig.Argument)

if err != nil {
return warnings, fmt.Errorf("spec.sampler.argument is not a valid argument for sampler %s: %w", r.Spec.Sampler.Type, err)
return warnings, fmt.Errorf("spec.sampler.argument is not a valid argument for sampler %s: %w", r.Spec.SamplerConfig.Type, err)
}
}
case AlwaysOn, AlwaysOff, ParentBasedAlwaysOn, ParentBasedAlwaysOff, XRaySampler:
default:
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Sampler.Type)
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.SamplerConfig.Type)
}
return warnings, nil
}
Expand Down
12 changes: 6 additions & 6 deletions apis/v1alpha1/instrumentation_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
name: "sampler configuration not present",
inst: Instrumentation{
Spec: InstrumentationSpec{
Sampler: Sampler{},
SamplerConfig: SamplerConfig{},
},
},
warnings: []string{"sampler type not set"},
Expand All @@ -73,7 +73,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
err: "spec.sampler.argument is not a number",
inst: Instrumentation{
Spec: InstrumentationSpec{
Sampler: Sampler{
SamplerConfig: SamplerConfig{
Type: ParentBasedTraceIDRatio,
Argument: "abc",
},
Expand All @@ -85,7 +85,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
err: "spec.sampler.argument should be in rage [0..1]",
inst: Instrumentation{
Spec: InstrumentationSpec{
Sampler: Sampler{
SamplerConfig: SamplerConfig{
Type: ParentBasedTraceIDRatio,
Argument: "1.99",
},
Expand All @@ -96,7 +96,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
name: "argument is a number",
inst: Instrumentation{
Spec: InstrumentationSpec{
Sampler: Sampler{
SamplerConfig: SamplerConfig{
Type: ParentBasedTraceIDRatio,
Argument: "0.99",
},
Expand All @@ -107,7 +107,7 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
name: "argument is missing",
inst: Instrumentation{
Spec: InstrumentationSpec{
Sampler: Sampler{
SamplerConfig: SamplerConfig{
Type: ParentBasedTraceIDRatio,
},
},
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestInstrumentationJaegerRemote(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
inst := Instrumentation{
Spec: InstrumentationSpec{
Sampler: Sampler{
SamplerConfig: SamplerConfig{
Type: sampler,
Argument: test.arg,
},
Expand Down
8 changes: 4 additions & 4 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Enum=tracecontext;baggage;b3;b3multi;jaeger;xray;ottrace;none<br/>
<td><b><a href="#instrumentationspecsampler">sampler</a></b></td>
<td>object</td>
<td>
Sampler defines sampling configuration.<br/>
SamplerConfig defines sampling configuration.<br/>
</td>
<td>false</td>
</tr></tbody>
Expand Down Expand Up @@ -4016,7 +4016,7 @@ For example environment: dev<br/>



Sampler defines sampling configuration.
SamplerConfig defines sampling configuration.

<table>
<thead>
Expand Down
8 changes: 4 additions & 4 deletions pkg/instrumentation/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,17 @@ func (i *sdkInjector) injectCommonSDKConfig(ctx context.Context, otelinst v1alph

idx = getIndexOfEnv(container.Env, constants.EnvOTELTracesSampler)
// configure sampler only if it is configured in the CR
if idx == -1 && otelinst.Spec.Sampler.Type != "" {
if idx == -1 && otelinst.Spec.SamplerConfig.Type != "" {
idxSamplerArg := getIndexOfEnv(container.Env, constants.EnvOTELTracesSamplerArg)
if idxSamplerArg == -1 {
container.Env = append(container.Env, corev1.EnvVar{
Name: constants.EnvOTELTracesSampler,
Value: string(otelinst.Spec.Sampler.Type),
Value: string(otelinst.Spec.SamplerConfig.Type),
})
if otelinst.Spec.Sampler.Argument != "" {
if otelinst.Spec.SamplerConfig.Argument != "" {
container.Env = append(container.Env, corev1.EnvVar{
Name: constants.EnvOTELTracesSamplerArg,
Value: otelinst.Spec.Sampler.Argument,
Value: otelinst.Spec.SamplerConfig.Argument,
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/instrumentation/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestSDKInjection(t *testing.T) {
AddK8sUIDAttributes: true,
},
Propagators: []v1alpha1.Propagator{"b3", "jaeger"},
Sampler: v1alpha1.Sampler{
SamplerConfig: v1alpha1.SamplerConfig{
Type: "parentbased_traceidratio",
Argument: "0.25",
},
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestSDKInjection(t *testing.T) {
},
},
Propagators: []v1alpha1.Propagator{"jaeger"},
Sampler: v1alpha1.Sampler{
SamplerConfig: v1alpha1.SamplerConfig{
Type: "parentbased_traceidratio",
Argument: "0.25",
},
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestSDKInjection(t *testing.T) {
},
},
Propagators: []v1alpha1.Propagator{"jaeger"},
Sampler: v1alpha1.Sampler{
SamplerConfig: v1alpha1.SamplerConfig{
Type: "parentbased_traceidratio",
Argument: "0.25",
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/instrumentation/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestUpgrade(t *testing.T) {
Namespace: nsName,
},
Spec: v1alpha1.InstrumentationSpec{
Sampler: v1alpha1.Sampler{
SamplerConfig: v1alpha1.SamplerConfig{
Type: v1alpha1.ParentBasedAlwaysOff,
},
},
Expand Down

0 comments on commit 86a975c

Please sign in to comment.