Skip to content

Commit

Permalink
chore(phlare/pyroscope): rename phlare to pyroscope (grafana#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed May 31, 2023
1 parent cf58d9e commit 6675ff5
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 93 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Main (unreleased)
- Upgrade the embedded windows_exporter to commit 79781c6. (@jkroepke)

- Prometheus exporters in Flow mode now set the `instance` label to a value similar to the one they used to have in Static mode (<hostname> by default, customized by some integrations). (@jcreixell)

- `phlare.scrape` and `phlare.write` have been renamed to `pyroscope.scrape` and `pyroscope.scrape`. (@korniltsev)

### Features

Expand Down
4 changes: 2 additions & 2 deletions component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ import (
_ "github.com/grafana/agent/component/otelcol/receiver/otlp" // Import otelcol.receiver.otlp
_ "github.com/grafana/agent/component/otelcol/receiver/prometheus" // Import otelcol.receiver.prometheus
_ "github.com/grafana/agent/component/otelcol/receiver/zipkin" // Import otelcol.receiver.zipkin
_ "github.com/grafana/agent/component/phlare/scrape" // Import phlare.scrape
_ "github.com/grafana/agent/component/phlare/write" // Import phlare.write
_ "github.com/grafana/agent/component/prometheus/exporter/apache" // Import prometheus.exporter.apache
_ "github.com/grafana/agent/component/prometheus/exporter/blackbox" // Import prometheus.exporter.blackbox
_ "github.com/grafana/agent/component/prometheus/exporter/consul" // Import prometheus.exporter.consul
Expand All @@ -82,6 +80,8 @@ import (
_ "github.com/grafana/agent/component/prometheus/relabel" // Import prometheus.relabel
_ "github.com/grafana/agent/component/prometheus/remotewrite" // Import prometheus.remote_write
_ "github.com/grafana/agent/component/prometheus/scrape" // Import prometheus.scrape
_ "github.com/grafana/agent/component/pyroscope/scrape" // Import pyroscope.scrape
_ "github.com/grafana/agent/component/pyroscope/write" // Import pyroscope.write
_ "github.com/grafana/agent/component/remote/http" // Import remote.http
_ "github.com/grafana/agent/component/remote/s3" // Import remote.s3
_ "github.com/grafana/agent/component/remote/vault" // Import remote.vault
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package phlare
package pyroscope

import (
"context"
Expand Down Expand Up @@ -40,8 +40,8 @@ type Fanout struct {
// NewFanout creates a fanout appendable.
func NewFanout(children []Appendable, componentID string, register prometheus.Registerer) *Fanout {
wl := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "phlare_fanout_latency",
Help: "Write latency for sending to phlare profiles",
Name: "pyroscope_fanout_latency",
Help: "Write latency for sending to pyroscope profiles",
})
_ = register.Register(wl)
return &Fanout{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package phlare
package pyroscope

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/agent/component/pyroscope"
"github.com/prometheus/prometheus/discovery/targetgroup"

"github.com/grafana/agent/component/phlare"
)

var reloadInterval = 5 * time.Second
Expand All @@ -18,7 +17,7 @@ type Manager struct {
logger log.Logger

graceShut chan struct{}
appendable phlare.Appendable
appendable pyroscope.Appendable

mtxScrape sync.Mutex // Guards the fields below.
config Arguments
Expand All @@ -28,7 +27,7 @@ type Manager struct {
triggerReload chan struct{}
}

func NewManager(appendable phlare.Appendable, logger log.Logger) *Manager {
func NewManager(appendable pyroscope.Appendable, logger log.Logger) *Manager {
if logger == nil {
logger = log.NewNopLogger()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/grafana/agent/component/phlare"
"github.com/grafana/agent/component/pyroscope"
"github.com/grafana/agent/pkg/util"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery/targetgroup"
Expand All @@ -16,7 +16,7 @@ import (
func TestManager(t *testing.T) {
reloadInterval = time.Millisecond

m := NewManager(phlare.AppendableFunc(func(ctx context.Context, labels labels.Labels, samples []*phlare.RawSample) error {
m := NewManager(pyroscope.AppendableFunc(func(ctx context.Context, labels labels.Labels, samples []*pyroscope.RawSample) error {
return nil
}), util.TestLogger(t))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"time"

"github.com/go-kit/log/level"
"github.com/grafana/agent/component/pyroscope"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery/targetgroup"

"github.com/grafana/agent/component"
component_config "github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/phlare"
"github.com/grafana/agent/component/prometheus/scrape"
)

Expand All @@ -29,7 +29,7 @@ const (

func init() {
component.Register(component.Registration{
Name: "phlare.scrape",
Name: "pyroscope.scrape",
Args: Arguments{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
Expand All @@ -41,8 +41,8 @@ func init() {
// Arguments holds values which are used to configure the pprof.scrape
// component.
type Arguments struct {
Targets []discovery.Target `river:"targets,attr"`
ForwardTo []phlare.Appendable `river:"forward_to,attr"`
Targets []discovery.Target `river:"targets,attr"`
ForwardTo []pyroscope.Appendable `river:"forward_to,attr"`

// The job name to override the job label with.
JobName string `river:"job_name,attr,optional"`
Expand Down Expand Up @@ -218,14 +218,14 @@ type Component struct {
mut sync.RWMutex
args Arguments
scraper *Manager
appendable *phlare.Fanout
appendable *pyroscope.Fanout
}

var _ component.Component = (*Component)(nil)

// New creates a new pprof.scrape component.
func New(o component.Options, args Arguments) (*Component, error) {
flowAppendable := phlare.NewFanout(args.ForwardTo, o.ID, o.Registerer)
flowAppendable := pyroscope.NewFanout(args.ForwardTo, o.ID, o.Registerer)
scraper := NewManager(flowAppendable, o.Logger)
c := &Component{
opts: o,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/agent/component/pyroscope"
commonconfig "github.com/prometheus/common/config"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/util/pool"
"golang.org/x/net/context/ctxhttp"

"github.com/grafana/agent/component/phlare"
"github.com/grafana/agent/pkg/build"
)

Expand All @@ -31,14 +31,14 @@ type scrapePool struct {

logger log.Logger
scrapeClient *http.Client
appendable phlare.Appendable
appendable pyroscope.Appendable

mtx sync.RWMutex
activeTargets map[uint64]*scrapeLoop
droppedTargets []*Target
}

func newScrapePool(cfg Arguments, appendable phlare.Appendable, logger log.Logger) (*scrapePool, error) {
func newScrapePool(cfg Arguments, appendable pyroscope.Appendable, logger log.Logger) (*scrapePool, error) {
scrapeClient, err := commonconfig.NewClientFromConfig(*cfg.HTTPClientConfig.Convert(), cfg.JobName)
if err != nil {
return nil, err
Expand Down Expand Up @@ -164,7 +164,7 @@ type scrapeLoop struct {
lastScrapeSize int

scrapeClient *http.Client
appendable phlare.Appendable
appendable pyroscope.Appendable

req *http.Request
logger log.Logger
Expand All @@ -174,7 +174,7 @@ type scrapeLoop struct {
wg sync.WaitGroup
}

func newScrapeLoop(t *Target, scrapeClient *http.Client, appendable phlare.Appendable, interval, timeout time.Duration, logger log.Logger) *scrapeLoop {
func newScrapeLoop(t *Target, scrapeClient *http.Client, appendable pyroscope.Appendable, interval, timeout time.Duration, logger log.Logger) *scrapeLoop {
return &scrapeLoop{
Target: t,
logger: logger,
Expand Down Expand Up @@ -238,7 +238,7 @@ func (t *scrapeLoop) scrape() {
if len(b) > 0 {
t.lastScrapeSize = len(b)
}
if err := t.appendable.Appender().Append(context.Background(), t.labels, []*phlare.RawSample{{RawProfile: b}}); err != nil {
if err := t.appendable.Appender().Append(context.Background(), t.labels, []*pyroscope.RawSample{{RawProfile: b}}); err != nil {
level.Error(t.logger).Log("msg", "push failed", "labels", t.Labels().String(), "err", err)
t.updateTargetStatus(start, err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/phlare"
"github.com/grafana/agent/component/pyroscope"
"github.com/grafana/agent/pkg/util"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery/targetgroup"
Expand All @@ -32,8 +32,8 @@ func TestScrapePool(t *testing.T) {
args.ProfilingConfig.Goroutine.Enabled = false
args.ProfilingConfig.Memory.Enabled = false

p, err := newScrapePool(args, phlare.AppendableFunc(
func(ctx context.Context, labels labels.Labels, samples []*phlare.RawSample) error {
p, err := newScrapePool(args, pyroscope.AppendableFunc(
func(ctx context.Context, labels labels.Labels, samples []*pyroscope.RawSample) error {
return nil
}),
util.TestLogger(t))
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestScrapeLoop(t *testing.T) {
"seconds": []string{"1"},
}),
server.Client(),
phlare.AppendableFunc(func(_ context.Context, labels labels.Labels, samples []*phlare.RawSample) error {
pyroscope.AppendableFunc(func(_ context.Context, labels labels.Labels, samples []*pyroscope.RawSample) error {
appendTotal.Inc()
require.Equal(t, []byte("ok"), samples[0].RawProfile)
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/grafana/agent/component"
"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/phlare"
"github.com/grafana/agent/component/prometheus/scrape"
"github.com/grafana/agent/component/pyroscope"
"github.com/grafana/agent/pkg/cluster"
"github.com/grafana/agent/pkg/river"
"github.com/grafana/agent/pkg/util"
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestComponent(t *testing.T) {
require.Empty(t, c.appendable.Children())
require.Empty(t, c.DebugInfo().(scrape.ScraperStatus).TargetStatus)

arg.ForwardTo = []phlare.Appendable{phlare.NoopAppendable}
arg.ForwardTo = []pyroscope.Appendable{pyroscope.NoopAppendable}
arg.Targets = []discovery.Target{
{
model.AddressLabel: "foo",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ type metrics struct {
func newMetrics(reg prometheus.Registerer) *metrics {
m := &metrics{
sentBytes: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "phlare_write_sent_bytes_total",
Help: "Total number of compressed bytes sent to Phlare.",
Name: "pyroscope_write_sent_bytes_total",
Help: "Total number of compressed bytes sent to Pyroscope.",
}, []string{"endpoint"}),
droppedBytes: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "phlare_write_dropped_bytes_total",
Help: "Total number of compressed bytes dropped by Phlare.",
Name: "pyroscope_write_dropped_bytes_total",
Help: "Total number of compressed bytes dropped by Pyroscope.",
}, []string{"endpoint"}),
sentProfiles: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "phlare_write_sent_profiles_total",
Help: "Total number of profiles sent to Phlare.",
Name: "pyroscope_write_sent_profiles_total",
Help: "Total number of profiles sent to Pyroscope.",
}, []string{"endpoint"}),
droppedProfiles: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "phlare_write_dropped_profiles_total",
Help: "Total number of profiles dropped by Phlare.",
Name: "pyroscope_write_dropped_profiles_total",
Help: "Total number of profiles dropped by Pyroscope.",
}, []string{"endpoint"}),
retries: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "phlare_write_retries_total",
Help: "Total number of retries to Phlare.",
Name: "pyroscope_write_retries_total",
Help: "Total number of retries to Pyroscope.",
}, []string{"endpoint"}),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/bufbuild/connect-go"
"github.com/go-kit/log/level"
"github.com/grafana/agent/component/pyroscope"
"github.com/oklog/run"
commonconfig "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
Expand All @@ -17,7 +18,6 @@ import (

"github.com/grafana/agent/component"
"github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/component/phlare"
"github.com/grafana/agent/pkg/build"
"github.com/grafana/dskit/backoff"
pushv1 "github.com/grafana/phlare/api/gen/proto/go/push/v1"
Expand All @@ -35,7 +35,7 @@ var (

func init() {
component.Register(component.Registration{
Name: "phlare.write",
Name: "pyroscope.write",
Args: Arguments{},
Exports: Exports{},
Build: func(o component.Options, c component.Arguments) (component.Component, error) {
Expand All @@ -44,7 +44,7 @@ func init() {
})
}

// Arguments represents the input state of the phlare.write
// Arguments represents the input state of the pyroscope.write
// component.
type Arguments struct {
ExternalLabels map[string]string `river:"external_labels,attr,optional"`
Expand All @@ -60,7 +60,7 @@ func (rc *Arguments) UnmarshalRiver(f func(interface{}) error) error {
}

// EndpointOptions describes an individual location for where profiles
// should be delivered to using the Phlare push API.
// should be delivered to using the Pyroscope push API.
type EndpointOptions struct {
Name string `river:"name,attr,optional"`
URL string `river:"url,attr"`
Expand Down Expand Up @@ -102,19 +102,19 @@ func (r *EndpointOptions) UnmarshalRiver(f func(v interface{}) error) error {
return nil
}

// Component is the phlare.write component.
// Component is the pyroscope.write component.
type Component struct {
opts component.Options
cfg Arguments
metrics *metrics
}

// Exports are the set of fields exposed by the phlare.write component.
// Exports are the set of fields exposed by the pyroscope.write component.
type Exports struct {
Receiver phlare.Appendable `river:"receiver,attr"`
Receiver pyroscope.Appendable `river:"receiver,attr"`
}

// NewComponent creates a new phlare.write component.
// NewComponent creates a new pyroscope.write component.
func NewComponent(o component.Options, c Arguments) (*Component, error) {
metrics := newMetrics(o.Registerer)
receiver, err := NewFanOut(o, c, metrics)
Expand Down Expand Up @@ -142,7 +142,7 @@ func (c *Component) Run(ctx context.Context) error {
// Update implements Component.
func (c *Component) Update(newConfig component.Arguments) error {
c.cfg = newConfig.(Arguments)
level.Debug(c.opts.Logger).Log("msg", "updating phlare.write config", "old", c.cfg, "new", newConfig)
level.Debug(c.opts.Logger).Log("msg", "updating pyroscope.write config", "old", c.cfg, "new", newConfig)
receiver, err := NewFanOut(c.opts, newConfig.(Arguments), c.metrics)
if err != nil {
return err
Expand Down Expand Up @@ -269,13 +269,13 @@ func requestSize(req *connect.Request[pushv1.PushRequest]) (int64, int64) {
return size, profiles
}

// Append implements the phlare.Appendable interface.
func (f *fanOutClient) Appender() phlare.Appender {
// Append implements the pyroscope.Appendable interface.
func (f *fanOutClient) Appender() pyroscope.Appender {
return f
}

// Append implements the Appender interface.
func (f *fanOutClient) Append(ctx context.Context, lbs labels.Labels, samples []*phlare.RawSample) error {
func (f *fanOutClient) Append(ctx context.Context, lbs labels.Labels, samples []*pyroscope.RawSample) error {
// todo(ctovena): we should probably pool the label pair arrays and label builder to avoid allocs.
var (
protoLabels = make([]*typesv1.LabelPair, 0, len(lbs)+len(f.config.ExternalLabels))
Expand Down
Loading

0 comments on commit 6675ff5

Please sign in to comment.