Files
MarioandGitHub e0354d1bed Update Prometheus to v0.307.2, OTel collector contrib to v0.138.0, OTel to v1.44.0 (#5810)
* Update Prometheus to v0.307.2

* Update otel collector

* Update OTel collector
2025-10-28 11:30:17 +01:00

81 lines
2.7 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package pprofileotlp // import "go.opentelemetry.io/collector/pdata/pprofile/pprofileotlp"
import (
"slices"
"go.opentelemetry.io/collector/pdata/internal"
otlpcollectorprofile "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/profiles/v1development"
"go.opentelemetry.io/collector/pdata/internal/json"
"go.opentelemetry.io/collector/pdata/internal/otlp"
"go.opentelemetry.io/collector/pdata/pprofile"
)
// ExportRequest represents the request for gRPC/HTTP client/server.
// It's a wrapper for pprofile.Profiles data.
type ExportRequest struct {
orig *otlpcollectorprofile.ExportProfilesServiceRequest
state *internal.State
}
// NewExportRequest returns an empty ExportRequest.
func NewExportRequest() ExportRequest {
return ExportRequest{
orig: &otlpcollectorprofile.ExportProfilesServiceRequest{},
state: internal.NewState(),
}
}
// NewExportRequestFromProfiles returns a ExportRequest from pprofile.Profiles.
// Because ExportRequest is a wrapper for pprofile.Profiles,
// any changes to the provided Profiles struct will be reflected in the ExportRequest and vice versa.
func NewExportRequestFromProfiles(td pprofile.Profiles) ExportRequest {
return ExportRequest{
orig: internal.GetOrigProfiles(internal.Profiles(td)),
state: internal.GetProfilesState(internal.Profiles(td)),
}
}
// MarshalProto marshals ExportRequest into proto bytes.
func (ms ExportRequest) MarshalProto() ([]byte, error) {
size := internal.SizeProtoOrigExportProfilesServiceRequest(ms.orig)
buf := make([]byte, size)
_ = internal.MarshalProtoOrigExportProfilesServiceRequest(ms.orig, buf)
return buf, nil
}
// UnmarshalProto unmarshalls ExportRequest from proto bytes.
func (ms ExportRequest) UnmarshalProto(data []byte) error {
err := internal.UnmarshalProtoOrigExportProfilesServiceRequest(ms.orig, data)
if err != nil {
return err
}
otlp.MigrateProfiles(ms.orig.ResourceProfiles)
return nil
}
// MarshalJSON marshals ExportRequest into JSON bytes.
func (ms ExportRequest) MarshalJSON() ([]byte, error) {
dest := json.BorrowStream(nil)
defer json.ReturnStream(dest)
internal.MarshalJSONOrigExportProfilesServiceRequest(ms.orig, dest)
if dest.Error() != nil {
return nil, dest.Error()
}
return slices.Clone(dest.Buffer()), nil
}
// UnmarshalJSON unmarshalls ExportRequest from JSON bytes.
func (ms ExportRequest) UnmarshalJSON(data []byte) error {
iter := json.BorrowIterator(data)
defer json.ReturnIterator(iter)
internal.UnmarshalJSONOrigExportProfilesServiceRequest(ms.orig, iter)
return iter.Error()
}
func (ms ExportRequest) Profiles() pprofile.Profiles {
return pprofile.Profiles(internal.NewProfiles(ms.orig, ms.state))
}