Skip to content

Commit

Permalink
Merge branch 'open-telemetry-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
afek854 committed Oct 31, 2024
2 parents 64c3f2c + d7853fb commit 565539f
Show file tree
Hide file tree
Showing 71 changed files with 1,382 additions and 881 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.cache
/.idea
/go
.vscode
ebpf-profiler
ci-kernels
ebpf-profiler
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"typeinfo": "cpp"
}
}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ RUN
# Append to /etc/profile for login shells
RUN echo 'export PATH="/usr/local/go/bin:$PATH"' >> /etc/profile

RUN apt-get install -y libbpf-dev

ENTRYPOINT ["/bin/bash", "-l", "-c"]
21 changes: 6 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ export GOARCH = $(TARGET_ARCH)
export CC = $(ARCH_PREFIX)gcc
export OBJCOPY = $(ARCH_PREFIX)objcopy

# Add EXTERNAL flag support
ifdef EXTERNAL
export EXTERNAL
GO_TAGS := osusergo,netgo,external_trigger
else
GO_TAGS := osusergo,netgo
endif

BRANCH = $(shell git rev-parse --abbrev-ref HEAD | tr -d '-' | tr '[:upper:]' '[:lower:]')
COMMIT_SHORT_SHA = $(shell git rev-parse --short=8 HEAD)

Expand All @@ -52,11 +44,11 @@ LDFLAGS := -X go.opentelemetry.io/ebpf-profiler/vc.version=$(VERSION) \
-X go.opentelemetry.io/ebpf-profiler/vc.buildTimestamp=$(BUILD_TIMESTAMP) \
-extldflags=-static


GO_FLAGS := -buildvcs=false -ldflags="$(LDFLAGS)" -tags $(GO_TAGS)

GO_TAGS := osusergo,netgo
EBPF_FLAGS :=

GO_FLAGS := -buildvcs=false -ldflags="$(LDFLAGS)"

MAKEFLAGS += -j$(shell nproc)

all: ebpf-profiler
Expand All @@ -77,8 +69,7 @@ generate:
go generate ./...

ebpf:
$(MAKE) $(EBPF_FLAGS) -j$(shell nproc) -C support/ebpf EXTERNAL=external
$(MAKE) $(EBPF_FLAGS) -j$(shell nproc) -C support/ebpf
$(MAKE) $(EBPF_FLAGS) -C support/ebpf

ebpf-profiler: generate ebpf
go build $(GO_FLAGS) -tags $(GO_TAGS)
Expand Down Expand Up @@ -129,7 +120,7 @@ docker-image:

agent:
docker run -v "$$PWD":/agent -it --rm --user $(shell id -u):$(shell id -g) profiling-agent \
"make TARGET_ARCH=$(TARGET_ARCH) VERSION=$(VERSION) REVISION=$(REVISION) BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) $(if $(EXTERNAL),EXTERNAL=external)"
"make TARGET_ARCH=$(TARGET_ARCH) VERSION=$(VERSION) REVISION=$(REVISION) BUILD_TIMESTAMP=$(BUILD_TIMESTAMP)"

debug-agent:
docker run -v "$$PWD":/agent -it --rm --user $(shell id -u):$(shell id -g) profiling-agent \
Expand All @@ -141,4 +132,4 @@ legal:
@./legal/add-non-go.sh legal/non-go-dependencies.json LICENSES

codespell:
@codespell
@codespell
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ devfiler spins up a local server that listens on `0.0.0.0:11000`.

To run it, simply download and unpack the archive from the following URL:

https://upload.elastic.co/d/a3033fd2b515144b1c566961495302dac4da3223e59832f7755e18ac7fd94a19
https://upload.elastic.co/d/87e7697991940ec37f0c6e39ac38d213f65e8dc1ef9dbedff6aab9cba0adfaba

Authentication token: `c74dfc4db2212015`

Authentication token: `786a077d31b02bda`

