-
Notifications
You must be signed in to change notification settings - Fork 267
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: initial pyroscope integration #1006
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ecfaa2b
feat: initial pyroscope integration
evan-forbes 2848044
Merge branch 'v0.34.x-celestia' into evan/pyroscope-integration
evan-forbes 1f6fcd3
Merge branch 'v0.34.x-celestia' into evan/pyroscope-integration
evan-forbes 422e63f
Merge branch 'v0.34.x-celestia' into evan/pyroscope-integration
evan-forbes a9859eb
fix: add missing quotes
evan-forbes 6446c72
fix: linters
evan-forbes 310cd2a
fix: linter
evan-forbes 95f26b7
Apply suggestions from code review
evan-forbes ea7667d
refactor: make setupPyroscrope a function instead of a method
evan-forbes c9794fa
feat: add pyroscope profile types to the config
evan-forbes da83f3e
Merge branch 'evan/pyroscope-integration' of github.com:celestiaorg/c…
evan-forbes 954a792
fix: use the noop pyroscope logger by passing nil
evan-forbes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package node | ||
|
||
import ( | ||
"github.com/pyroscope-io/client/pyroscope" | ||
|
||
otelpyroscope "github.com/pyroscope-io/otel-profiling-go" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace" | ||
"go.opentelemetry.io/otel/propagation" | ||
|
||
sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||
) | ||
|
||
// setupPyroscope sets up pyroscope profiler and optionally tracing. | ||
func (n *Node) setupPyroscope(addr, nodeID string, tracing bool) (*pyroscope.Profiler, *sdktrace.TracerProvider, error) { | ||
staheri14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tp, err := tracerProviderDebug() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
labels := map[string]string{"node_id": nodeID} | ||
|
||
if tracing { | ||
if _, err = setupTracing(addr, labels); err != nil { | ||
return nil, nil, err | ||
} | ||
} else { | ||
tp = nil | ||
} | ||
|
||
pflr, err := pyroscope.Start(pyroscope.Config{ | ||
ApplicationName: "celestia", | ||
ServerAddress: addr, | ||
Logger: pyroscope.StandardLogger, | ||
Tags: labels, | ||
}) | ||
|
||
return pflr, tp, err | ||
} | ||
|
||
func setupTracing(addr string, labels map[string]string) (tp *sdktrace.TracerProvider, err error) { | ||
tp, err = tracerProviderDebug() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Set the Tracer Provider and the W3C Trace Context propagator as globals. | ||
// We wrap the tracer provider to also annotate goroutines with Span ID so | ||
// that pprof would add corresponding labels to profiling samples. | ||
otel.SetTracerProvider(otelpyroscope.NewTracerProvider(tp, | ||
otelpyroscope.WithAppName("celestia"), | ||
otelpyroscope.WithRootSpanOnly(true), | ||
otelpyroscope.WithAddSpanName(true), | ||
otelpyroscope.WithPyroscopeURL(addr), | ||
otelpyroscope.WithProfileBaselineLabels(labels), | ||
otelpyroscope.WithProfileBaselineURL(true), | ||
otelpyroscope.WithProfileURL(true), | ||
)) | ||
|
||
// Register the trace context and baggage propagators so data is propagated across services/processes. | ||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator( | ||
propagation.TraceContext{}, | ||
propagation.Baggage{}, | ||
)) | ||
|
||
return tp, err | ||
} | ||
|
||
func tracerProviderDebug() (*sdktrace.TracerProvider, error) { | ||
exp, err := stdouttrace.New(stdouttrace.WithPrettyPrint()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sdktrace.NewBatchSpanProcessor(exp))), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I do not know why the linter started complaining for this here, but this seemed like the best solution
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.
seems resolved by 310cd2a