Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ type Config struct {
DisableGCRuns bool // this will disable automatic runtime.GC runs between getting the heap profiles
HTTPHeaders map[string]string
HTTPClient remote.HTTPClient

// Deprecated: the field will be removed in future releases.
// Use BasicAuthUser and BasicAuthPassword instead.
AuthToken string // specify this token when using pyroscope cloud
// Deprecated: the field will be removed in future releases.
// Use UploadRate instead.
DisableAutomaticResets bool
// Deprecated: the field will be removed in future releases.
// DisableCumulativeMerge is ignored.
DisableCumulativeMerge bool
// Deprecated: the field will be removed in future releases.
// SampleRate is set to 100 and is not configurable.
SampleRate uint32
}

type Profiler struct {
Expand All @@ -59,7 +46,6 @@ func Start(cfg Config) (*Profiler, error) {
}

rc := remote.Config{
AuthToken: cfg.AuthToken,
TenantID: cfg.TenantID,
BasicAuthUser: cfg.BasicAuthUser,
BasicAuthPassword: cfg.BasicAuthPassword,
Expand All @@ -76,14 +62,13 @@ func Start(cfg Config) (*Profiler, error) {
}

sc := SessionConfig{
Upstream: uploader,
Logger: cfg.Logger,
AppName: cfg.ApplicationName,
Tags: cfg.Tags,
ProfilingTypes: cfg.ProfileTypes,
DisableGCRuns: cfg.DisableGCRuns,
DisableAutomaticResets: cfg.DisableAutomaticResets,
UploadRate: cfg.UploadRate,
Upstream: uploader,
Logger: cfg.Logger,
AppName: cfg.ApplicationName,
Tags: cfg.Tags,
ProfilingTypes: cfg.ProfileTypes,
DisableGCRuns: cfg.DisableGCRuns,
UploadRate: cfg.UploadRate,
}

s, err := NewSession(sc)
Expand Down
1 change: 0 additions & 1 deletion example/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func main() {
ApplicationName: "simple.golang.app-new",
ServerAddress: "http://localhost:4040",
Logger: pyroscope.StandardLogger,
AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"),
TenantID: os.Getenv("PYROSCOPE_TENANT_ID"),
BasicAuthUser: os.Getenv("PYROSCOPE_BASIC_AUTH_USER"),
BasicAuthPassword: os.Getenv("PYROSCOPE_BASIC_AUTH_PASSWORD"),
Expand Down
17 changes: 0 additions & 17 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pyroscope

import (
"bytes"
"math"
"runtime"
"runtime/debug"
"runtime/pprof"
Expand All @@ -20,8 +19,6 @@ type Session struct {
profileTypes []ProfileType
uploadRate time.Duration
disableGCRuns bool
// Deprecated: the field will be removed in future releases.
DisableAutomaticResets bool

logger Logger
stopOnce sync.Once
Expand Down Expand Up @@ -54,16 +51,6 @@ type SessionConfig struct {
ProfilingTypes []ProfileType
DisableGCRuns bool
UploadRate time.Duration

// Deprecated: the field will be removed in future releases.
// Use UploadRate instead.
DisableAutomaticResets bool
// Deprecated: the field will be removed in future releases.
// DisableCumulativeMerge is ignored.
DisableCumulativeMerge bool
// Deprecated: the field will be removed in future releases.
// SampleRate is set to 100 and is not configurable.
SampleRate uint32
}

type flush struct {
Expand All @@ -84,10 +71,6 @@ func NewSession(c SessionConfig) (*Session, error) {
c.Logger.Infof(" DisableGCRuns: %+v", c.DisableGCRuns)
c.Logger.Infof(" UploadRate: %+v", c.UploadRate)

if c.DisableAutomaticResets {
c.UploadRate = math.MaxInt64
}

appName, err := mergeTagsWithAppName(c.AppName, newSessionID(), c.Tags)
if err != nil {
return nil, err
Expand Down
33 changes: 2 additions & 31 deletions upstream/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"mime/multipart"
Expand All @@ -13,24 +12,12 @@ import (
"path"
"runtime/debug"
"strconv"
"strings"
"sync"
"time"

"github.com/grafana/pyroscope-go/upstream"
)

var errCloudTokenRequired = errors.New("please provide an authentication token." +
" You can find it here: https://pyroscope.io/cloud")

const (
authTokenDeprecationWarning = "Authtoken is specified, but deprecated and ignored. " +
"Please switch to BasicAuthUser and BasicAuthPassword. " +
"If you need to use Bearer token authentication for a custom setup, " +
"you can use the HTTPHeaders option to set the Authorization header manually."
cloudHostnameSuffix = "pyroscope.cloud"
)

type Remote struct {
mu sync.Mutex
cfg Config
Expand All @@ -49,9 +36,6 @@ type HTTPClient interface {
}

type Config struct {
// Deprecated: AuthToken will be removed in future releases.
// Use BasicAuthUser and BasicAuthPassword instead.
AuthToken string
BasicAuthUser string // http basic auth user
BasicAuthPassword string // http basic auth password
TenantID string
Expand Down Expand Up @@ -101,10 +85,7 @@ func NewRemote(cfg Config) (*Remote, error) {
return nil, err
}

// authorize the token first
if cfg.AuthToken == "" && isOGPyroscopeCloud(u) {
return nil, errCloudTokenRequired
}
_ = u

return r, nil
}
Expand Down Expand Up @@ -201,14 +182,8 @@ func (r *Remote) uploadProfile(j *upstream.UploadJob) error {
request.Header.Set("Content-Type", contentType)
// request.Header.Set("Content-Type", "binary/octet-stream+"+string(j.Format))

switch {
case r.cfg.AuthToken != "" && isOGPyroscopeCloud(u):
request.Header.Set("Authorization", "Bearer "+r.cfg.AuthToken)
case r.cfg.BasicAuthUser != "" && r.cfg.BasicAuthPassword != "":
if r.cfg.BasicAuthUser != "" && r.cfg.BasicAuthPassword != "" {
request.SetBasicAuth(r.cfg.BasicAuthUser, r.cfg.BasicAuthPassword)
case r.cfg.AuthToken != "":
request.Header.Set("Authorization", "Bearer "+r.cfg.AuthToken)
r.logger.Infof(authTokenDeprecationWarning)
}
if r.cfg.TenantID != "" {
request.Header.Set("X-Scope-OrgID", r.cfg.TenantID)
Expand Down Expand Up @@ -255,10 +230,6 @@ func (r *Remote) handleJobs() {
}
}

func isOGPyroscopeCloud(u *url.URL) bool {
return strings.HasSuffix(u.Host, cloudHostnameSuffix)
}

// do safe upload
func (r *Remote) safeUpload(job *upstream.UploadJob) {
defer func() {
Expand Down
32 changes: 2 additions & 30 deletions upstream/remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/grafana/pyroscope-go/internal/testutil"
"github.com/grafana/pyroscope-go/upstream"
Expand All @@ -24,35 +22,15 @@ func TestUploadProfile(t *testing.T) {
cfg Config
serverAddress string
expectedAuthHeader string
expectWarning bool
}{
{
name: "OG Pyroscope Cloud with AuthToken",
cfg: Config{
AuthToken: "test-token",
Address: "https://example.pyroscope.cloud",
},
expectedAuthHeader: "Bearer test-token",
expectWarning: false,
},
{
name: "Non-OG Server with BasicAuth",
name: "Server with BasicAuth",
cfg: Config{
BasicAuthUser: "user",
BasicAuthPassword: "pass",
Address: "https://example.com",
},
expectedAuthHeader: "Basic dXNlcjpwYXNz", // Base64 encoded "user:pass"
expectWarning: false,
},
{
name: "Non-OG Server with AuthToken (Deprecated)",
cfg: Config{
AuthToken: "deprecated-token",
Address: "https://example.com",
},
expectedAuthHeader: "Bearer deprecated-token",
expectWarning: true,
},
}

Expand Down Expand Up @@ -82,12 +60,6 @@ func TestUploadProfile(t *testing.T) {
})
require.NoError(t, err)

if tt.expectWarning {
assert.Contains(t, logger.Lines(), authTokenDeprecationWarning)
} else {
assert.NotContains(t, logger.Lines(), authTokenDeprecationWarning)
}

mockClient.AssertCalled(t, "Do", mock.MatchedBy(func(req *http.Request) bool {
return req.Header.Get("Authorization") == tt.expectedAuthHeader
}))
Expand Down
Loading