The archive contains a build for each of the following platforms:

Expand Down
93 changes: 29 additions & 64 deletions cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/peterbourgon/ff/v3"
log "github.com/sirupsen/logrus"

"go.opentelemetry.io/ebpf-profiler/internal/controller"
"go.opentelemetry.io/ebpf-profiler/tracer"
)

Expand All @@ -27,23 +27,20 @@ const (

// This is the X in 2^(n + x) where n is the default hardcoded map size value
defaultArgMapScaleFactor = 0
// 1TB of executable address space
maxArgMapScaleFactor = 8
)

// Help strings for command line arguments
var (
noKernelVersionCheckHelp = "Disable checking kernel version for eBPF support. " +
"Use at your own risk, to run the agent on older kernels with backported eBPF features."
copyrightHelp = "Show copyright and short license text."
collAgentAddrHelp = "The collection agent address in the format of host:port."
verboseModeHelp = "Enable verbose logging and debugging capabilities."
tracersHelp = "Comma-separated list of interpreter tracers to include."
externallyManagedHelp = "Agent is externally managed."
mapScaleFactorHelp = fmt.Sprintf("Scaling factor for eBPF map sizes. "+
copyrightHelp = "Show copyright and short license text."
collAgentAddrHelp = "The collection agent address in the format of host:port."
verboseModeHelp = "Enable verbose logging and debugging capabilities."
tracersHelp = "Comma-separated list of interpreter tracers to include."
mapScaleFactorHelp = fmt.Sprintf("Scaling factor for eBPF map sizes. "+
"Every increase by 1 doubles the map size. Increase if you see eBPF map size errors. "+
"Default is %d corresponding to 4GB of executable address space, max is %d.",
defaultArgMapScaleFactor, maxArgMapScaleFactor)
defaultArgMapScaleFactor, controller.MaxArgMapScaleFactor)
disableTLSHelp = "Disable encryption for data in transit."
bpfVerifierLogLevelHelp = "Log level of the eBPF verifier output (0,1,2). Default is 0."
versionHelp = "Show version."
Expand All @@ -66,87 +63,62 @@ var (
sendErrorFramesHelp = "Send error frames (devfiler only, breaks Kibana)"
)

type arguments struct {
bpfVerifierLogLevel uint
collAgentAddr string
copyright bool
disableTLS bool
mapScaleFactor uint
monitorInterval time.Duration
clockSyncInterval time.Duration
noKernelVersionCheck bool
pprofAddr string
probabilisticInterval time.Duration
probabilisticThreshold uint
reporterInterval time.Duration
samplesPerSecond int
sendErrorFrames bool
tracers string
externallyManaged bool
verboseMode bool
version bool

fs *flag.FlagSet
}

// Package-scope variable, so that conditionally compiled other components can refer
// to the same flagset.

func parseArgs() (*arguments, error) {
var args arguments
func parseArgs() (*controller.Config, error) {
var args controller.Config

fs := flag.NewFlagSet("ebpf-profiler", flag.ExitOnError)

// Please keep the parameters ordered alphabetically in the source-code.
fs.UintVar(&args.bpfVerifierLogLevel, "bpf-log-level", 0, bpfVerifierLogLevelHelp)
fs.UintVar(&args.BpfVerifierLogLevel, "bpf-log-level", 0, bpfVerifierLogLevelHelp)

fs.StringVar(&args.collAgentAddr, "collection-agent", "", collAgentAddrHelp)
fs.BoolVar(&args.copyright, "copyright", false, copyrightHelp)
fs.StringVar(&args.CollAgentAddr, "collection-agent", "", collAgentAddrHelp)
fs.BoolVar(&args.Copyright, "copyright", false, copyrightHelp)

fs.BoolVar(&args.disableTLS, "disable-tls", false, disableTLSHelp)
fs.BoolVar(&args.DisableTLS, "disable-tls", false, disableTLSHelp)

fs.UintVar(&args.mapScaleFactor, "map-scale-factor",
fs.UintVar(&args.MapScaleFactor, "map-scale-factor",
defaultArgMapScaleFactor, mapScaleFactorHelp)

fs.DurationVar(&args.monitorInterval, "monitor-interval", defaultArgMonitorInterval,
fs.DurationVar(&args.MonitorInterval, "monitor-interval", defaultArgMonitorInterval,
monitorIntervalHelp)

fs.DurationVar(&args.clockSyncInterval, "clock-sync-interval", defaultClockSyncInterval,
fs.DurationVar(&args.ClockSyncInterval, "clock-sync-interval", defaultClockSyncInterval,
clockSyncIntervalHelp)

fs.BoolVar(&args.noKernelVersionCheck, "no-kernel-version-check", false,
fs.BoolVar(&args.NoKernelVersionCheck, "no-kernel-version-check", false,
noKernelVersionCheckHelp)

fs.StringVar(&args.pprofAddr, "pprof", "", pprofHelp)
fs.StringVar(&args.PprofAddr, "pprof", "", pprofHelp)

fs.DurationVar(&args.probabilisticInterval, "probabilistic-interval",
fs.DurationVar(&args.ProbabilisticInterval, "probabilistic-interval",
defaultProbabilisticInterval, probabilisticIntervalHelp)
fs.UintVar(&args.probabilisticThreshold, "probabilistic-threshold",
fs.UintVar(&args.ProbabilisticThreshold, "probabilistic-threshold",
defaultProbabilisticThreshold, probabilisticThresholdHelp)

fs.DurationVar(&args.reporterInterval, "reporter-interval", defaultArgReporterInterval,
fs.DurationVar(&args.ReporterInterval, "reporter-interval", defaultArgReporterInterval,
reporterIntervalHelp)

fs.IntVar(&args.samplesPerSecond, "samples-per-second", defaultArgSamplesPerSecond,
fs.IntVar(&args.SamplesPerSecond, "samples-per-second", defaultArgSamplesPerSecond,
samplesPerSecondHelp)

fs.BoolVar(&args.sendErrorFrames, "send-error-frames", defaultArgSendErrorFrames,
fs.BoolVar(&args.SendErrorFrames, "send-error-frames", defaultArgSendErrorFrames,
sendErrorFramesHelp)

fs.StringVar(&args.tracers, "t", "all", "Shorthand for -tracers.")
fs.StringVar(&args.tracers, "tracers", "all", tracersHelp)

fs.BoolVar(&args.externallyManaged, "externally-managed", false, externallyManagedHelp)
fs.StringVar(&args.Tracers, "t", "all", "Shorthand for -tracers.")
fs.StringVar(&args.Tracers, "tracers", "all", tracersHelp)

fs.BoolVar(&args.verboseMode, "v", false, "Shorthand for -verbose.")
fs.BoolVar(&args.verboseMode, "verbose", false, verboseModeHelp)
fs.BoolVar(&args.version, "version", false, versionHelp)
fs.BoolVar(&args.VerboseMode, "v", false, "Shorthand for -verbose.")
fs.BoolVar(&args.VerboseMode, "verbose", false, verboseModeHelp)
fs.BoolVar(&args.Version, "version", false, versionHelp)

fs.Usage = func() {
fs.PrintDefaults()
}

args.fs = fs
args.Fs = fs

return &args, ff.Parse(fs, os.Args[1:],
ff.WithEnvVarPrefix("OTEL_PROFILING_AGENT"),
Expand All @@ -158,10 +130,3 @@ func parseArgs() (*arguments, error) {
ff.WithAllowMissingConfigFile(true),
)
}

func (args *arguments) dump() {
log.Debug("Config:")
args.fs.VisitAll(func(f *flag.Flag) {
log.Debug(fmt.Sprintf("%s: %v", f.Name, f.Value))
})
}
Loading

0 comments on commit 565539f

Please sign in to comment.