-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from metrico/extension/pyroscope
pyroscope client extension
- Loading branch information
Showing
6 changed files
with
152 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Pyroscope client | ||
|
||
| Status | | | ||
|---------------------------|--------| | ||
| Stability | [beta] | | ||
|
||
|
||
The Extension provides the functionality to export the opentelementry collector profiles into a pyroscope compatible | ||
server. | ||
|
||
|
||
The following settings can be configured: | ||
|
||
- application_name (default = "opentelemetry-collector"): The name of the application as it will appear in Pyroscope. | ||
- tags (default = empty map): A map of key-value pairs for additional tags to be associated with the profiles. | ||
- server_address (default = "http://localhost:8062"): The URL of the Pyroscope server to which the profiles will be sent. | ||
- basic_auth (default = empty): Basic authentication configuration for connecting to the Pyroscope server. | ||
- username: The username for basic authentication. | ||
- password: The password for basic authentication. | ||
- profile_types (default = ["cpu", "alloc_objects", "alloc_space", "inuse_objects", "inuse_space"]): | ||
An array of profile types to collect and send to Pyroscope. | ||
- tenant_id (default = ""): The tenant ID to use when sending profiles to Pyroscope, for multi-tenancy support. | ||
|
||
Example: | ||
```yaml | ||
extensions: | ||
pyroscope: | ||
application_name: "my-collector" | ||
tags: | ||
environment: "production" | ||
region: "us-west-2" | ||
server_address: "http://localhost:8062" | ||
basic_auth: | ||
username: "user" | ||
password: "secret" | ||
profile_types: | ||
- "cpu" | ||
- "alloc_objects" | ||
- "inuse_space" | ||
service: | ||
extensions: [pyroscope] | ||
``` |
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,27 @@ | ||
package pyroscope | ||
|
||
import "go.opentelemetry.io/collector/component" | ||
|
||
type Config struct { | ||
ApplicationName string `json:"application_name"` | ||
Tags map[string]string `json:"tags"` | ||
ServerAddress string `json:"server_address"` | ||
BasicAuth BasicAuth `json:"basic_auth"` | ||
ProfileTypes []string `json:"profile_types"` | ||
TenantID string `json:"tenant_id"` | ||
} | ||
|
||
type BasicAuth struct { | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
} | ||
|
||
func defaultConfig() component.Config { | ||
return &Config{ | ||
ApplicationName: "opentelemetry-collector", | ||
ServerAddress: "http://localhost:8062", | ||
Tags: map[string]string{}, | ||
BasicAuth: BasicAuth{}, | ||
ProfileTypes: []string{"cpu", "alloc_objects", "alloc_space", "inuse_objects", "inuse_space"}, | ||
} | ||
} |
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,74 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package pyroscope | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
"github.com/grafana/pyroscope-go" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/extension" | ||
) | ||
|
||
var pyroscopeType = component.MustNewType("pyroscope") | ||
|
||
// NewNopCreateSettings returns a new nop settings for extension.Factory Create* functions. | ||
func NewPyroscopeCreateSettings() extension.CreateSettings { | ||
return extension.CreateSettings{ | ||
ID: component.NewIDWithName(pyroscopeType, uuid.NewString()), | ||
TelemetrySettings: componenttest.NewNopTelemetrySettings(), | ||
BuildInfo: component.NewDefaultBuildInfo(), | ||
} | ||
} | ||
|
||
// NewNopFactory returns an extension.Factory that constructs nop extensions. | ||
func NewFactory() extension.Factory { | ||
return extension.NewFactory( | ||
pyroscopeType, | ||
defaultConfig, | ||
func(ctx context.Context, settings extension.CreateSettings, config component.Config) (extension.Extension, error) { | ||
return &PyroscopeExtension{ | ||
config: config.(*Config), | ||
}, nil | ||
}, | ||
component.StabilityLevelStable) | ||
} | ||
|
||
type PyroscopeExtension struct { | ||
config *Config | ||
settings extension.CreateSettings | ||
ctx context.Context | ||
profiler *pyroscope.Profiler | ||
} | ||
|
||
func (p PyroscopeExtension) Start(ctx context.Context, host component.Host) error { | ||
cfg := pyroscope.Config{ | ||
ApplicationName: p.config.ApplicationName, | ||
|
||
// replace this with the address of pyroscope server | ||
ServerAddress: p.config.ServerAddress, | ||
|
||
// you can disable logging by setting this to nil | ||
Logger: pyroscope.StandardLogger, | ||
|
||
// Optional HTTP Basic authentication (Grafana Cloud) | ||
BasicAuthUser: p.config.BasicAuth.Username, | ||
BasicAuthPassword: p.config.BasicAuth.Password, | ||
Tags: p.config.Tags, | ||
TenantID: p.config.TenantID, | ||
ProfileTypes: nil, | ||
} | ||
for _, profileType := range p.config.ProfileTypes { | ||
cfg.ProfileTypes = append(cfg.ProfileTypes, pyroscope.ProfileType(profileType)) | ||
} | ||
var err error | ||
p.profiler, err = pyroscope.Start(cfg) | ||
return err | ||
} | ||
|
||
func (p PyroscopeExtension) Shutdown(ctx context.Context) error { | ||
return p.profiler.Stop() | ||
} |
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