Skip to content

Commit

Permalink
Fix metrics (#2998)
Browse files Browse the repository at this point in the history
* Fix metrics

* Fix errors against parca-dev/opentelemetry-ebpf-profile HEAD

* update go.mod to point to github.com/parca-dev/opentelemetry-ebpf-profiler HEAD
  • Loading branch information
gnurizen authored Nov 12, 2024
1 parent 2e00ac0 commit 1dfbcf8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 71 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be
github.com/containerd/containerd v1.7.20
github.com/docker/docker v26.1.5+incompatible
github.com/elastic/go-freelru v0.13.0
github.com/elastic/go-freelru v0.15.0
github.com/gogo/protobuf v1.3.2
github.com/golang/snappy v0.0.4
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
Expand Down Expand Up @@ -149,4 +149,4 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace go.opentelemetry.io/ebpf-profiler => github.com/parca-dev/opentelemetry-ebpf-profiler v0.0.0-20241030163650-5b64dd57b3ea
replace go.opentelemetry.io/ebpf-profiler => github.com/parca-dev/opentelemetry-ebpf-profiler v0.0.0-20241107010347-d633df82a9a2
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/elastic/go-freelru v0.13.0 h1:TKKY6yCfNNNky7Pj9xZAOEpBcdNgZJfihEftOb55omg=
github.com/elastic/go-freelru v0.13.0/go.mod h1:bSdWT4M0lW79K8QbX6XY2heQYSCqD7THoYf82pT/H3I=
github.com/elastic/go-freelru v0.15.0 h1:Jo1aY8JAvpyxbTDJEudrsBfjFDaALpfVv8mxuh9sfvI=
github.com/elastic/go-freelru v0.15.0/go.mod h1:bSdWT4M0lW79K8QbX6XY2heQYSCqD7THoYf82pT/H3I=
github.com/elastic/go-perf v0.0.0-20241016160959-1342461adb4a h1:ymmtaN4bVCmKKeu4XEf6JEWNZKRXPMng1zjpKd+8rCU=
github.com/elastic/go-perf v0.0.0-20241016160959-1342461adb4a/go.mod h1:Nt+pnRYvf0POC+7pXsrv8ubsEOSsaipJP0zlz1Ms1RM=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
Expand Down Expand Up @@ -244,8 +244,8 @@ github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bl
github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
github.com/parca-dev/opentelemetry-ebpf-profiler v0.0.0-20241030163650-5b64dd57b3ea h1:HNLGar6f5Sy9DqZirDu4zIniX3Bg90GelQB9HKdhoRQ=
github.com/parca-dev/opentelemetry-ebpf-profiler v0.0.0-20241030163650-5b64dd57b3ea/go.mod h1:poOphaa9n1NeidFV425KI5PzP6Ho90LEkERlJqLBEpE=
github.com/parca-dev/opentelemetry-ebpf-profiler v0.0.0-20241107010347-d633df82a9a2 h1:ZcYFRGuhgf3od4taXiiYOSx4k5W3aoQD22kdv9jK6Ms=
github.com/parca-dev/opentelemetry-ebpf-profiler v0.0.0-20241107010347-d633df82a9a2/go.mod h1:LZs0Ai6k5IPICeMqXRDpr1uyW7NJnoXgyrlaQh36XSM=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
Expand Down
29 changes: 11 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ import (
"github.com/apache/arrow/go/v16/arrow/memory"
"github.com/armon/circbuf"
"github.com/common-nighthawk/go-figure"
"go.opentelemetry.io/ebpf-profiler/host"
otelmetrics "go.opentelemetry.io/ebpf-profiler/metrics"
otelreporter "go.opentelemetry.io/ebpf-profiler/reporter"
"go.opentelemetry.io/ebpf-profiler/times"
"go.opentelemetry.io/ebpf-profiler/tracehandler"
"go.opentelemetry.io/ebpf-profiler/tracer"
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
"go.opentelemetry.io/ebpf-profiler/util"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand All @@ -41,6 +33,14 @@ import (
"github.com/tklauser/numcpus"
"github.com/zcalusic/sysinfo"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/ebpf-profiler/host"
otelmetrics "go.opentelemetry.io/ebpf-profiler/metrics"
otelreporter "go.opentelemetry.io/ebpf-profiler/reporter"
"go.opentelemetry.io/ebpf-profiler/times"
"go.opentelemetry.io/ebpf-profiler/tracehandler"
"go.opentelemetry.io/ebpf-profiler/tracer"
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
"go.opentelemetry.io/ebpf-profiler/util"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -249,10 +249,6 @@ func mainWithExitCode() flags.ExitCode {
return flags.Failure(fmt.Sprintf("Failed to probe eBPF syscall: %v", err))
}

if err = tracer.ProbeTracepoint(); err != nil {
log.Warnf("Failed to probe tracepoint: %v. Parca-agent may fail to run on some kernel versions.", err)
}

externalLabels := reporter.Labels{}
if len(f.Metadata.ExternalLabels) > 0 {
for name, value := range f.Metadata.ExternalLabels {
Expand Down Expand Up @@ -317,7 +313,7 @@ func mainWithExitCode() flags.ExitCode {
return flags.Failure("Failed to start reporting: %v", err)
}
otelmetrics.SetReporter(parcaReporter)
parcaReporter.Run(mainCtx)
parcaReporter.Start(mainCtx)
var rep otelreporter.Reporter = parcaReporter

// Load the eBPF code and map definitions
Expand All @@ -340,11 +336,8 @@ func mainWithExitCode() flags.ExitCode {
log.Printf("eBPF tracer loaded")
defer trc.Close()

// Initial scan of /proc filesystem to list currently-active PIDs and have them processed.
if err = trc.StartPIDEventProcessor(mainCtx); err != nil {
log.Errorf("Failed to list processes from /proc: %v", err)
}
log.Debug("Completed initial PID listing")
// Start watching for PID events.
trc.StartPIDEventProcessor(mainCtx)

// Attach our tracer to the perf event
if err := trc.AttachTracer(); err != nil {
Expand Down
44 changes: 1 addition & 43 deletions metrics/all.go

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

4 changes: 2 additions & 2 deletions metrics/genschema/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def read_json_array(filename):
package metrics
import (
\totelmetrics "github.com/open-telemetry/opentelemetry-ebpf-profiler/metrics"
\totelmetrics "go.opentelemetry.io/ebpf-profiler/metrics"
)
const (
Expand Down Expand Up @@ -64,7 +64,7 @@ def get_unit(s):
return "MetricUnitSeconds"
case _:
raise ValueError(f"Unknown metric unit: {s}")

for metric in data:
if not "name" in metric:
continue
Expand Down
7 changes: 7 additions & 0 deletions metrics/metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,48 +434,55 @@
"id": 59
},
{
"obsolete": true,
"description": "Indicator for whether the exeMetadata queue has been overwritten",
"type": "counter",
"name": "ExeMetadataOverwrite",
"field": "agent.overwrites.exe_metadata",
"id": 60
},
{
"obsolete": true,
"description": "Indicator for whether the countsForTraces queue has been overwritten",
"type": "counter",
"name": "CountsForTracesOverwrite",
"field": "agent.overwrites.counts_for_traces",
"id": 61
},
{
"obsolete": true,
"description": "Indicator for whether the metrics queue has been overwritten",
"type": "counter",
"name": "MetricsOverwrite",
"field": "agent.overwrites.metrics",
"id": 62
},
{
"obsolete": true,
"description": "Indicator for whether the framesForTraces queue has been overwritten",
"type": "counter",
"name": "FramesForTracesOverwrite",
"field": "agent.overwrites.frames_for_traces",
"id": 63
},
{
"obsolete": true,
"description": "Indicator for whether the frameMetadata queue has been overwritten",
"type": "counter",
"name": "FrameMetadataOverwrite",
"field": "agent.overwrites.frame_metadata",
"id": 64
},
{
"obsolete": true,
"description": "Indicator for whether the hostMetadata queue has been overwritten",
"type": "counter",
"name": "HostMetadataOverwrite",
"field": "agent.overwrites.host_metadata",
"id": 65
},
{
"obsolete": true,
"description": "Indicator for whether the fallbackSymbols queue has been overwritten",
"type": "counter",
"name": "FallbackSymbolsOverwrite",
Expand Down
11 changes: 9 additions & 2 deletions reporter/parca_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ func (r *ParcaReporter) ReportFramesForTrace(_ *libpf.Trace) {}
func (r *ParcaReporter) ReportCountForTrace(_ libpf.TraceHash, _ uint16, _ *reporter.TraceEventMeta) {
}

// ExecutableKnown returns true if the metadata of the Executable specified by fileID is
// cached in the reporter.
func (r *ParcaReporter) ExecutableKnown(fileID libpf.FileID) bool {
_, known := r.executables.Get(fileID)
return known
}

// ExecutableMetadata accepts a fileID with the corresponding filename
// and caches this information.
func (r *ParcaReporter) ExecutableMetadata(args *reporter.ExecutableMetadataArgs) {
Expand Down Expand Up @@ -526,7 +533,7 @@ func New(
return r, nil
}

func (r *ParcaReporter) Run(mainCtx context.Context) (reporter.Reporter, error) {
func (r *ParcaReporter) Start(mainCtx context.Context) error {
// Create a child context for reporting features
ctx, cancelReporting := context.WithCancel(mainCtx)

Expand Down Expand Up @@ -564,7 +571,7 @@ func (r *ParcaReporter) Run(mainCtx context.Context) (reporter.Reporter, error)
cancelReporting()
}()

return r, nil
return nil
}

// reportDataToBackend creates and sends out an arrow record for a Parca backend.
Expand Down

0 comments on commit 1dfbcf8

Please sign in to comment.