-
Notifications
You must be signed in to change notification settings - Fork 576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(otlp): experimental otlp support #2177
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
"strings" | ||
|
||
"github.com/bufbuild/connect-go" | ||
"github.com/felixge/fgprof" | ||
Check failure on line 16 in pkg/api/api.go
|
||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/gorilla/mux" | ||
|
@@ -21,6 +21,7 @@ | |
grpcgw "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" | ||
"github.com/weaveworks/common/middleware" | ||
"github.com/weaveworks/common/server" | ||
"go.opentelemetry.io/collector/pdata/pprofile/pprofileotlp" | ||
|
||
"github.com/grafana/pyroscope/public" | ||
|
||
|
@@ -37,6 +38,7 @@ | |
"github.com/grafana/pyroscope/pkg/frontend" | ||
"github.com/grafana/pyroscope/pkg/frontend/frontendpb/frontendpbconnect" | ||
"github.com/grafana/pyroscope/pkg/ingester" | ||
"github.com/grafana/pyroscope/pkg/ingester/otlp" | ||
"github.com/grafana/pyroscope/pkg/ingester/pyroscope" | ||
"github.com/grafana/pyroscope/pkg/querier" | ||
"github.com/grafana/pyroscope/pkg/scheduler" | ||
|
@@ -197,13 +199,19 @@ | |
// RegisterDistributor registers the endpoints associated with the distributor. | ||
func (a *API) RegisterDistributor(d *distributor.Distributor) { | ||
pyroscopeHandler := pyroscope.NewPyroscopeIngestHandler(d, a.logger) | ||
otlpHandler := otlp.NewOTLPIngestHandler(d, a.logger) | ||
a.RegisterRoute("/ingest", pyroscopeHandler, true, true, "POST") | ||
a.RegisterRoute("/pyroscope/ingest", pyroscopeHandler, true, true, "POST") | ||
pushv1connect.RegisterPusherServiceHandler(a.server.HTTP, d, a.grpcAuthMiddleware) | ||
a.RegisterRoute("/distributor/ring", d, false, true, "GET", "POST") | ||
a.indexPage.AddLinks(defaultWeight, "Distributor", []IndexPageLink{ | ||
{Desc: "Ring status", Path: "/distributor/ring"}, | ||
}) | ||
|
||
pprofileotlp.RegisterGRPCServer(a.server.GRPC, otlpHandler) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just so you know I don't think we expose GRPC endpoint anywhere in our infra nor in helm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cyriltovena yeah we might need a separate grpc server |
||
|
||
// TODO(@petethepig): implement http/protobuf and http/json support | ||
// a.RegisterRoute("/v1/profiles", otlpHandler, true, true, "POST") | ||
} | ||
|
||
// RegisterMemberlistKV registers the endpoints associated with the memberlist KV store. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package otlp | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/bufbuild/connect-go" | ||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/google/uuid" | ||
|
||
pushv1 "github.com/grafana/pyroscope/api/gen/proto/go/push/v1" | ||
typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1" | ||
"github.com/grafana/pyroscope/pkg/tenant" | ||
"go.opentelemetry.io/collector/pdata/pprofile" | ||
"go.opentelemetry.io/collector/pdata/pprofile/pprofileotlp" | ||
) | ||
|
||
type ingestHandler struct { | ||
pprofileotlp.UnimplementedGRPCServer | ||
svc PushService | ||
log log.Logger | ||
} | ||
|
||
// TODO(@petethepig): split http and grpc | ||
type Handler interface { | ||
http.Handler | ||
pprofileotlp.GRPCServer | ||
} | ||
|
||
type PushService interface { | ||
Push(ctx context.Context, req *connect.Request[pushv1.PushRequest]) (*connect.Response[pushv1.PushResponse], error) | ||
} | ||
|
||
func NewOTLPIngestHandler(svc PushService, l log.Logger) Handler { | ||
return &ingestHandler{ | ||
svc: svc, | ||
log: level.Error(l), | ||
} | ||
} | ||
|
||
// TODO(@petethepig): implement | ||
// TODO(@petethepig): split http and grpc | ||
func (h *ingestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
panic("not implemented") | ||
|
||
req := &pushv1.PushRequest{} | ||
_, err := h.svc.Push(r.Context(), connect.NewRequest(req)) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Write([]byte("Internal Server Error: " + err.Error())) | ||
return | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte("OK")) | ||
} | ||
|
||
// TODO(@petethepig): split http and grpc | ||
func (h *ingestHandler) Export(ctx context.Context, er pprofileotlp.ExportRequest) (pprofileotlp.ExportResponse, error) { | ||
// TODO(@petethepig): make it tenant-aware | ||
ctx = tenant.InjectTenantID(ctx, tenant.DefaultTenantID) | ||
|
||
h.log.Log("msg", "Export called") | ||
|
||
rps := er.Profiles().ResourceProfiles() | ||
for i := 0; i < rps.Len(); i++ { | ||
rp := rps.At(i) | ||
|
||
labelsDst := []*typesv1.LabelPair{} | ||
// TODO(@petethepig): make labels work | ||
labelsDst = append(labelsDst, &typesv1.LabelPair{ | ||
Name: "__name__", | ||
Value: "process_cpu", | ||
}) | ||
labelsDst = append(labelsDst, &typesv1.LabelPair{ | ||
Name: "service_name", | ||
Value: "otlp_test_app", | ||
}) | ||
labelsDst = append(labelsDst, &typesv1.LabelPair{ | ||
Name: "__delta__", | ||
Value: "false", | ||
}) | ||
labelsDst = append(labelsDst, &typesv1.LabelPair{ | ||
Name: "pyroscope_spy", | ||
Value: "unknown", | ||
}) | ||
|
||
sps := rp.ScopeProfiles() | ||
for j := 0; j < sps.Len(); j++ { | ||
sp := sps.At(j) | ||
for k := 0; k < sp.Profiles().Len(); k++ { | ||
p := sp.Profiles().At(k) | ||
|
||
pprofBytes := pprofile.OprofToPprof(p) | ||
|
||
req := &pushv1.PushRequest{ | ||
Series: []*pushv1.RawProfileSeries{ | ||
{ | ||
Labels: labelsDst, | ||
Samples: []*pushv1.RawSample{{ | ||
RawProfile: pprofBytes, | ||
ID: uuid.New().String(), | ||
}}, | ||
}, | ||
}, | ||
} | ||
_, err := h.svc.Push(ctx, connect.NewRequest(req)) | ||
if err != nil { | ||
h.log.Log("msg", "failed to push profile", "err", err) | ||
return pprofileotlp.NewExportResponse(), fmt.Errorf("failed to make a GRPC request: %w", err) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
return pprofileotlp.NewExportResponse(), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear, we won't have this dependency once this is ready to merge