Skip to content

Commit

Permalink
Add config options
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelroquetto committed Jan 6, 2025
1 parent 48b12d4 commit bb1694d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/beyla/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/grafana/beyla/pkg/export/instrumentations"
"github.com/grafana/beyla/pkg/export/otel"
"github.com/grafana/beyla/pkg/export/prom"
"github.com/grafana/beyla/pkg/internal/ebpf/tcmanager"
"github.com/grafana/beyla/pkg/internal/filter"
"github.com/grafana/beyla/pkg/internal/imetrics"
"github.com/grafana/beyla/pkg/internal/infraolly/process"
Expand Down Expand Up @@ -48,6 +49,7 @@ var DefaultConfig = Config{
BatchLength: 100,
BatchTimeout: time.Second,
HTTPRequestTimeout: 30 * time.Second,
TCBackend: tcmanager.TCBackendTC,
},
Grafana: otel.GrafanaConfig{
OTLP: otel.GrafanaOTLP{
Expand Down Expand Up @@ -243,6 +245,10 @@ func (c *Config) Validate() error {
if c.EBPF.BatchLength == 0 {
return ConfigError("BEYLA_BPF_BATCH_LENGTH must be at least 1")
}
if !c.EBPF.TCBackend.Valid() {
return ConfigError("Invalid BEYLA_BPF_TC_BACKEND value")
}

if c.Attributes.Kubernetes.InformersSyncTimeout == 0 {
return ConfigError("BEYLA_KUBE_INFORMERS_SYNC_TIMEOUT duration must be greater than 0s")
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/config/ebpf_tracer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package config

import "time"
import (
"time"

"github.com/grafana/beyla/pkg/internal/ebpf/tcmanager"
)

// EBPFTracer configuration for eBPF programs
type EBPFTracer struct {
Expand Down Expand Up @@ -31,6 +35,10 @@ type EBPFTracer struct {
// Enables Linux Traffic Control probes for context propagation
UseTCForL7CP bool `yaml:"traffic_control_l7_context_propagation" env:"BEYLA_BPF_TC_L7_CP"`

// Select the TC attachment backend: accepted values are 'tc' (netlink),
// and 'tcx'
TCBackend tcmanager.TCBackend `yaml:"traffic_control_backend" env:"BEYLA_BPF_TC_BACKEND"`

// Disables Beyla black-box context propagation. Used for testing purposes only.
DisableBlackBoxCP bool `yaml:"disable_black_box_cp" env:"BEYLA_BPF_DISABLE_BLACK_BOX_CP"`

Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/httptracer/httptracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (p *Tracer) startTC(ctx context.Context) {
p.log.Error("cannot enable L7 context-propagation, kernel 5.17 or newer required")
}

p.tcManager = tcmanager.NewNetlinkManager()
p.tcManager = tcmanager.NewTCManager(p.cfg.EBPF.TCBackend)
p.tcManager.AddProgram("tc/tc_http_egress", p.bpfObjects.BeylaTcHttpEgress, tcmanager.AttachmentEgress)
p.tcManager.AddProgram("tc/tc_http_ingress", p.bpfObjects.BeylaTcHttpIngress, tcmanager.AttachmentIngress)
p.tcManager.Start(ctx)
Expand Down
42 changes: 42 additions & 0 deletions pkg/internal/ebpf/tcmanager/tcmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package tcmanager

import (
"context"
"fmt"
"log/slog"
"strings"
"sync"
"time"

Expand All @@ -11,6 +13,13 @@ import (
"github.com/grafana/beyla/pkg/internal/netolly/ifaces"
)

type TCBackend uint8

const (
TCBackendTC = TCBackend(iota + 1)
TCBackendTCX
)

type AttachmentType uint8

const (
Expand Down Expand Up @@ -64,3 +73,36 @@ func newTCManagerBase(component string) tcManagerBase {
wg: sync.WaitGroup{},
}
}

func NewTCManager(backend TCBackend) TCManager {
switch backend {
case TCBackendTC:
return NewNetlinkManager()
case TCBackendTCX:
return NewTCXManager()
}

return NewNetlinkManager() // default
}

func (b *TCBackend) UnmarshalText(text []byte) error {
switch strings.TrimSpace(string(text)) {
case "tc":
*b = TCBackendTC
return nil
case "tcx":
*b = TCBackendTCX
return nil
}

return fmt.Errorf("invalid TCBakend value: '%s'", text)
}

func (b TCBackend) Valid() bool {
switch b {
case TCBackendTC, TCBackendTCX:
return true
}

return false
}
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/tctracer/tctracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (p *Tracer) startTC(ctx context.Context) {

p.log.Info("enabling L4 context-propagation with Linux Traffic Control")

p.tcManager = tcmanager.NewNetlinkManager()
p.tcManager = tcmanager.NewTCManager(p.cfg.EBPF.TCBackend)
p.tcManager.AddProgram("tc/tc_egress", p.bpfObjects.BeylaAppEgress, tcmanager.AttachmentEgress)
p.tcManager.AddProgram("tc/tc_ingress", p.bpfObjects.BeylaAppIngress, tcmanager.AttachmentIngress)
p.tcManager.Start(ctx)
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/netolly/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func FlowsAgent(ctxInfo *global.ContextInfo, cfg *beyla.Config) (*Flows, error)
alog := alog()
alog.Info("initializing Flows agent")

tcManager := tcmanager.NewNetlinkManager()
tcManager := tcmanager.NewTCManager(cfg.EBPF.TCBackend)
tcManager.SetChannelBufferLen(cfg.ChannelBufferLen)
tcManager.SetPollPeriod(cfg.NetworkFlows.ListenPollPeriod)
tcManager.SetMonitorMode(monitorMode(cfg, alog))
Expand Down

0 comments on commit bb1694d

Please sign in to comment.