From 64b5c6f4bfbc6c675fcb1fd29c25f1beae832ff2 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Thu, 14 Nov 2024 16:54:16 +0000 Subject: [PATCH 01/15] chore: update the opentelemetry-ebpf-profiler version this requires moving the import path from github.com/open-telemetry/opentelemetry-ebpf-profiler to go.opentelemetry.io --- LICENSE-3rdparty.csv | 8 +-- cli_flags.go | 2 +- containermetadata/containermetadata.go | 8 +-- containermetadata/containermetadata_test.go | 2 +- go.mod | 30 ++++----- go.sum | 73 ++++++++++++--------- main.go | 16 ++--- reporter/datadog_reporter.go | 8 +-- reporter/symbol_uploader.go | 8 +-- 9 files changed, 82 insertions(+), 73 deletions(-) diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 34264ef..4d062fa 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -56,7 +56,6 @@ import,github.com/moby/sys/userns,Apache-2.0,unknown import,github.com/modern-go/concurrent,Apache-2.0,unknown import,github.com/modern-go/reflect2,Apache-2.0,unknown import,github.com/munnerz/goautoneg,BSD-3-Clause,"Copyright (c) 2011, Open Knowledge Foundation Ltd." -import,github.com/open-telemetry/opentelemetry-ebpf-profiler,Apache-2.0,Copyright The OpenTelemetry Authors. import,github.com/opencontainers/go-digest,Apache-2.0,"Copyright 2019, 2020 OCI Contributors | Copyright 2016 Docker, Inc." import,github.com/opencontainers/image-spec,Apache-2.0,Copyright 2016 The Linux Foundation. import,github.com/opencontainers/runtime-spec/specs-go,Apache-2.0,Copyright 2015 The Linux Foundation. @@ -73,15 +72,16 @@ import,github.com/x448/float16,MIT,Copyright (c) 2019 Montgomery Edwards⁴⁴ import,github.com/xrash/smetrics,MIT,Copyright (C) 2016 Felipe da Cunha Gonçalves import,github.com/zeebo/xxh3,BSD-2-Clause,"Copyright (c) 2012-2014, Yann Collet | Copyright (c) 2019, Jeff Wendling" import,go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp,Apache-2.0,unknown +import,go.opentelemetry.io/ebpf-profiler,Apache-2.0,unknown import,go.opentelemetry.io/otel,Apache-2.0,unknown import,go.opentelemetry.io/otel/metric,Apache-2.0,unknown import,go.opentelemetry.io/otel/trace,Apache-2.0,unknown import,go.opentelemetry.io/proto/otlp,Apache-2.0,unknown -import,golang.org/x/arch/arm64/arm64asm,BSD-3-Clause,Copyright (c) 2015 The Go Authors. All rights reserved. -import,golang.org/x/exp/constraints,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. +import,golang.org/x/arch/arm64/arm64asm,BSD-3-Clause,Copyright 2015 The Go Authors. +import,golang.org/x/exp/constraints,BSD-3-Clause,Copyright 2009 The Go Authors. import,golang.org/x/net,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. import,golang.org/x/oauth2,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. -import,golang.org/x/sync,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. +import,golang.org/x/sync,BSD-3-Clause,Copyright 2009 The Go Authors. import,golang.org/x/sys/unix,BSD-3-Clause,Copyright 2009 The Go Authors. import,golang.org/x/term,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. import,golang.org/x/text,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. diff --git a/cli_flags.go b/cli_flags.go index 9552538..f91f6a8 100644 --- a/cli_flags.go +++ b/cli_flags.go @@ -12,9 +12,9 @@ import ( "time" cebpf "github.com/cilium/ebpf" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/tracer" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v3" + "go.opentelemetry.io/ebpf-profiler/tracer" "github.com/DataDog/dd-otel-host-profiler/version" ) diff --git a/containermetadata/containermetadata.go b/containermetadata/containermetadata.go index 5bfb063..53ef38f 100644 --- a/containermetadata/containermetadata.go +++ b/containermetadata/containermetadata.go @@ -33,12 +33,12 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" lru "github.com/elastic/go-freelru" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/metrics" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/periodiccaller" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/stringutil" log "github.com/sirupsen/logrus" "github.com/zeebo/xxh3" + "go.opentelemetry.io/ebpf-profiler/libpf" + "go.opentelemetry.io/ebpf-profiler/metrics" + "go.opentelemetry.io/ebpf-profiler/periodiccaller" + "go.opentelemetry.io/ebpf-profiler/stringutil" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/runtime" diff --git a/containermetadata/containermetadata_test.go b/containermetadata/containermetadata_test.go index 2948a2a..a5d184f 100644 --- a/containermetadata/containermetadata_test.go +++ b/containermetadata/containermetadata_test.go @@ -20,9 +20,9 @@ import ( "github.com/containerd/containerd" "github.com/docker/docker/client" lru "github.com/elastic/go-freelru" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/ebpf-profiler/libpf" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" diff --git a/go.mod b/go.mod index 9b6d318..b37fa43 100644 --- a/go.mod +++ b/go.mod @@ -5,18 +5,18 @@ go 1.23.1 require ( github.com/DataDog/jsonapi v0.10.0 github.com/DataDog/zstd v1.5.6 - github.com/cilium/ebpf v0.15.0 + github.com/cilium/ebpf v0.16.0 github.com/containerd/containerd v1.7.22 github.com/docker/docker v27.2.1+incompatible - github.com/elastic/go-freelru v0.13.0 + github.com/elastic/go-freelru v0.15.0 github.com/google/pprof v0.0.0-20240829160300-da1f7e9f2b25 - github.com/open-telemetry/opentelemetry-ebpf-profiler v0.0.0-20240918090752-0a8979a41728 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 github.com/tklauser/numcpus v0.8.0 github.com/urfave/cli/v3 v3.0.0-alpha9 github.com/zeebo/xxh3 v1.0.2 - golang.org/x/sys v0.23.0 + go.opentelemetry.io/ebpf-profiler v0.0.0-20241114112653-6d846a2023a0 + golang.org/x/sys v0.26.0 gopkg.in/DataDog/dd-trace-go.v1 v1.69.1 k8s.io/api v0.31.0 k8s.io/apimachinery v0.31.0 @@ -45,7 +45,7 @@ require ( github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/elastic/go-perf v0.0.0-20191212140718-9c656876f595 // indirect + github.com/elastic/go-perf v0.0.0-20241016160959-1342461adb4a // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect @@ -92,22 +92,22 @@ require ( github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect - go.opentelemetry.io/otel v1.27.0 // indirect - go.opentelemetry.io/otel/metric v1.27.0 // indirect - go.opentelemetry.io/otel/trace v1.27.0 // indirect + go.opentelemetry.io/otel v1.30.0 // indirect + go.opentelemetry.io/otel/metric v1.30.0 // indirect + go.opentelemetry.io/otel/trace v1.30.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect - golang.org/x/arch v0.8.0 // indirect - golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect + golang.org/x/arch v0.10.0 // indirect + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sync v0.7.0 // indirect + golang.org/x/sync v0.8.0 // indirect golang.org/x/term v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect - google.golang.org/grpc v1.64.1 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect + google.golang.org/grpc v1.66.2 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect @@ -125,4 +125,4 @@ require ( // To update the Datadog/opentelemetry-ebpf-profiler dependency on latest commit on datadog branch, change the following line to: // replace github.com/open-telemetry/opentelemetry-ebpf-profiler => github.com/DataDog/opentelemetry-ebpf-profiler datadog // and run `GOPRIVATE=github.com/Datadog/* go mod tidy` -replace github.com/open-telemetry/opentelemetry-ebpf-profiler => github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20240923191704-f29cae5f1ff3 +replace go.opentelemetry.io/ebpf-profiler => github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20241119174319-901d5b72ce75 diff --git a/go.sum b/go.sum index b35a91c..85d7f5a 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/ github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM= github.com/DataDog/jsonapi v0.10.0 h1:qDNSVEdnNteT6lXg9xN/JaGNgvVphwmN8frtJVzUVEU= github.com/DataDog/jsonapi v0.10.0/go.mod h1:FUSGF3bwMARlVfXEoFo9R/CVlYYy9BGL4C/Prf6Ke3M= -github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20240923191704-f29cae5f1ff3 h1:NDp4//eOtBNK4FQ5HwzCrJdWOqX8soz0wQkx4jTbS6k= -github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20240923191704-f29cae5f1ff3/go.mod h1:GQVu1MAtVCPc3mW4Atj8YVUEPdXoC/vo/kp0lNpQZhw= +github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20241119174319-901d5b72ce75 h1:nkofaoWfM7irT7Af870L8LKPGkKP9Wq4vR96dN248Ts= +github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20241119174319-901d5b72ce75/go.mod h1:LZs0Ai6k5IPICeMqXRDpr1uyW7NJnoXgyrlaQh36XSM= github.com/DataDog/sketches-go v1.4.5 h1:ki7VfeNz7IcNafq7yI/j5U/YCkO3LJiMDtXz9OMQbyE= github.com/DataDog/sketches-go v1.4.5/go.mod h1:7Y8GN8Jf66DLyDhc94zuWA3uHEt/7ttt8jHOBWWrSOg= github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY= @@ -38,8 +38,8 @@ github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cilium/ebpf v0.15.0 h1:7NxJhNiBT3NG8pZJ3c+yfrVdHY8ScgKD27sScgjLMMk= -github.com/cilium/ebpf v0.15.0/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso= +github.com/cilium/ebpf v0.16.0 h1:+BiEnHL6Z7lXnlGUsXQPPAE7+kenAd4ES8MQ5min0Ok= +github.com/cilium/ebpf v0.16.0/go.mod h1:L7u2Blt2jMM/vLAVgjxluxtBKlz3/GWjB0dMOEngfwE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= @@ -84,10 +84,10 @@ github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 h1:8EXxF+tCLqaVk8 github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4/go.mod h1:I5sHm0Y0T1u5YjlyqC5GVArM7aNZRUYtTjmJ8mPJFds= github.com/ebitengine/purego v0.6.0-alpha.5 h1:EYID3JOAdmQ4SNZYJHu9V6IqOeRQDBYxqKAg9PyoHFY= github.com/ebitengine/purego v0.6.0-alpha.5/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ= -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-perf v0.0.0-20191212140718-9c656876f595 h1:q8n4QjcLa4q39Q3fqHRknTBXBtegjriHFrB42YKgXGI= -github.com/elastic/go-perf v0.0.0-20191212140718-9c656876f595/go.mod h1:s09U1b4P1ZxnKx2OsqY7KlHdCesqZWIhyq0Gs/QC/Us= +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= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -165,6 +165,11 @@ github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0S github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA= +github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= +github.com/jsimonetti/rtnetlink v1.4.2 h1:Df9w9TZ3npHTyDn0Ev9e1uzmN2odmXd0QX+J5GTEn90= +github.com/jsimonetti/rtnetlink/v2 v2.0.1 h1:xda7qaHDSVOsADNouv7ukSuicKZO7GgVUCXxpaIEIlM= +github.com/jsimonetti/rtnetlink/v2 v2.0.1/go.mod h1:7MoNYNbb3UaDHtF8udiJo/RH6VsTKP1pqKLUTVCvToE= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -182,6 +187,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g= +github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw= +github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= +github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -285,38 +294,38 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZx8cOF0+Kkazoc7lwUNMGy0LrzEMxTm4BbTxg= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q= -go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= -go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= +go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts= +go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= -go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= -go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w= +go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= -go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc= +go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o= go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= -golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/arch v0.10.0 h1:S3huipmSclq3PJMNe76NGwkBR504WFkQ5dhzWzP8ZW8= +golang.org/x/arch v0.10.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -338,8 +347,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -353,8 +362,8 @@ golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= @@ -373,8 +382,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= -golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE= +golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -388,17 +397,17 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 h1:1hfbdAfFbkmpg41000wDVqr7jUpK/Yo+LPnIxxGzmkg= google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3/go.mod h1:5RBcpGRxr25RbDzY5w+dmaqpSEvl8Gwl1x2CICf60ic= -google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No= -google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM= +google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 h1:+rdxYoE3E5htTEWIe15GlN6IfvbURM//Jt0mmkmm6ZU= +google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117/go.mod h1:OimBR/bc1wPO9iV4NC2bpyjy3VnAwZh5EBPQdtaE5oo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= +google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/main.go b/main.go index d6d88be..f552485 100644 --- a/main.go +++ b/main.go @@ -18,16 +18,16 @@ import ( "strings" "time" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/host" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/metrics" - otelreporter "github.com/open-telemetry/opentelemetry-ebpf-profiler/reporter" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/times" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/tracehandler" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/tracer" - tracertypes "github.com/open-telemetry/opentelemetry-ebpf-profiler/tracer/types" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/util" log "github.com/sirupsen/logrus" "github.com/tklauser/numcpus" + "go.opentelemetry.io/ebpf-profiler/host" + "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" "golang.org/x/sys/unix" "gopkg.in/DataDog/dd-trace-go.v1/profiler" diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 5aadf59..56be19f 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -19,12 +19,12 @@ import ( "github.com/DataDog/zstd" lru "github.com/elastic/go-freelru" pprofile "github.com/google/pprof/profile" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf/xsync" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/process" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/reporter" log "github.com/sirupsen/logrus" "github.com/zeebo/xxh3" + "go.opentelemetry.io/ebpf-profiler/libpf" + "go.opentelemetry.io/ebpf-profiler/libpf/xsync" + "go.opentelemetry.io/ebpf-profiler/process" + "go.opentelemetry.io/ebpf-profiler/reporter" "github.com/DataDog/dd-otel-host-profiler/containermetadata" ) diff --git a/reporter/symbol_uploader.go b/reporter/symbol_uploader.go index ecb9d2b..e95ac6c 100644 --- a/reporter/symbol_uploader.go +++ b/reporter/symbol_uploader.go @@ -28,11 +28,11 @@ import ( "github.com/DataDog/zstd" lru "github.com/elastic/go-freelru" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf/pfelf" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/libpf/readatbuf" - "github.com/open-telemetry/opentelemetry-ebpf-profiler/process" log "github.com/sirupsen/logrus" + "go.opentelemetry.io/ebpf-profiler/libpf" + "go.opentelemetry.io/ebpf-profiler/libpf/pfelf" + "go.opentelemetry.io/ebpf-profiler/libpf/readatbuf" + "go.opentelemetry.io/ebpf-profiler/process" ) const uploadCacheSize = 16384 From 88a6774ad7e0e6bb624589328626f576ab7b82e6 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Thu, 14 Nov 2024 17:01:42 +0000 Subject: [PATCH 02/15] chore: remove deprecated bpfVerifierLogSize this was deprecated upstream --- cli_flags.go | 10 ---------- go.mod | 2 +- main.go | 1 - 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/cli_flags.go b/cli_flags.go index f91f6a8..e5ae9b7 100644 --- a/cli_flags.go +++ b/cli_flags.go @@ -11,7 +11,6 @@ import ( "runtime" "time" - cebpf "github.com/cilium/ebpf" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v3" "go.opentelemetry.io/ebpf-profiler/tracer" @@ -38,7 +37,6 @@ const ( type arguments struct { bpfVerifierLogLevel uint64 - bpfVerifierLogSize uint64 agentURL string copyright bool mapScaleFactor uint64 @@ -97,14 +95,6 @@ func parseArgs() (*arguments, error) { Destination: &args.bpfVerifierLogLevel, Sources: cli.EnvVars("DD_HOST_PROFILING_BPF_LOG_LEVEL"), }, - &cli.UintFlag{ - Name: "bpf-log-size", - Value: cebpf.DefaultVerifierLogSize, - Usage: "Size in bytes that will be allocated for the eBPF verifier output. " + - "Only takes effect if bpf-log-level > 0.", - Destination: &args.bpfVerifierLogSize, - Sources: cli.EnvVars("DD_HOST_PROFILING_BPF_LOG_SIZE"), - }, &cli.StringFlag{ Name: "agent-url", Aliases: []string{"U"}, diff --git a/go.mod b/go.mod index b37fa43..1449b18 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.23.1 require ( github.com/DataDog/jsonapi v0.10.0 github.com/DataDog/zstd v1.5.6 - github.com/cilium/ebpf v0.16.0 github.com/containerd/containerd v1.7.22 github.com/docker/docker v27.2.1+incompatible github.com/elastic/go-freelru v0.15.0 @@ -31,6 +30,7 @@ require ( github.com/Microsoft/go-winio v0.6.2 // indirect github.com/Microsoft/hcsshim v0.11.7 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cilium/ebpf v0.16.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/containerd/api v1.7.19 // indirect github.com/containerd/continuity v0.4.2 // indirect diff --git a/main.go b/main.go index f552485..38342c7 100644 --- a/main.go +++ b/main.go @@ -234,7 +234,6 @@ func mainWithExitCode() exitCode { MapScaleFactor: int(args.mapScaleFactor), KernelVersionCheck: !args.noKernelVersionCheck, BPFVerifierLogLevel: uint32(args.bpfVerifierLogLevel), - BPFVerifierLogSize: int(args.bpfVerifierLogSize), ProbabilisticInterval: args.probabilisticInterval, ProbabilisticThreshold: uint(args.probabilisticThreshold), }) From 3664da5eb1a16f988c7ec5e9d2c3659f2c6555f4 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Thu, 14 Nov 2024 17:02:13 +0000 Subject: [PATCH 03/15] chore: remove err from StartPIDEventProcessor signature the initial pid scan is no longer triggered, we solely rely on the mechanism to report new pid events. this has the nice benefit to greatly improve the startup time of the profiler --- main.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 38342c7..fa9797f 100644 --- a/main.go +++ b/main.go @@ -244,10 +244,8 @@ func mainWithExitCode() exitCode { defer trc.Close() now := time.Now() - // 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) - } + trc.StartPIDEventProcessor(mainCtx) + metrics.Add(metrics.IDProcPIDStartupMs, metrics.MetricValue(time.Since(now).Milliseconds())) log.Debug("Completed initial PID listing") From 525dca72594b0327676d8003ea71a6857d8f58a8 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Fri, 15 Nov 2024 09:27:03 +0000 Subject: [PATCH 04/15] reporter: fully remove host metadata make it clear that it's a no-op right now --- reporter/datadog_reporter.go | 38 ++++-------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 56be19f..c14dc02 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -20,7 +20,6 @@ import ( lru "github.com/elastic/go-freelru" pprofile "github.com/google/pprof/profile" log "github.com/sirupsen/logrus" - "github.com/zeebo/xxh3" "go.opentelemetry.io/ebpf-profiler/libpf" "go.opentelemetry.io/ebpf-profiler/libpf/xsync" "go.opentelemetry.io/ebpf-profiler/process" @@ -95,9 +94,6 @@ type DatadogReporter struct { // this structure holds in long term storage information that might // be duplicated in other places but not accessible for DatadogReporter. - // hostmetadata stores metadata that is sent out with every request. - hostmetadata *lru.SyncedLRU[string, string] - // fallbackSymbols keeps track of FrameID to their symbol. fallbackSymbols *lru.SyncedLRU[libpf.FrameID, string] @@ -173,13 +169,6 @@ func (r *DatadogReporter) ReportTraceEvent(trace *libpf.Trace, meta *reporter.Tr } } -// hashString is a helper function for LRUs that use string as a key. -// Xxh3 turned out to be the fastest hash function for strings in the FreeLRU benchmarks. -// It was only outperformed by the AES hash function, which is implemented in Plan9 assembly. -func hashString(s string) uint32 { - return uint32(xxh3.HashString(s)) -} - // SupportsReportTraceEvent returns true if the reporter supports reporting trace events // via ReportTraceEvent(). func (r *DatadogReporter) SupportsReportTraceEvent() bool { @@ -251,25 +240,15 @@ func (r *DatadogReporter) FrameMetadata(fileID libpf.FileID, addressOrLine libpf r.frames.Add(fileID, &mu) } -// ReportHostMetadata enqueues host metadata. -func (r *DatadogReporter) ReportHostMetadata(metadataMap map[string]string) { - r.addHostmetadata(metadataMap) -} +// ReportHostMetadata is a NOP for DatadogReporter. +func (r *DatadogReporter) ReportHostMetadata(_ map[string]string) {} -// ReportHostMetadataBlocking enqueues host metadata. +// ReportHostMetadataBlocking is a NOP for DatadogReporter. func (r *DatadogReporter) ReportHostMetadataBlocking(_ context.Context, - metadataMap map[string]string, _ int, _ time.Duration) error { - r.addHostmetadata(metadataMap) + _ map[string]string, _ int, _ time.Duration) error { return nil } -// addHostmetadata adds to and overwrites host metadata. -func (r *DatadogReporter) addHostmetadata(metadataMap map[string]string) { - for k, v := range metadataMap { - r.hostmetadata.Add(k, v) - } -} - // ReportMetrics is a NOP for DatadogReporter. func (r *DatadogReporter) ReportMetrics(_ uint32, _ []uint32, _ []int64) {} @@ -306,14 +285,6 @@ func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) ( return nil, err } - // Next step: Dynamically configure the size of this LRU. - // Currently, we use the length of the JSON array in - // hostmetadata/hostmetadata.json. - hostmetadata, err := lru.NewSynced[string, string](115, hashString) - if err != nil { - return nil, err - } - var symbolUploader *DatadogSymbolUploader if cfg.SymbolUploaderConfig.Enabled { log.Infof("Enabling Datadog local symbol upload") @@ -332,7 +303,6 @@ func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) ( fallbackSymbols: fallbackSymbols, executables: executables, frames: frames, - hostmetadata: hostmetadata, containerMetadataProvider: p, traceEvents: xsync.NewRWMutex(map[traceAndMetaKey]*traceFramesCounts{}), processes: processes, From 259debcc6c2e1ab84d49bec80c610ddba0bb1c57 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Fri, 15 Nov 2024 09:34:43 +0000 Subject: [PATCH 05/15] reporter: rename traceFramesCounts to traceEvents --- reporter/datadog_reporter.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index c14dc02..d3342d8 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -65,8 +65,8 @@ type traceAndMetaKey struct { tid libpf.PID } -// traceFramesCounts holds known information about a trace. -type traceFramesCounts struct { +// traceEvents holds known information about a trace. +type traceEvents struct { files []libpf.FileID linenos []libpf.AddressOrLineno frameTypes []libpf.FrameType @@ -104,7 +104,7 @@ type DatadogReporter struct { frames *lru.SyncedLRU[libpf.FileID, *xsync.RWMutex[map[libpf.AddressOrLineno]sourceInfo]] // traceEvents stores reported trace events (trace metadata with frames and counts) - traceEvents xsync.RWMutex[map[traceAndMetaKey]*traceFramesCounts] + traceEvents xsync.RWMutex[map[traceAndMetaKey]*traceEvents] // processes stores the metadata associated to a PID. processes *lru.SyncedLRU[libpf.PID, processMetadata] @@ -135,10 +135,16 @@ type DatadogReporter struct { profileSeq uint64 } +// SupportsReportTraceEvent returns true if the reporter supports reporting trace events +// via ReportTraceEvent(). +func (r *DatadogReporter) SupportsReportTraceEvent() bool { + return true +} + // ReportTraceEvent enqueues reported trace events for the Datadog reporter. func (r *DatadogReporter) ReportTraceEvent(trace *libpf.Trace, meta *reporter.TraceEventMeta) { - traceEvents := r.traceEvents.WLock() - defer r.traceEvents.WUnlock(&traceEvents) + traceEventsMap := r.traceEvents.WLock() + defer r.traceEvents.WUnlock(&traceEventsMap) if _, ok := r.processes.Get(meta.PID); !ok { r.addProcessMetadata(meta.PID) @@ -152,13 +158,13 @@ func (r *DatadogReporter) ReportTraceEvent(trace *libpf.Trace, meta *reporter.Tr tid: meta.TID, } - if tr, exists := (*traceEvents)[key]; exists { + if tr, exists := (*traceEventsMap)[key]; exists { tr.timestamps = append(tr.timestamps, uint64(meta.Timestamp)) - (*traceEvents)[key] = tr + (*traceEventsMap)[key] = tr return } - (*traceEvents)[key] = &traceFramesCounts{ + (*traceEventsMap)[key] = &traceEvents{ files: trace.Files, linenos: trace.Linenos, frameTypes: trace.FrameTypes, @@ -169,12 +175,6 @@ func (r *DatadogReporter) ReportTraceEvent(trace *libpf.Trace, meta *reporter.Tr } } -// SupportsReportTraceEvent returns true if the reporter supports reporting trace events -// via ReportTraceEvent(). -func (r *DatadogReporter) SupportsReportTraceEvent() bool { - return true -} - // ReportFramesForTrace is a NOP for DatadogReporter. func (r *DatadogReporter) ReportFramesForTrace(_ *libpf.Trace) {} @@ -304,7 +304,7 @@ func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) ( executables: executables, frames: frames, containerMetadataProvider: p, - traceEvents: xsync.NewRWMutex(map[traceAndMetaKey]*traceFramesCounts{}), + traceEvents: xsync.NewRWMutex(map[traceAndMetaKey]*traceEvents{}), processes: processes, intakeURL: cfg.IntakeURL, pprofPrefix: cfg.PprofPrefix, From 972e432714f671ce73f660d73ff1872dee511fec Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Fri, 15 Nov 2024 09:35:09 +0000 Subject: [PATCH 06/15] reporter: remove ReportFallbackSymbol was removed from the interface upstream --- reporter/datadog_reporter.go | 63 +++++------------------------------- 1 file changed, 8 insertions(+), 55 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index d3342d8..385485f 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -94,9 +94,6 @@ type DatadogReporter struct { // this structure holds in long term storage information that might // be duplicated in other places but not accessible for DatadogReporter. - // fallbackSymbols keeps track of FrameID to their symbol. - fallbackSymbols *lru.SyncedLRU[libpf.FrameID, string] - // executables stores metadata for executables. executables *lru.SyncedLRU[libpf.FileID, execInfo] @@ -182,14 +179,6 @@ func (r *DatadogReporter) ReportFramesForTrace(_ *libpf.Trace) {} func (r *DatadogReporter) ReportCountForTrace(_ libpf.TraceHash, _ uint16, _ *reporter.TraceEventMeta) { } -// ReportFallbackSymbol enqueues a fallback symbol for reporting, for a given frame. -func (r *DatadogReporter) ReportFallbackSymbol(frameID libpf.FrameID, symbol string) { - if _, exists := r.fallbackSymbols.Peek(frameID); exists { - return - } - r.fallbackSymbols.Add(frameID, symbol) -} - // ExecutableMetadata accepts a fileID with the corresponding filename // and caches this information. func (r *DatadogReporter) ExecutableMetadata(fileID libpf.FileID, filePath, buildID string, @@ -264,11 +253,6 @@ func (r *DatadogReporter) GetMetrics() reporter.Metrics { // StartDatadog sets up and manages the reporting connection to the Datadog Backend. func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) (reporter.Reporter, error) { - fallbackSymbols, err := lru.NewSynced[libpf.FrameID, string](cfg.CacheSize, libpf.FrameID.Hash32) - if err != nil { - return nil, err - } - executables, err := lru.NewSynced[libpf.FileID, execInfo](cfg.CacheSize, libpf.FileID.Hash32) if err != nil { return nil, err @@ -300,7 +284,6 @@ func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) ( version: cfg.Version, samplesPerSecond: cfg.SamplesPerSecond, stopSignal: make(chan libpf.Void), - fallbackSymbols: fallbackSymbols, executables: executables, frames: frames, containerMetadataProvider: p, @@ -436,10 +419,9 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile, } fileIDtoMapping := make(map[libpf.FileID]*pprofile.Mapping) - frameIDtoFunction := make(map[libpf.FrameID]*pprofile.Function) totalSampleCount := 0 - for traceAndMetaKey, traceInfo := range samples { + for traceKey, traceInfo := range samples { sample := &pprofile.Sample{} for _, ts := range traceInfo.timestamps { @@ -485,30 +467,6 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile, line := pprofile.Line{Function: createPprofFunctionEntry(funcMap, profile, "", loc.Mapping.File)} loc.Line = append(loc.Line, line) - case libpf.KernelFrame: - // Reconstruct frameID - frameID := libpf.NewFrameID(traceInfo.files[i], traceInfo.linenos[i]) - // Store Kernel frame information as Line message: - line := pprofile.Line{} - - if tmpFunction, exists := frameIDtoFunction[frameID]; exists { - line.Function = tmpFunction - } else { - symbol, exists := r.fallbackSymbols.Get(frameID) - if !exists { - // TODO: choose a proper default value if the kernel symbol was not - // reported yet. - symbol = unknownStr - } - line.Function = createPprofFunctionEntry( - funcMap, profile, symbol, "") - } - loc.Line = append(loc.Line, line) - - // To be compliant with the protocol generate a dummy mapping entry. - loc.Mapping = getDummyMapping(fileIDtoMapping, profile, - traceInfo.files[i]) - case libpf.AbortFrame: // Next step: Figure out how the OTLP protocol // could handle artificial frames, like AbortFrame, @@ -526,20 +484,15 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile, "UNREPORTED", frameKind.String()) } else { fileIDInfo := fileIDInfoLock.RLock() - si, exists := (*fileIDInfo)[traceInfo.linenos[i]] - if !exists { + if si, exists := (*fileIDInfo)[traceInfo.linenos[i]]; exists { + line.Line = int64(si.lineNumber) + line.Function = createPprofFunctionEntry(funcMap, profile, + si.functionName, si.filePath) + } else { // At this point, we do not have enough information for the frame. // Therefore, we report a dummy entry and use the interpreter as filename. - // To differentiate this case with the case where no information about - // the file ID is available at all, we use a different name for reported - // function. line.Function = createPprofFunctionEntry(funcMap, profile, "UNRESOLVED", frameKind.String()) - } else { - line.Line = int64(si.lineNumber) - - line.Function = createPprofFunctionEntry(funcMap, profile, - si.functionName, si.filePath) } fileIDInfoLock.RUnlock(&fileIDInfo) } @@ -551,7 +504,7 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile, sample.Location = append(sample.Location, loc) } - processMeta, _ := r.processes.Get(traceAndMetaKey.pid) + processMeta, _ := r.processes.Get(traceKey.pid) execPath := processMeta.execPath // Check if the last frame is a kernel frame. @@ -575,7 +528,7 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile, if r.timeline { timestamps = traceInfo.timestamps } - addTraceLabels(sample.Label, traceAndMetaKey, processMeta, baseExec, timestamps) + addTraceLabels(sample.Label, traceKey, processMeta, baseExec, timestamps) count := int64(len(traceInfo.timestamps)) sample.Value = append(sample.Value, count, count*samplingPeriod) From bfb5c23365267b12417da8368e632097939ada59 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Fri, 15 Nov 2024 09:36:46 +0000 Subject: [PATCH 07/15] reporter: add ExecutableKnown and FrameKnown add two new functions which were added to the reporter interface implementation is the same than that of the OTLP reporter --- reporter/datadog_reporter.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 385485f..71a4d5f 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -179,6 +179,13 @@ func (r *DatadogReporter) ReportFramesForTrace(_ *libpf.Trace) {} func (r *DatadogReporter) 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 *DatadogReporter) 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 *DatadogReporter) ExecutableMetadata(fileID libpf.FileID, filePath, buildID string, @@ -193,6 +200,18 @@ func (r *DatadogReporter) ExecutableMetadata(fileID libpf.FileID, filePath, buil } } +// FrameKnown returns true if the metadata of the Frame specified by frameID is +// cached in the reporter. +func (r *DatadogReporter) FrameKnown(frameID libpf.FrameID) bool { + known := false + if frameMapLock, exists := r.frames.Get(frameID.FileID()); exists { + frameMap := frameMapLock.RLock() + defer frameMapLock.RUnlock(&frameMap) + _, known = (*frameMap)[frameID.AddressOrLine()] + } + return known +} + // FrameMetadata accepts metadata associated with a frame and caches this information. func (r *DatadogReporter) FrameMetadata(fileID libpf.FileID, addressOrLine libpf.AddressOrLineno, lineNumber libpf.SourceLineno, functionOffset uint32, functionName, filePath string) { From 20a199a3660a65531c2c1c9934fb600653bc95ff Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Fri, 15 Nov 2024 09:58:26 +0000 Subject: [PATCH 08/15] reporter: split report creation and start also add lifetime for reporter caches to avoid memory leaks this required changes in pid cache to avoid removing entries for live processes --- main.go | 7 +- reporter/datadog_reporter.go | 130 +++++++++++++++++++++-------------- 2 files changed, 83 insertions(+), 54 deletions(-) diff --git a/main.go b/main.go index fa9797f..b1b78a7 100644 --- a/main.go +++ b/main.go @@ -198,7 +198,7 @@ func mainWithExitCode() exitCode { } } - rep, err := reporter.Start(mainCtx, &reporter.Config{ + rep, err := reporter.NewDatadog(&reporter.Config{ IntakeURL: intakeURL, Version: versionInfo.Version, ReportInterval: intervals.ReportInterval(), @@ -218,6 +218,11 @@ func mainWithExitCode() exitCode { Version: args.serviceVersion, }, }, containerMetadataProvider) + if err != nil { + return failure("Failed to create Datadog reporter: %v", err) + } + + err = rep.Start(mainCtx) if err != nil { return failure("Failed to start reporting: %v", err) } diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 71a4d5f..76806ff 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -31,7 +31,11 @@ import ( // Assert that we implement the full Reporter interface. var _ reporter.Reporter = (*DatadogReporter)(nil) -const profilerName = "dd-otel-host-profiler" +const ( + profilerName = "dd-otel-host-profiler" + pidCacheUpdateInterval = 1 * time.Minute // pid cache items will be updated at most once per this interval + pidCacheCleanupInterval = 5 * time.Minute // pid cache items for which metadata hasn't been updated in this interval will be removed +) // execInfo enriches an executable with additional metadata. type execInfo struct { @@ -78,12 +82,15 @@ type traceEvents struct { } type processMetadata struct { + updatedAt time.Time execPath string containerMetadata containermetadata.ContainerMetadata } // DatadogReporter receives and transforms information to be OTLP/profiles compliant. type DatadogReporter struct { + config *Config + // profiler version version string @@ -132,6 +139,57 @@ type DatadogReporter struct { profileSeq uint64 } +func NewDatadog(cfg *Config, p containermetadata.Provider) (*DatadogReporter, error) { + executables, err := lru.NewSynced[libpf.FileID, execInfo](cfg.CacheSize, libpf.FileID.Hash32) + if err != nil { + return nil, err + } + executables.SetLifetime(1 * time.Hour) // Allow GC to clean stale items. + + frames, err := lru.NewSynced[libpf.FileID, + *xsync.RWMutex[map[libpf.AddressOrLineno]sourceInfo]](cfg.CacheSize, libpf.FileID.Hash32) + if err != nil { + return nil, err + } + frames.SetLifetime(1 * time.Hour) // Allow GC to clean stale items. + + processes, err := lru.NewSynced[libpf.PID, processMetadata](cfg.CacheSize, libpf.PID.Hash32) + if err != nil { + return nil, err + } + processes.SetLifetime(pidCacheCleanupInterval) + + var symbolUploader *DatadogSymbolUploader + if cfg.SymbolUploaderConfig.Enabled { + log.Infof("Enabling Datadog local symbol upload") + symbolUploader, err = NewDatadogSymbolUploader(cfg.SymbolUploaderConfig) + if err != nil { + log.Errorf( + "Failed to create Datadog symbol uploader, symbol upload will be disabled: %v", + err) + } + } + + return &DatadogReporter{ + config: cfg, + version: cfg.Version, + samplesPerSecond: cfg.SamplesPerSecond, + stopSignal: make(chan libpf.Void), + executables: executables, + frames: frames, + containerMetadataProvider: p, + traceEvents: xsync.NewRWMutex(map[traceAndMetaKey]*traceEvents{}), + processes: processes, + intakeURL: cfg.IntakeURL, + pprofPrefix: cfg.PprofPrefix, + apiKey: cfg.APIKey, + symbolUploader: symbolUploader, + tags: cfg.Tags, + timeline: cfg.Timeline, + profileSeq: 0, + }, nil +} + // SupportsReportTraceEvent returns true if the reporter supports reporting trace events // via ReportTraceEvent(). func (r *DatadogReporter) SupportsReportTraceEvent() bool { @@ -143,7 +201,7 @@ func (r *DatadogReporter) ReportTraceEvent(trace *libpf.Trace, meta *reporter.Tr traceEventsMap := r.traceEvents.WLock() defer r.traceEvents.WUnlock(&traceEventsMap) - if _, ok := r.processes.Get(meta.PID); !ok { + if pMeta, ok := r.processes.Get(meta.PID); !ok || time.Since(pMeta.updatedAt) > pidCacheUpdateInterval { r.addProcessMetadata(meta.PID) } @@ -270,53 +328,8 @@ func (r *DatadogReporter) GetMetrics() reporter.Metrics { return reporter.Metrics{} } -// StartDatadog sets up and manages the reporting connection to the Datadog Backend. -func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) (reporter.Reporter, error) { - executables, err := lru.NewSynced[libpf.FileID, execInfo](cfg.CacheSize, libpf.FileID.Hash32) - if err != nil { - return nil, err - } - - frames, err := lru.NewSynced[libpf.FileID, - *xsync.RWMutex[map[libpf.AddressOrLineno]sourceInfo]](cfg.CacheSize, libpf.FileID.Hash32) - if err != nil { - return nil, err - } - - processes, err := lru.NewSynced[libpf.PID, processMetadata](cfg.CacheSize, libpf.PID.Hash32) - if err != nil { - return nil, err - } - - var symbolUploader *DatadogSymbolUploader - if cfg.SymbolUploaderConfig.Enabled { - log.Infof("Enabling Datadog local symbol upload") - symbolUploader, err = NewDatadogSymbolUploader(cfg.SymbolUploaderConfig) - if err != nil { - log.Errorf( - "Failed to create Datadog symbol uploader, symbol upload will be disabled: %v", - err) - } - } - - r := &DatadogReporter{ - version: cfg.Version, - samplesPerSecond: cfg.SamplesPerSecond, - stopSignal: make(chan libpf.Void), - executables: executables, - frames: frames, - containerMetadataProvider: p, - traceEvents: xsync.NewRWMutex(map[traceAndMetaKey]*traceEvents{}), - processes: processes, - intakeURL: cfg.IntakeURL, - pprofPrefix: cfg.PprofPrefix, - apiKey: cfg.APIKey, - symbolUploader: symbolUploader, - tags: cfg.Tags, - timeline: cfg.Timeline, - profileSeq: 0, - } - +// Start sets up and manages the reporting connection to the Datadog Backend. +func (r *DatadogReporter) Start(mainCtx context.Context) error { // Create a child context for reporting features ctx, cancelReporting := context.WithCancel(mainCtx) @@ -327,8 +340,10 @@ func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) ( } go func() { - tick := time.NewTicker(cfg.ReportInterval) + tick := time.NewTicker(r.config.ReportInterval) defer tick.Stop() + purgeTick := time.NewTicker(5 * time.Minute) + defer purgeTick.Stop() for { select { case <-ctx.Done(): @@ -339,7 +354,12 @@ func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) ( if err := r.reportProfile(ctx); err != nil { log.Errorf("Request failed: %v", err) } - tick.Reset(libpf.AddJitter(cfg.ReportInterval, 0.2)) + tick.Reset(libpf.AddJitter(r.config.ReportInterval, 0.2)) + case <-purgeTick.C: + // Allow the GC to purge expired entries to avoid memory leaks. + r.executables.PurgeExpired() + r.frames.PurgeExpired() + r.processes.PurgeExpired() } } }() @@ -351,7 +371,7 @@ func Start(mainCtx context.Context, cfg *Config, p containermetadata.Provider) ( cancelReporting() }() - return r, nil + return nil } // reportProfile creates and sends out a profile. @@ -685,5 +705,9 @@ func (r *DatadogReporter) addProcessMetadata(pid libpf.PID) { // Even upon failure, we might still have managed to get the containerID } - r.processes.Add(pid, processMetadata{execPath, containerMetadata}) + r.processes.Add(pid, processMetadata{ + updatedAt: time.Now(), + execPath: execPath, + containerMetadata: containerMetadata, + }) } From c454d637cae838e1ee66771183a0b3f27eb1d139 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Fri, 15 Nov 2024 09:59:04 +0000 Subject: [PATCH 09/15] reporter: modify FrameMetadata arguments --- reporter/datadog_reporter.go | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 76806ff..f7478f2 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -271,25 +271,33 @@ func (r *DatadogReporter) FrameKnown(frameID libpf.FrameID) bool { } // FrameMetadata accepts metadata associated with a frame and caches this information. -func (r *DatadogReporter) FrameMetadata(fileID libpf.FileID, addressOrLine libpf.AddressOrLineno, - lineNumber libpf.SourceLineno, functionOffset uint32, functionName, filePath string) { +func (r *DatadogReporter) FrameMetadata(args *reporter.FrameMetadataArgs) { + fileID := args.FrameID.FileID() + addressOrLine := args.FrameID.AddressOrLine() + + log.Debugf("FrameMetadata [%x] %v+%v at %v:%v", + fileID, args.FunctionName, args.FunctionOffset, + args.SourceFile, args.SourceLine) + if frameMapLock, exists := r.frames.Get(fileID); exists { frameMap := frameMapLock.WLock() defer frameMapLock.WUnlock(&frameMap) - if filePath == "" { - // The new filePath may be empty, and we don't want to overwrite + sourceFile := args.SourceFile + + if sourceFile == "" { + // The new sourceFile may be empty, and we don't want to overwrite // an existing filePath with it. if s, exists := (*frameMap)[addressOrLine]; exists { - filePath = s.filePath + sourceFile = s.filePath } } (*frameMap)[addressOrLine] = sourceInfo{ - lineNumber: lineNumber, - functionOffset: functionOffset, - functionName: functionName, - filePath: filePath, + lineNumber: args.SourceLine, + filePath: sourceFile, + functionOffset: args.FunctionOffset, + functionName: args.FunctionName, } return @@ -297,10 +305,10 @@ func (r *DatadogReporter) FrameMetadata(fileID libpf.FileID, addressOrLine libpf v := make(map[libpf.AddressOrLineno]sourceInfo) v[addressOrLine] = sourceInfo{ - lineNumber: lineNumber, - functionOffset: functionOffset, - functionName: functionName, - filePath: filePath, + lineNumber: args.SourceLine, + filePath: args.SourceFile, + functionOffset: args.FunctionOffset, + functionName: args.FunctionName, } mu := xsync.NewRWMutex(v) r.frames.Add(fileID, &mu) From 0bb48f4d83c15ac74274294688a3a9f22ca819ef Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Fri, 15 Nov 2024 10:03:28 +0000 Subject: [PATCH 10/15] reporter: change ExecutableMetadata signature --- reporter/datadog_reporter.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index f7478f2..9331b50 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -22,7 +22,6 @@ import ( log "github.com/sirupsen/logrus" "go.opentelemetry.io/ebpf-profiler/libpf" "go.opentelemetry.io/ebpf-profiler/libpf/xsync" - "go.opentelemetry.io/ebpf-profiler/process" "go.opentelemetry.io/ebpf-profiler/reporter" "github.com/DataDog/dd-otel-host-profiler/containermetadata" @@ -246,15 +245,14 @@ func (r *DatadogReporter) ExecutableKnown(fileID libpf.FileID) bool { // ExecutableMetadata accepts a fileID with the corresponding filename // and caches this information. -func (r *DatadogReporter) ExecutableMetadata(fileID libpf.FileID, filePath, buildID string, - interp libpf.InterpreterType, opener process.FileOpener) { - r.executables.Add(fileID, execInfo{ - fileName: path.Base(filePath), - buildID: buildID, +func (r *DatadogReporter) ExecutableMetadata(args *reporter.ExecutableMetadataArgs) { + r.executables.Add(args.FileID, execInfo{ + fileName: path.Base(args.FileName), + buildID: args.GnuBuildID, }) - if r.symbolUploader != nil && interp == libpf.Native { - r.symbolUploader.UploadSymbols(fileID, filePath, buildID, opener) + if r.symbolUploader != nil && args.Interp == libpf.Native { + r.symbolUploader.UploadSymbols(args.FileID, args.FileName, args.GnuBuildID, args.Open) } } From 2e594416e02bc6e9a7573c6128c4f6102408075a Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Tue, 19 Nov 2024 11:07:41 +0000 Subject: [PATCH 11/15] reporter: remove executables lifetime due to issue upstream, we can fix this ulteriorly when the issue is fixed upstream --- reporter/datadog_reporter.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 9331b50..09b7aaa 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -143,7 +143,12 @@ func NewDatadog(cfg *Config, p containermetadata.Provider) (*DatadogReporter, er if err != nil { return nil, err } - executables.SetLifetime(1 * time.Hour) // Allow GC to clean stale items. + // TODO: Consider purging stale entries from executables to avoid memory leaks. + // Currently, setting a lifetime via go-freelru will cause the executables to be + // removed from the cache after the lifetime expires, regardless of whether + // they are still in use or not. + // This leads to mappings missing filename and buildID information, which is + // required for the profile to be correctly displayed in the Datadog UI. frames, err := lru.NewSynced[libpf.FileID, *xsync.RWMutex[map[libpf.AddressOrLineno]sourceInfo]](cfg.CacheSize, libpf.FileID.Hash32) From 778b84965dd1e85053221a24cf8f9bb411c017a6 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Tue, 19 Nov 2024 18:58:32 +0100 Subject: [PATCH 12/15] main: remove call to tracer.ProbeTracepoint the upstream ebpf profiler is now allow to run without tracepoints if possible --- main.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.go b/main.go index b1b78a7..36c838e 100644 --- a/main.go +++ b/main.go @@ -144,10 +144,6 @@ func mainWithExitCode() exitCode { return failure("Failed to probe eBPF syscall: %v", err) } - if err = tracer.ProbeTracepoint(); err != nil { - return failure("Failed to probe tracepoint: %v", err) - } - presentCores, err := numcpus.GetPresent() if err != nil { return failure("Failed to read CPU file: %v", err) From 3b9c620dceff24f403af0d6f86412b77ff699bc7 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Tue, 19 Nov 2024 19:05:02 +0100 Subject: [PATCH 13/15] reporter: split reporter cache sizes definition without impacting the cache sizes, we can refine this later on based on the runtime profiler outputs internally --- main.go | 21 ++++++++++++--------- reporter/config.go | 8 ++++++-- reporter/datadog_reporter.go | 6 +++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 36c838e..28d428a 100644 --- a/main.go +++ b/main.go @@ -195,15 +195,18 @@ func mainWithExitCode() exitCode { } rep, err := reporter.NewDatadog(&reporter.Config{ - IntakeURL: intakeURL, - Version: versionInfo.Version, - ReportInterval: intervals.ReportInterval(), - CacheSize: traceHandlerCacheSize, - SamplesPerSecond: int(args.samplesPerSecond), - PprofPrefix: args.pprofPrefix, - Tags: validatedTags, - Timeline: args.timeline, - APIKey: apiKey, + IntakeURL: intakeURL, + Version: versionInfo.Version, + ReportInterval: intervals.ReportInterval(), + ExecutablesCacheElements: traceHandlerCacheSize, + // Next step: Calculate FramesCacheElements from numCores and samplingRate. + FramesCacheElements: traceHandlerCacheSize, + ProcessesCacheElements: traceHandlerCacheSize, + SamplesPerSecond: int(args.samplesPerSecond), + PprofPrefix: args.pprofPrefix, + Tags: validatedTags, + Timeline: args.timeline, + APIKey: apiKey, SymbolUploaderConfig: reporter.SymbolUploaderConfig{ Enabled: args.uploadSymbols, UploadDynamicSymbols: args.uploadDynamicSymbols, diff --git a/reporter/config.go b/reporter/config.go index d900053..a02c8ba 100644 --- a/reporter/config.go +++ b/reporter/config.go @@ -28,8 +28,12 @@ type Config struct { Version string // IntakeURL defines the URL of profiling intake. IntakeURL string - // CacheSize defines the size of the reporter caches. - CacheSize uint32 + // ExecutablesCacheElements defines item capacity of the executables cache. + ExecutablesCacheElements uint32 + // FramesCacheElements defines the item capacity of the frames cache. + FramesCacheElements uint32 + // ProcessesCacheElements defines the item capacity of the processes cache. + ProcessesCacheElements uint32 // samplesPerSecond defines the number of samples per second. SamplesPerSecond int // ReportInterval defines the interval at which the agent reports data to the collection agent. diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 09b7aaa..c8b527b 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -139,7 +139,7 @@ type DatadogReporter struct { } func NewDatadog(cfg *Config, p containermetadata.Provider) (*DatadogReporter, error) { - executables, err := lru.NewSynced[libpf.FileID, execInfo](cfg.CacheSize, libpf.FileID.Hash32) + executables, err := lru.NewSynced[libpf.FileID, execInfo](cfg.ExecutablesCacheElements, libpf.FileID.Hash32) if err != nil { return nil, err } @@ -151,13 +151,13 @@ func NewDatadog(cfg *Config, p containermetadata.Provider) (*DatadogReporter, er // required for the profile to be correctly displayed in the Datadog UI. frames, err := lru.NewSynced[libpf.FileID, - *xsync.RWMutex[map[libpf.AddressOrLineno]sourceInfo]](cfg.CacheSize, libpf.FileID.Hash32) + *xsync.RWMutex[map[libpf.AddressOrLineno]sourceInfo]](cfg.FramesCacheElements, libpf.FileID.Hash32) if err != nil { return nil, err } frames.SetLifetime(1 * time.Hour) // Allow GC to clean stale items. - processes, err := lru.NewSynced[libpf.PID, processMetadata](cfg.CacheSize, libpf.PID.Hash32) + processes, err := lru.NewSynced[libpf.PID, processMetadata](cfg.ProcessesCacheElements, libpf.PID.Hash32) if err != nil { return nil, err } From 2a9defc95f6c3c4717e3f5a391a88315a7a9eb95 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Tue, 19 Nov 2024 19:19:39 +0100 Subject: [PATCH 14/15] reporter: pass down container metadata in addTraceLabels appease gocritic linter on copied struct size --- reporter/datadog_reporter.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index c8b527b..77ea844 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -578,7 +578,7 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile, if r.timeline { timestamps = traceInfo.timestamps } - addTraceLabels(sample.Label, traceKey, processMeta, baseExec, timestamps) + addTraceLabels(sample.Label, traceKey, processMeta.containerMetadata, baseExec, timestamps) count := int64(len(traceInfo.timestamps)) sample.Value = append(sample.Value, count, count*samplingPeriod) @@ -620,22 +620,22 @@ func createPprofFunctionEntry(funcMap map[funcInfo]*pprofile.Function, return function } -func addTraceLabels(labels map[string][]string, i traceAndMetaKey, processMeta processMetadata, +func addTraceLabels(labels map[string][]string, i traceAndMetaKey, containerMetadata containermetadata.ContainerMetadata, baseExec string, timestamps []uint64) { if i.comm != "" { labels["thread_name"] = append(labels["thread_name"], i.comm) } - if processMeta.containerMetadata.PodName != "" { - labels["pod_name"] = append(labels["pod_name"], processMeta.containerMetadata.PodName) + if containerMetadata.PodName != "" { + labels["pod_name"] = append(labels["pod_name"], containerMetadata.PodName) } - if processMeta.containerMetadata.ContainerID != "" { - labels["container_id"] = append(labels["container_id"], processMeta.containerMetadata.ContainerID) + if containerMetadata.ContainerID != "" { + labels["container_id"] = append(labels["container_id"], containerMetadata.ContainerID) } - if processMeta.containerMetadata.ContainerName != "" { - labels["container_name"] = append(labels["container_name"], processMeta.containerMetadata.ContainerName) + if containerMetadata.ContainerName != "" { + labels["container_name"] = append(labels["container_name"], containerMetadata.ContainerName) } if i.apmServiceName != "" { From f4536b1dd479fc02bd306d5fcf4accd3b31c16bd Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Wed, 20 Nov 2024 08:39:24 +0100 Subject: [PATCH 15/15] frames: also remove lifetime --- reporter/datadog_reporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 77ea844..802e6b2 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -155,7 +155,7 @@ func NewDatadog(cfg *Config, p containermetadata.Provider) (*DatadogReporter, er if err != nil { return nil, err } - frames.SetLifetime(1 * time.Hour) // Allow GC to clean stale items. + // TODO: Similarly to executables, consider purging stale entries from frames. processes, err := lru.NewSynced[libpf.PID, processMetadata](cfg.ProcessesCacheElements, libpf.PID.Hash32) if err != nil {