Created
July 9, 2026 07:44
-
-
Save florianl/082661d4cab4e078bac423c4cdfab185 to your computer and use it in GitHub Desktop.
Extend option to collector receiver
This file contains hidden or 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
| diff --git a/collector/config/config.go b/collector/config/config.go | |
| index 9dfc35a7..eb9730bc 100644 | |
| --- a/collector/config/config.go | |
| +++ b/collector/config/config.go | |
| @@ -70,6 +70,11 @@ type Config struct { | |
| ErrorMode ErrorMode `mapstructure:"error_mode"` | |
| OBIProcessCtx bool `mapstructure:"obi_process_ctx"` | |
| TargetCPUIDs string `mapstructure:"target_cpu_ids"` | |
| + | |
| + // Configuration options that users can not set directly: | |
| + // | |
| + // PinnedCPUIDs is derived from TargetCPUIDs during Validate | |
| + PinnedCPUIDs []int `mapstructure:"-"` | |
| } | |
| // Validate validates the config. | |
| @@ -127,6 +132,14 @@ func (cfg *Config) Validate() error { | |
| "should be in the range [0..1]. 0 disables jitter") | |
| } | |
| + if cfg.TargetCPUIDs != "" { | |
| + cpus, err := tracer.ReadCPURange(cfg.TargetCPUIDs) | |
| + if err != nil { | |
| + return fmt.Errorf("invalid argument for target_cpu_ids: %v", err) | |
| + } | |
| + cfg.PinnedCPUIDs = cpus | |
| + } | |
| + | |
| if !cfg.NoKernelVersionCheck { | |
| major, minor, patch, err := linux.GetCurrentKernelVersion() | |
| if err != nil { | |
| diff --git a/collector/config/config_test.go b/collector/config/config_test.go | |
| index 97c8f10f..c992b07a 100644 | |
| --- a/collector/config/config_test.go | |
| +++ b/collector/config/config_test.go | |
| @@ -117,6 +117,43 @@ func TestUnmarshalText(t *testing.T) { | |
| } | |
| } | |
| +func TestValidateTargetCPUIDs(t *testing.T) { | |
| + for _, tt := range []struct { | |
| + name string | |
| + targetCPUIDs string | |
| + wantPinned []int | |
| + wantErr bool | |
| + }{ | |
| + { | |
| + name: "empty leaves PinnedCPUIDs unset", | |
| + targetCPUIDs: "", | |
| + wantPinned: nil, | |
| + }, | |
| + { | |
| + name: "range and single values are parsed into PinnedCPUIDs", | |
| + targetCPUIDs: "0-2,6", | |
| + wantPinned: []int{0, 1, 2, 6}, | |
| + }, | |
| + { | |
| + name: "invalid range is rejected", | |
| + targetCPUIDs: "not-a-range", | |
| + wantErr: true, | |
| + }, | |
| + } { | |
| + t.Run(tt.name, func(t *testing.T) { | |
| + cfg := validConfig() | |
| + cfg.TargetCPUIDs = tt.targetCPUIDs | |
| + err := xconfmap.Validate(cfg) | |
| + if tt.wantErr { | |
| + require.Error(t, err) | |
| + return | |
| + } | |
| + require.NoError(t, err) | |
| + require.Equal(t, tt.wantPinned, cfg.PinnedCPUIDs) | |
| + }) | |
| + } | |
| +} | |
| + | |
| func TestValidateErrorMode(t *testing.T) { | |
| for _, tt := range []struct { | |
| name string | |
| diff --git a/internal/controller/config.go b/internal/controller/config.go | |
| index cbc7640b..2d13e652 100644 | |
| --- a/internal/controller/config.go | |
| +++ b/internal/controller/config.go | |
| @@ -5,7 +5,6 @@ import ( | |
| "fmt" | |
| "go.opentelemetry.io/ebpf-profiler/internal/log" | |
| - "go.opentelemetry.io/ebpf-profiler/tracer" | |
| "go.opentelemetry.io/collector/consumer/xconsumer" | |
| "go.opentelemetry.io/ebpf-profiler/collector/config" | |
| @@ -19,7 +18,6 @@ type Config struct { | |
| DisableTLS bool | |
| PprofAddr string | |
| Version bool | |
| - PinnedCPUIDs []int | |
| ExecutableReporter reporter.ExecutableReporter | |
| OnShutdown func() error | |
| @@ -44,13 +42,5 @@ func (cfg *Config) Dump() { | |
| // Validate runs validations on the provided configuration, and returns errors | |
| // if invalid values were provided. | |
| func (cfg *Config) Validate() error { | |
| - if cfg.TargetCPUIDs != "" { | |
| - cpus, err := tracer.ReadCPURange(cfg.TargetCPUIDs) | |
| - if err != nil { | |
| - return fmt.Errorf("invalid argument for target-cpu-ids: %v", err) | |
| - } | |
| - cfg.PinnedCPUIDs = cpus | |
| - } | |
| - | |
| return cfg.Config.Validate() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment