diff --git a/.chloggen/pprofile-wrapper.yaml b/.chloggen/pprofile-wrapper.yaml new file mode 100644 index 00000000000..bd69f1e9925 --- /dev/null +++ b/.chloggen/pprofile-wrapper.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: pdata/pprofile + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add pprofile wrapper to convert proto into pprofile. + +# One or more tracking issues or pull requests related to the change +issues: [10401] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/.chloggen/profile-testdata.yaml b/.chloggen/profile-testdata.yaml new file mode 100644 index 00000000000..fb2be1ee340 --- /dev/null +++ b/.chloggen/profile-testdata.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: pdata/testdata + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add pdata testdata for profiles. + +# One or more tracking issues or pull requests related to the change +issues: [10401] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/Makefile b/Makefile index 067da69bd5d..60ee82a7681 100644 --- a/Makefile +++ b/Makefile @@ -284,6 +284,7 @@ check-contrib: -replace go.opentelemetry.io/collector/otelcol/otelcoltest=$(CURDIR)/otelcol/otelcoltest \ -replace go.opentelemetry.io/collector/pdata=$(CURDIR)/pdata \ -replace go.opentelemetry.io/collector/pdata/testdata=$(CURDIR)/pdata/testdata \ + -replace go.opentelemetry.io/collector/pdata/pprofile=$(CURDIR)/pdata/pprofile \ -replace go.opentelemetry.io/collector/processor=$(CURDIR)/processor \ -replace go.opentelemetry.io/collector/processor/batchprocessor=$(CURDIR)/processor/batchprocessor \ -replace go.opentelemetry.io/collector/processor/memorylimiterprocessor=$(CURDIR)/processor/memorylimiterprocessor \ @@ -341,6 +342,7 @@ restore-contrib: -dropreplace go.opentelemetry.io/collector/otelcol/otelcoltest \ -dropreplace go.opentelemetry.io/collector/pdata \ -dropreplace go.opentelemetry.io/collector/pdata/testdata \ + -dropreplace go.opentelemetry.io/collector/pdata/pprofile \ -dropreplace go.opentelemetry.io/collector/processor \ -dropreplace go.opentelemetry.io/collector/processor/batchprocessor \ -dropreplace go.opentelemetry.io/collector/processor/memorylimiterprocessor \ diff --git a/cmd/builder/internal/builder/main_test.go b/cmd/builder/internal/builder/main_test.go index fa0c0d35d24..ea39bcf785c 100644 --- a/cmd/builder/internal/builder/main_test.go +++ b/cmd/builder/internal/builder/main_test.go @@ -78,6 +78,7 @@ var ( "/otelcol", "/pdata", "/pdata/testdata", + "/pdata/pprofile", "/semconv", "/service", } diff --git a/cmd/mdatagen/go.mod b/cmd/mdatagen/go.mod index 45649111b17..e96e33fbcc4 100644 --- a/cmd/mdatagen/go.mod +++ b/cmd/mdatagen/go.mod @@ -87,3 +87,5 @@ retract ( v0.76.1 v0.65.0 ) + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/cmd/otelcorecol/builder-config.yaml b/cmd/otelcorecol/builder-config.yaml index 6197cd1c540..5630bd9ac80 100644 --- a/cmd/otelcorecol/builder-config.yaml +++ b/cmd/otelcorecol/builder-config.yaml @@ -1,8 +1,8 @@ # NOTE: # This builder configuration is NOT used to build any official binary. -# To see the builder manifests used for official binaries, +# To see the builder manifests used for official binaries, # check https://github.com/open-telemetry/opentelemetry-collector-releases -# +# # For the OpenTelemetry Collector Core official distribution sources, check # https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol @@ -77,6 +77,7 @@ replaces: - go.opentelemetry.io/collector/featuregate => ../../featuregate - go.opentelemetry.io/collector/pdata => ../../pdata - go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata + - go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile - go.opentelemetry.io/collector/processor => ../../processor - go.opentelemetry.io/collector/receiver => ../../receiver - go.opentelemetry.io/collector/receiver/nopreceiver => ../../receiver/nopreceiver diff --git a/cmd/otelcorecol/go.mod b/cmd/otelcorecol/go.mod index 19864d8c1f6..40274203ee1 100644 --- a/cmd/otelcorecol/go.mod +++ b/cmd/otelcorecol/go.mod @@ -203,6 +203,8 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile + replace go.opentelemetry.io/collector/processor => ../../processor replace go.opentelemetry.io/collector/receiver => ../../receiver diff --git a/config/configgrpc/go.mod b/config/configgrpc/go.mod index 7d3954590d3..82b0d2755d8 100644 --- a/config/configgrpc/go.mod +++ b/config/configgrpc/go.mod @@ -52,6 +52,7 @@ require ( go.opentelemetry.io/collector/confmap v0.103.0 // indirect go.opentelemetry.io/collector/extension v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect go.opentelemetry.io/otel/metric v1.27.0 // indirect go.opentelemetry.io/otel/sdk v1.27.0 // indirect @@ -94,6 +95,8 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile + replace go.opentelemetry.io/collector/component => ../../component replace go.opentelemetry.io/collector/consumer => ../../consumer diff --git a/config/confighttp/go.mod b/config/confighttp/go.mod index beb57170b41..cbca50bb8c1 100644 --- a/config/confighttp/go.mod +++ b/config/confighttp/go.mod @@ -91,3 +91,5 @@ replace go.opentelemetry.io/collector/component => ../../component replace go.opentelemetry.io/collector/consumer => ../../consumer replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/config/internal/go.mod b/config/internal/go.mod index 302136bd7f5..7935ffc8420 100644 --- a/config/internal/go.mod +++ b/config/internal/go.mod @@ -33,3 +33,5 @@ replace go.opentelemetry.io/collector/consumer => ../../consumer replace go.opentelemetry.io/collector/component => ../../component replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/confmap/converter/expandconverter/go.mod b/confmap/converter/expandconverter/go.mod index f622a5442d2..e2c0bd1125f 100644 --- a/confmap/converter/expandconverter/go.mod +++ b/confmap/converter/expandconverter/go.mod @@ -40,3 +40,5 @@ replace go.opentelemetry.io/collector/pdata => ../../../pdata replace go.opentelemetry.io/collector/featuregate => ../../../featuregate replace go.opentelemetry.io/collector/consumer => ../../../consumer + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../../pdata/pprofile diff --git a/connector/forwardconnector/go.mod b/connector/forwardconnector/go.mod index d24d5022777..ee5c2b80467 100644 --- a/connector/forwardconnector/go.mod +++ b/connector/forwardconnector/go.mod @@ -77,3 +77,5 @@ retract ( ) replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/connector/go.mod b/connector/go.mod index ec511264df7..4bb65875437 100644 --- a/connector/go.mod +++ b/connector/go.mod @@ -31,6 +31,7 @@ require ( github.com/prometheus/common v0.54.0 // indirect github.com/prometheus/procfs v0.15.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.103.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/otel v1.27.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect go.opentelemetry.io/otel/metric v1.27.0 // indirect @@ -61,3 +62,5 @@ replace go.opentelemetry.io/collector/featuregate => ../featuregate replace go.opentelemetry.io/collector/pdata => ../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../pdata/testdata + +replace go.opentelemetry.io/collector/pdata/pprofile => ../pdata/pprofile diff --git a/consumer/go.mod b/consumer/go.mod index 121a85a3ca1..5afc53a9c3d 100644 --- a/consumer/go.mod +++ b/consumer/go.mod @@ -13,10 +13,10 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/kr/text v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/sys v0.18.0 // indirect @@ -31,6 +31,8 @@ replace go.opentelemetry.io/collector/pdata => ../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../pdata/pprofile + retract ( v0.76.0 // Depends on retracted pdata v1.0.0-rc10 module, use v0.76.1 v0.69.0 // Release failed, use v0.69.1 diff --git a/consumer/go.sum b/consumer/go.sum index 4ae987d011c..ff7072f4244 100644 --- a/consumer/go.sum +++ b/consumer/go.sum @@ -1,4 +1,3 @@ -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/exporter/debugexporter/go.mod b/exporter/debugexporter/go.mod index d7b06607b5d..dc28381d31e 100644 --- a/exporter/debugexporter/go.mod +++ b/exporter/debugexporter/go.mod @@ -43,6 +43,7 @@ require ( go.opentelemetry.io/collector/config/configretry v0.103.0 // indirect go.opentelemetry.io/collector/extension v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/collector/receiver v0.103.0 // indirect go.opentelemetry.io/otel v1.27.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect @@ -76,6 +77,8 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile + replace go.opentelemetry.io/collector/receiver => ../../receiver replace go.opentelemetry.io/collector/extension => ../../extension diff --git a/exporter/go.mod b/exporter/go.mod index 6b36eb211cf..c84500495f6 100644 --- a/exporter/go.mod +++ b/exporter/go.mod @@ -51,6 +51,7 @@ require ( github.com/prometheus/procfs v0.15.0 // indirect go.opentelemetry.io/collector/confmap v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/text v0.15.0 // indirect @@ -75,6 +76,8 @@ replace go.opentelemetry.io/collector/pdata => ../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../pdata/pprofile + replace go.opentelemetry.io/collector/receiver => ../receiver retract v0.76.0 // Depends on retracted pdata v1.0.0-rc10 module diff --git a/exporter/loggingexporter/go.mod b/exporter/loggingexporter/go.mod index 70b16b95bc1..c03f7bca6e7 100644 --- a/exporter/loggingexporter/go.mod +++ b/exporter/loggingexporter/go.mod @@ -88,3 +88,5 @@ retract ( replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry replace go.opentelemetry.io/collector/config/configretry => ../../config/configretry + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/exporter/nopexporter/go.mod b/exporter/nopexporter/go.mod index 11b194e85b7..dfee2fb64d2 100644 --- a/exporter/nopexporter/go.mod +++ b/exporter/nopexporter/go.mod @@ -78,3 +78,5 @@ replace go.opentelemetry.io/collector/confmap => ../../confmap replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry replace go.opentelemetry.io/collector/extension => ../../extension + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/exporter/otlpexporter/go.mod b/exporter/otlpexporter/go.mod index 171134158ab..0582666f260 100644 --- a/exporter/otlpexporter/go.mod +++ b/exporter/otlpexporter/go.mod @@ -59,6 +59,7 @@ require ( go.opentelemetry.io/collector/extension v0.103.0 // indirect go.opentelemetry.io/collector/extension/auth v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/collector/receiver v0.103.0 // indirect go.opentelemetry.io/contrib/config v0.7.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect @@ -116,6 +117,8 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile + replace go.opentelemetry.io/collector/receiver => ../../receiver replace go.opentelemetry.io/collector/consumer => ../../consumer diff --git a/exporter/otlphttpexporter/go.mod b/exporter/otlphttpexporter/go.mod index 9611315bdcd..61c34d04c25 100644 --- a/exporter/otlphttpexporter/go.mod +++ b/exporter/otlphttpexporter/go.mod @@ -115,6 +115,8 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile + replace go.opentelemetry.io/collector/receiver => ../../receiver replace go.opentelemetry.io/collector/consumer => ../../consumer diff --git a/extension/ballastextension/go.mod b/extension/ballastextension/go.mod index c174281d886..40eec48ca11 100644 --- a/extension/ballastextension/go.mod +++ b/extension/ballastextension/go.mod @@ -81,3 +81,5 @@ retract ( replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/extension/memorylimiterextension/go.mod b/extension/memorylimiterextension/go.mod index 892db56f289..85017f19736 100644 --- a/extension/memorylimiterextension/go.mod +++ b/extension/memorylimiterextension/go.mod @@ -75,3 +75,5 @@ replace go.opentelemetry.io/collector/consumer => ../../consumer replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/extension/zpagesextension/go.mod b/extension/zpagesextension/go.mod index 39eac98fb79..94fbb642050 100644 --- a/extension/zpagesextension/go.mod +++ b/extension/zpagesextension/go.mod @@ -113,3 +113,5 @@ replace go.opentelemetry.io/collector/config/configauth => ../../config/configau replace go.opentelemetry.io/collector/extension/auth => ../auth replace go.opentelemetry.io/collector/config/confighttp => ../../config/confighttp + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/go.mod b/go.mod index 06653587634..9531c1b08f0 100644 --- a/go.mod +++ b/go.mod @@ -57,6 +57,7 @@ require ( github.com/tklauser/numcpus v0.6.1 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.103.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/otel v1.27.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 // indirect @@ -101,3 +102,5 @@ retract ( v0.57.0 // Release failed, use v0.57.2 v0.32.0 // Contains incomplete metrics transition to proto 0.9.0, random components are not working. ) + +replace go.opentelemetry.io/collector/pdata/pprofile => ./pdata/pprofile diff --git a/internal/e2e/go.mod b/internal/e2e/go.mod index 648508434b8..62b7951791e 100644 --- a/internal/e2e/go.mod +++ b/internal/e2e/go.mod @@ -62,6 +62,7 @@ require ( go.opentelemetry.io/collector/extension v0.103.0 // indirect go.opentelemetry.io/collector/extension/auth v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/contrib/config v0.7.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect @@ -121,6 +122,8 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile + replace go.opentelemetry.io/collector/consumer => ../../consumer replace go.opentelemetry.io/collector/receiver/otlpreceiver => ../../receiver/otlpreceiver diff --git a/otelcol/go.mod b/otelcol/go.mod index 9ad6a104267..29c3cfd6540 100644 --- a/otelcol/go.mod +++ b/otelcol/go.mod @@ -70,6 +70,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/collector/consumer v0.103.0 // indirect go.opentelemetry.io/collector/pdata v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/collector/pdata/testdata v0.103.0 // indirect go.opentelemetry.io/collector/semconv v0.103.0 // indirect go.opentelemetry.io/contrib/config v0.7.0 // indirect @@ -109,6 +110,8 @@ replace go.opentelemetry.io/collector/pdata => ../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../pdata/pprofile + replace go.opentelemetry.io/collector/extension/zpagesextension => ../extension/zpagesextension replace go.opentelemetry.io/collector/extension => ../extension diff --git a/otelcol/otelcoltest/go.mod b/otelcol/otelcoltest/go.mod index 1a415596200..0a786db0a56 100644 --- a/otelcol/otelcoltest/go.mod +++ b/otelcol/otelcoltest/go.mod @@ -65,6 +65,7 @@ require ( go.opentelemetry.io/collector/consumer v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect go.opentelemetry.io/collector/pdata v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/collector/pdata/testdata v0.103.0 // indirect go.opentelemetry.io/collector/semconv v0.103.0 // indirect go.opentelemetry.io/contrib/config v0.7.0 // indirect @@ -136,6 +137,8 @@ replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata replace go.opentelemetry.io/collector/pdata => ../../pdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile + replace go.opentelemetry.io/collector/confmap/provider/httpsprovider => ../../confmap/provider/httpsprovider replace go.opentelemetry.io/collector/connector => ../../connector diff --git a/pdata/internal/wrapper_profiles.go b/pdata/internal/wrapper_profiles.go new file mode 100644 index 00000000000..564c8945862 --- /dev/null +++ b/pdata/internal/wrapper_profiles.go @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package internal // import "go.opentelemetry.io/collector/pdata/internal" + +import ( + otlpcollectorprofile "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/profiles/v1experimental" + otlpprofile "go.opentelemetry.io/collector/pdata/internal/data/protogen/profiles/v1experimental" +) + +type Profiles struct { + orig *otlpcollectorprofile.ExportProfilesServiceRequest + state *State +} + +func GetOrigProfiles(ms Profiles) *otlpcollectorprofile.ExportProfilesServiceRequest { + return ms.orig +} + +func GetProfilesState(ms Profiles) *State { + return ms.state +} + +func SetProfilesState(ms Profiles, state State) { + *ms.state = state +} + +func NewProfiles(orig *otlpcollectorprofile.ExportProfilesServiceRequest, state *State) Profiles { + return Profiles{orig: orig, state: state} +} + +// ProfilesToProto internal helper to convert Profiles to protobuf representation. +func ProfilesToProto(l Profiles) otlpprofile.ProfilesData { + return otlpprofile.ProfilesData{ + ResourceProfiles: l.orig.ResourceProfiles, + } +} + +// ProfilesFromProto internal helper to convert protobuf representation to Profiles. +// This function set exclusive state assuming that it's called only once per Profiles. +func ProfilesFromProto(orig otlpprofile.ProfilesData) Profiles { + state := StateMutable + return NewProfiles(&otlpcollectorprofile.ExportProfilesServiceRequest{ + ResourceProfiles: orig.ResourceProfiles, + }, &state) +} diff --git a/pdata/pprofile/profiles.go b/pdata/pprofile/profiles.go new file mode 100644 index 00000000000..4a81effa3d2 --- /dev/null +++ b/pdata/pprofile/profiles.go @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile" + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpcollectorprofile "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/profiles/v1experimental" +) + +// profiles is the top-level struct that is propagated through the profiles pipeline. +// Use NewProfiles to create new instance, zero-initialized instance is not valid for use. +type Profiles internal.Profiles + +func newProfiles(orig *otlpcollectorprofile.ExportProfilesServiceRequest) Profiles { + state := internal.StateMutable + return Profiles(internal.NewProfiles(orig, &state)) +} + +func (ms Profiles) getOrig() *otlpcollectorprofile.ExportProfilesServiceRequest { + return internal.GetOrigProfiles(internal.Profiles(ms)) +} + +func (ms Profiles) getState() *internal.State { + return internal.GetProfilesState(internal.Profiles(ms)) +} + +// NewProfiles creates a new Profiles struct. +func NewProfiles() Profiles { + return newProfiles(&otlpcollectorprofile.ExportProfilesServiceRequest{}) +} + +// IsReadOnly returns true if this ResourceProfiles instance is read-only. +func (ms Profiles) IsReadOnly() bool { + return *ms.getState() == internal.StateReadOnly +} + +// CopyTo copies the Profiles instance overriding the destination. +func (ms Profiles) CopyTo(dest Profiles) { + ms.ResourceProfiles().CopyTo(dest.ResourceProfiles()) +} + +// ResourceProfiles returns the ResourceProfilesSlice associated with this Profiles. +func (ms Profiles) ResourceProfiles() ResourceProfilesSlice { + return newResourceProfilesSlice(&ms.getOrig().ResourceProfiles, internal.GetProfilesState(internal.Profiles(ms))) +} + +// MarkReadOnly marks the ResourceProfiles as shared so that no further modifications can be done on it. +func (ms Profiles) MarkReadOnly() { + internal.SetProfilesState(internal.Profiles(ms), internal.StateReadOnly) +} diff --git a/pdata/pprofile/profiles_test.go b/pdata/pprofile/profiles_test.go new file mode 100644 index 00000000000..010637fcd31 --- /dev/null +++ b/pdata/pprofile/profiles_test.go @@ -0,0 +1,69 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pprofile + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/pcommon" +) + +func TestReadOnlyProfilesInvalidUsage(t *testing.T) { + profiles := NewProfiles() + assert.False(t, profiles.IsReadOnly()) + res := profiles.ResourceProfiles().AppendEmpty().Resource() + res.Attributes().PutStr("k1", "v1") + profiles.MarkReadOnly() + assert.True(t, profiles.IsReadOnly()) + assert.Panics(t, func() { res.Attributes().PutStr("k2", "v2") }) +} + +func BenchmarkProfilesUsage(b *testing.B) { + profiles := NewProfiles() + fillTestResourceProfilesSlice(profiles.ResourceProfiles()) + ts := pcommon.NewTimestampFromTime(time.Now()) + + b.ReportAllocs() + b.ResetTimer() + + for bb := 0; bb < b.N; bb++ { + for i := 0; i < profiles.ResourceProfiles().Len(); i++ { + rs := profiles.ResourceProfiles().At(i) + res := rs.Resource() + res.Attributes().PutStr("foo", "bar") + v, ok := res.Attributes().Get("foo") + assert.True(b, ok) + assert.Equal(b, "bar", v.Str()) + v.SetStr("new-bar") + assert.Equal(b, "new-bar", v.Str()) + res.Attributes().Remove("foo") + for j := 0; j < rs.ScopeProfiles().Len(); j++ { + iss := rs.ScopeProfiles().At(j) + iss.Scope().SetName("new_test_name") + assert.Equal(b, "new_test_name", iss.Scope().Name()) + for k := 0; k < iss.Profiles().Len(); k++ { + s := iss.Profiles().At(k) + s.ProfileID().FromRaw([]byte("profile_id")) + assert.Equal(b, "profile_id", string(s.ProfileID().AsRaw())) + s.SetStartTime(ts) + assert.Equal(b, ts, s.StartTime()) + s.SetEndTime(ts) + assert.Equal(b, ts, s.EndTime()) + } + s := iss.Profiles().AppendEmpty() + s.ProfileID().FromRaw([]byte("new_profile_id")) + s.SetStartTime(ts) + s.SetEndTime(ts) + s.Attributes().PutStr("foo1", "bar1") + s.Attributes().PutStr("foo2", "bar2") + iss.Profiles().RemoveIf(func(lr ProfileContainer) bool { + return string(lr.ProfileID().AsRaw()) == "new_profile_id" + }) + } + } + } +} diff --git a/pdata/testdata/go.mod b/pdata/testdata/go.mod index b310727a48f..dd15ae52815 100644 --- a/pdata/testdata/go.mod +++ b/pdata/testdata/go.mod @@ -2,7 +2,10 @@ module go.opentelemetry.io/collector/pdata/testdata go 1.21.0 -require go.opentelemetry.io/collector/pdata v1.10.0 +require ( + go.opentelemetry.io/collector/pdata v1.10.0 + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 +) require ( github.com/gogo/protobuf v1.3.2 // indirect @@ -19,3 +22,5 @@ require ( ) replace go.opentelemetry.io/collector/pdata => ../ + +replace go.opentelemetry.io/collector/pdata/pprofile => ../pprofile diff --git a/pdata/testdata/profile.go b/pdata/testdata/profile.go new file mode 100644 index 00000000000..04df7cc06f8 --- /dev/null +++ b/pdata/testdata/profile.go @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package testdata // import "go.opentelemetry.io/collector/pdata/testdata" + +import ( + "time" + + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/pprofile" +) + +var ( + profileStartTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 12, 321, time.UTC)) + profileEndTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC)) +) + +// GenerateProfiles generates dummy profiling data for tests +func GenerateProfiles(profilesCount int) pprofile.Profiles { + td := pprofile.NewProfiles() + initResource(td.ResourceProfiles().AppendEmpty().Resource()) + ss := td.ResourceProfiles().At(0).ScopeProfiles().AppendEmpty().Profiles() + ss.EnsureCapacity(profilesCount) + for i := 0; i < profilesCount; i++ { + switch i % 2 { + case 0: + fillProfileOne(ss.AppendEmpty()) + case 1: + fillProfileTwo(ss.AppendEmpty()) + } + } + return td +} + +func fillProfileOne(profile pprofile.ProfileContainer) { + profile.ProfileID().FromRaw([]byte("profileA")) + profile.SetStartTime(profileStartTimestamp) + profile.SetEndTime(profileEndTimestamp) + profile.SetDroppedAttributesCount(1) +} + +func fillProfileTwo(profile pprofile.ProfileContainer) { + profile.ProfileID().FromRaw([]byte("profileB")) + profile.SetStartTime(profileStartTimestamp) + profile.SetEndTime(profileEndTimestamp) +} diff --git a/processor/batchprocessor/go.mod b/processor/batchprocessor/go.mod index 5b9cdc0af1d..82ae287c710 100644 --- a/processor/batchprocessor/go.mod +++ b/processor/batchprocessor/go.mod @@ -44,6 +44,7 @@ require ( github.com/prometheus/common v0.54.0 // indirect github.com/prometheus/procfs v0.15.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect go.opentelemetry.io/otel/sdk v1.27.0 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -78,3 +79,5 @@ retract ( ) replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/processor/go.mod b/processor/go.mod index 97acff2356d..d202175e947 100644 --- a/processor/go.mod +++ b/processor/go.mod @@ -34,6 +34,7 @@ require ( github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.54.0 // indirect github.com/prometheus/procfs v0.15.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect go.opentelemetry.io/otel/sdk v1.27.0 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -60,4 +61,6 @@ replace go.opentelemetry.io/collector/pdata => ../pdata replace go.opentelemetry.io/collector/pdata/testdata => ../pdata/testdata +replace go.opentelemetry.io/collector/pdata/pprofile => ../pdata/pprofile + replace go.opentelemetry.io/collector/config/configtelemetry => ../config/configtelemetry diff --git a/processor/memorylimiterprocessor/go.mod b/processor/memorylimiterprocessor/go.mod index 69b5c61fa77..742ec39145c 100644 --- a/processor/memorylimiterprocessor/go.mod +++ b/processor/memorylimiterprocessor/go.mod @@ -45,6 +45,7 @@ require ( github.com/yusufpapurcu/wmi v1.2.4 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/collector/pdata/testdata v0.103.0 // indirect go.opentelemetry.io/otel v1.27.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect @@ -85,3 +86,5 @@ retract ( ) replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/receiver/go.mod b/receiver/go.mod index c1a73d56abb..4df1edb183a 100644 --- a/receiver/go.mod +++ b/receiver/go.mod @@ -62,3 +62,5 @@ replace go.opentelemetry.io/collector/pdata/testdata => ../pdata/testdata retract v0.76.0 // Depends on retracted pdata v1.0.0-rc10 module replace go.opentelemetry.io/collector/config/configtelemetry => ../config/configtelemetry + +replace go.opentelemetry.io/collector/pdata/pprofile => ../pdata/pprofile diff --git a/receiver/nopreceiver/go.mod b/receiver/nopreceiver/go.mod index c034cd2f02c..f883f64c2f6 100644 --- a/receiver/nopreceiver/go.mod +++ b/receiver/nopreceiver/go.mod @@ -71,3 +71,5 @@ replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/con replace go.opentelemetry.io/collector => ../.. replace go.opentelemetry.io/collector/featuregate => ../../featuregate + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/receiver/otlpreceiver/go.mod b/receiver/otlpreceiver/go.mod index 07da9641f2d..3b24dc33d7c 100644 --- a/receiver/otlpreceiver/go.mod +++ b/receiver/otlpreceiver/go.mod @@ -61,6 +61,7 @@ require ( go.opentelemetry.io/collector/extension v0.103.0 // indirect go.opentelemetry.io/collector/extension/auth v0.103.0 // indirect go.opentelemetry.io/collector/featuregate v1.10.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/contrib/config v0.7.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect @@ -128,3 +129,5 @@ retract ( v0.76.0 // Depends on retracted pdata v1.0.0-rc10 module, use v0.76.1 v0.69.0 // Release failed, use v0.69.1 ) + +replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile diff --git a/service/go.mod b/service/go.mod index f5367ba0e72..24d125be540 100644 --- a/service/go.mod +++ b/service/go.mod @@ -84,6 +84,7 @@ require ( go.opentelemetry.io/collector/config/configtls v0.103.0 // indirect go.opentelemetry.io/collector/config/internal v0.103.0 // indirect go.opentelemetry.io/collector/extension/auth v0.103.0 // indirect + go.opentelemetry.io/collector/pdata/pprofile v0.103.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect go.opentelemetry.io/contrib/zpages v0.52.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect @@ -146,3 +147,5 @@ replace go.opentelemetry.io/collector/config/internal => ../config/internal replace go.opentelemetry.io/collector/config/configtls => ../config/configtls replace go.opentelemetry.io/collector/config/configcompression => ../config/configcompression + +replace go.opentelemetry.io/collector/pdata/pprofile => ../pdata/pprofile