Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify Cilium only if TC is going to be enabled (#1584) #1585

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/beyla/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ func (c *Config) Validate() error {
if !c.EBPF.TCBackend.Valid() {
return ConfigError("Invalid BEYLA_BPF_TC_BACKEND value")
}
if err := tcmanager.EnsureCiliumCompatibility(c.EBPF.TCBackend); err != nil {
return ConfigError(fmt.Sprintf("Cilium compatibility error: %s", err.Error()))
if c.willUseTC() {
if err := tcmanager.EnsureCiliumCompatibility(c.EBPF.TCBackend); err != nil {
return ConfigError(fmt.Sprintf("Cilium compatibility error: %s", err.Error()))
}
}

if c.Attributes.Kubernetes.InformersSyncTimeout == 0 {
Expand Down Expand Up @@ -303,6 +305,10 @@ func (c *Config) otelNetO11yEnabled() bool {
return (c.Metrics.Enabled() || c.Grafana.OTLP.MetricsEnabled()) && c.Metrics.NetworkMetricsEnabled()
}

func (c *Config) willUseTC() bool {
return c.EBPF.ContextPropagationEnabled || (c.Enabled(FeatureNetO11y) && c.NetworkFlows.Source == EbpfSourceTC)
}

// Enabled checks if a given Beyla feature is enabled according to the global configuration
func (c *Config) Enabled(feature Feature) bool {
switch feature {
Expand Down
18 changes: 18 additions & 0 deletions pkg/beyla/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,24 @@ func TestDefaultExclusionFilter(t *testing.T) {
assert.True(t, c[0].Path.MatchString("/usr/bin/otelcol-contrib123"))
}

func TestWillUseTC(t *testing.T) {
env := envMap{"BEYLA_BPF_ENABLE_CONTEXT_PROPAGATION": "true"}
cfg := loadConfig(t, env)
assert.True(t, cfg.willUseTC())

env = envMap{"BEYLA_BPF_ENABLE_CONTEXT_PROPAGATION": "false"}
cfg = loadConfig(t, env)
assert.False(t, cfg.willUseTC())

env = envMap{"BEYLA_BPF_ENABLE_CONTEXT_PROPAGATION": "false", "BEYLA_NETWORK_METRICS": "true"}
cfg = loadConfig(t, env)
assert.False(t, cfg.willUseTC())

env = envMap{"BEYLA_BPF_ENABLE_CONTEXT_PROPAGATION": "false", "BEYLA_NETWORK_SOURCE": "tc", "BEYLA_NETWORK_METRICS": "true"}
cfg = loadConfig(t, env)
assert.True(t, cfg.willUseTC())
}

func loadConfig(t *testing.T, env envMap) *Config {
for k, v := range env {
require.NoError(t, os.Setenv(k, v))
Expand Down
Loading