Skip to content

Commit f7aab06

Browse files
authored
Pyroscope: Remove support for old pyroscope (grafana#74683)
1 parent 8b4d167 commit f7aab06

File tree

17 files changed

+78
-601
lines changed

17 files changed

+78
-601
lines changed

.github/CODEOWNERS

-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@
194194
/devenv/docker/blocks/mysql_opendata/ @grafana/oss-big-tent
195195
/devenv/docker/blocks/mysql_tests/ @grafana/oss-big-tent
196196
/devenv/docker/blocks/opentsdb/ @grafana/observability-metrics
197-
/devenv/docker/blocks/phlare/ @grafana/observability-traces-and-profiling
198197
/devenv/docker/blocks/postgres/ @grafana/oss-big-tent
199198
/devenv/docker/blocks/postgres_tests/ @grafana/oss-big-tent
200199
/devenv/docker/blocks/prometheus/ @grafana/observability-metrics

devenv/docker/blocks/phlare/docker-compose.yaml

-8
This file was deleted.

devenv/docker/blocks/phlare/phlare.yaml

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
pyroscope:
2-
image: "pyroscope/pyroscope:latest"
3-
command:
4-
- "server"
2+
image: "grafana/pyroscope:latest"
53
ports:
64
- "4040:4040"

docs/sources/datasources/grafana-pyroscope.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ weight: 1150
2121

2222
# Grafana Pyroscope data source
2323

24-
Formerly Phlare data source, it supports both Phlare and Pyroscope, a horizontally scalable, highly-available, multi-tenant, OSS, continuous profiling aggregation systems. Add it as a data source, and you are ready to query your profiles in [Explore][explore].
24+
Formerly Phlare data source, now Grafana Pyroscope, a horizontally scalable, highly-available, multi-tenant, OSS, continuous profiling aggregation system. Add it as a data source, and you are ready to query your profiles in [Explore][explore].
2525

2626
## Configure the Grafana Pyroscope data source
2727

@@ -45,7 +45,6 @@ To configure basic settings for the data source, complete the following steps:
4545
| `User` | User name for basic authentication. |
4646
| `Password` | Password for basic authentication. |
4747
| `Minimal step` | Used for queries returning timeseries data. Phlare backend, similar to Prometheus, scrapes profiles at certain intervals. To prevent querying at smaller interval use Minimal step same or higher than your Phlare scrape interval. For Pyroscope backend this prevents returning too many data points to the front end. |
48-
| `Backend type` | Select a backend type between Phlare and Pyroscope. It is autodetected if not set but once set you have to change it manually. |
4948

5049
## Querying
5150

@@ -55,13 +54,13 @@ To configure basic settings for the data source, complete the following steps:
5554

5655
Query editor gives you access to a profile type selector, a label selector, and collapsible options.
5756

58-
![Profile or App selector](/static/img/docs/phlare/select-profile.png 'Profile or App selector')
57+
![Profile selector](/static/img/docs/phlare/select-profile.png 'Profile selector')
5958

60-
Select a profile type or app from the drop-down menu. While the label selector can be left empty to query all profiles without filtering by labels, the profile type or app must be selected for the query to be valid. Grafana does not show any data if the profile type or app isn’t selected when a query is run.
59+
Select a profile type from the drop-down menu. While the label selector can be left empty to query all profiles without filtering by labels, the profile type or app must be selected for the query to be valid. Grafana does not show any data if the profile type or app isn’t selected when a query is run.
6160

6261
![Labels selector](/static/img/docs/phlare/labels-selector.png 'Labels selector')
6362

64-
Use the labels selector input to filter by labels. Phlare and Pyroscope uses similar syntax to Prometheus to filter labels. Refer to [Phlare documentation](https://grafana.com/docs/phlare/latest/) for available operators and syntax.
63+
Use the labels selector input to filter by labels. Pyroscope uses similar syntax to Prometheus to filter labels. Refer to [Pyroscope documentation](https://grafana.com/docs/pyroscope/latest/) for available operators and syntax.
6564

6665
![Options section](/static/img/docs/phlare/options-section.png 'Options section')
6766

@@ -77,7 +76,7 @@ Profiles can be visualized in a flame graph. See the [Flame Graph documentation]
7776

7877
![Flame graph](/static/img/docs/phlare/flame-graph.png 'Flame graph')
7978

80-
Phlare and Pyroscope returns profiles aggregated over a selected time range, and the absolute values in the flame graph grow as the time range gets bigger while keeping the relative values meaningful. You can zoom in on the time range to get a higher granularity profile up to the point of a single scrape interval.
79+
Pyroscope returns profiles aggregated over a selected time range, and the absolute values in the flame graph grow as the time range gets bigger while keeping the relative values meaningful. You can zoom in on the time range to get a higher granularity profile up to the point of a single scrape interval.
8180

8281
### Metrics query results
8382

@@ -98,11 +97,10 @@ apiVersion: 1
9897

9998
datasources:
10099
- name: Grafana Pyroscope
101-
type: phlare
102-
url: http://localhost:4100
100+
type: grafana-pyroscope-datasource
101+
url: http://localhost:4040
103102
jsonData:
104103
minStep: '15s'
105-
backendType: 'pyroscope'
106104
```
107105
108106
{{% docs/reference %}}

pkg/tests/api/plugins/data/expectedListResp.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@
671671
"name": "Grafana Labs",
672672
"url": "https://www.grafana.com"
673673
},
674-
"description": "Supports Phlare and Pyroscope backends, horizontally-scalable, highly-available, multi-tenant continuous profiling aggregation systems.",
674+
"description": "Data source for Grafana Pyroscope, horizontally-scalable, highly-available, multi-tenant continuous profiling aggregation system.",
675675
"links": [
676676
{
677677
"name": "GitHub Project",
@@ -1896,4 +1896,4 @@
18961896
"signatureOrg": "",
18971897
"angularDetected": false
18981898
}
1899-
]
1899+
]

pkg/tsdb/grafana-pyroscope-datasource/client.go

-66
This file was deleted.

pkg/tsdb/grafana-pyroscope-datasource/instance.go

+11-109
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import (
66
"fmt"
77
"net/http"
88
"net/url"
9-
"strconv"
109
"time"
1110

1211
"github.com/grafana/grafana-plugin-sdk-go/backend"
1312
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
1413
"github.com/grafana/grafana-plugin-sdk-go/data"
1514
"github.com/grafana/grafana/pkg/infra/httpclient"
1615
"github.com/grafana/grafana/pkg/services/accesscontrol"
17-
"github.com/grafana/grafana/pkg/services/contexthandler"
18-
"github.com/grafana/grafana/pkg/services/datasources"
1916
)
2017

2118
var (
@@ -25,6 +22,14 @@ var (
2522
_ backend.StreamHandler = (*PhlareDatasource)(nil)
2623
)
2724

25+
type ProfilingClient interface {
26+
ProfileTypes(context.Context) ([]*ProfileType, error)
27+
LabelNames(ctx context.Context) ([]string, error)
28+
LabelValues(ctx context.Context, label string) ([]string, error)
29+
GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, step float64) (*SeriesResponse, error)
30+
GetProfile(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, maxNodes *int64) (*ProfileResponse, error)
31+
}
32+
2833
// PhlareDatasource is a datasource for querying application performance profiles.
2934
type PhlareDatasource struct {
3035
httpClient *http.Client
@@ -33,10 +38,6 @@ type PhlareDatasource struct {
3338
ac accesscontrol.AccessControl
3439
}
3540

36-
type JsonData struct {
37-
BackendType string `json:"backendType"`
38-
}
39-
4041
// NewPhlareDatasource creates a new datasource instance.
4142
func NewPhlareDatasource(httpClientProvider httpclient.Provider, settings backend.DataSourceInstanceSettings, ac accesscontrol.AccessControl) (instancemgmt.Instance, error) {
4243
opt, err := settings.HTTPClientOptions()
@@ -48,15 +49,9 @@ func NewPhlareDatasource(httpClientProvider httpclient.Provider, settings backen
4849
return nil, err
4950
}
5051

51-
var jsonData *JsonData
52-
err = json.Unmarshal(settings.JSONData, &jsonData)
53-
if err != nil {
54-
return nil, err
55-
}
56-
5752
return &PhlareDatasource{
5853
httpClient: httpClient,
59-
client: getClient(jsonData.BackendType, httpClient, settings.URL),
54+
client: NewPhlareClient(httpClient, settings.URL),
6055
settings: settings,
6156
ac: ac,
6257
}, nil
@@ -73,9 +68,6 @@ func (d *PhlareDatasource) CallResource(ctx context.Context, req *backend.CallRe
7368
if req.Path == "labelValues" {
7469
return d.labelValues(ctx, req, sender)
7570
}
76-
if req.Path == "backendType" {
77-
return d.backendType(ctx, req, sender)
78-
}
7971
return sender.Send(&backend.CallResourceResponse{
8072
Status: 404,
8173
})
@@ -98,21 +90,7 @@ func (d *PhlareDatasource) profileTypes(ctx context.Context, req *backend.CallRe
9890
}
9991

10092
func (d *PhlareDatasource) labelNames(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
101-
u, err := url.Parse(req.URL)
102-
if err != nil {
103-
return err
104-
}
105-
query := u.Query()
106-
start, err := strconv.ParseInt(query["start"][0], 10, 64)
107-
if err != nil {
108-
return err
109-
}
110-
end, err := strconv.ParseInt(query["end"][0], 10, 64)
111-
if err != nil {
112-
return err
113-
}
114-
115-
res, err := d.client.LabelNames(ctx, query["query"][0], start, end)
93+
res, err := d.client.LabelNames(ctx)
11694
if err != nil {
11795
return fmt.Errorf("error calling LabelNames: %v", err)
11896
}
@@ -140,16 +118,8 @@ func (d *PhlareDatasource) labelValues(ctx context.Context, req *backend.CallRes
140118
return err
141119
}
142120
query := u.Query()
143-
start, err := strconv.ParseInt(query["start"][0], 10, 64)
144-
if err != nil {
145-
return err
146-
}
147-
end, err := strconv.ParseInt(query["end"][0], 10, 64)
148-
if err != nil {
149-
return err
150-
}
151121

152-
res, err := d.client.LabelValues(ctx, query["query"][0], query["label"][0], start, end)
122+
res, err := d.client.LabelValues(ctx, query["label"][0])
153123
if err != nil {
154124
return fmt.Errorf("error calling LabelValues: %v", err)
155125
}
@@ -164,74 +134,6 @@ func (d *PhlareDatasource) labelValues(ctx context.Context, req *backend.CallRes
164134
return nil
165135
}
166136

167-
type BackendTypeRespBody struct {
168-
BackendType string `json:"backendType"` // "phlare" or "pyroscope"
169-
}
170-
171-
// backendType is a simplistic test to figure out if we are speaking to phlare or pyroscope backend
172-
func (d *PhlareDatasource) backendType(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
173-
// To prevent any user sending arbitrary URL for us to test with we allow this only for users who can edit the datasource
174-
// as config page is where this is meant to be used.
175-
ok, err := d.isUserAllowedToEditDatasource(ctx)
176-
if err != nil {
177-
return err
178-
}
179-
180-
if !ok {
181-
return sender.Send(&backend.CallResourceResponse{Headers: req.Headers, Status: 401})
182-
}
183-
184-
u, err := url.Parse(req.URL)
185-
if err != nil {
186-
return err
187-
}
188-
query := u.Query()
189-
body := &BackendTypeRespBody{BackendType: "unknown"}
190-
191-
// We take the url from the request query because the data source may not yet be saved in DB with the URL we want
192-
// to test with (like when filling in the confgi page for the first time)
193-
url := query["url"][0]
194-
195-
pyroClient := getClient("pyroscope", d.httpClient, url)
196-
_, err = pyroClient.ProfileTypes(ctx)
197-
198-
if err == nil {
199-
body.BackendType = "pyroscope"
200-
} else {
201-
phlareClient := getClient("phlare", d.httpClient, url)
202-
_, err := phlareClient.ProfileTypes(ctx)
203-
if err == nil {
204-
body.BackendType = "phlare"
205-
}
206-
}
207-
208-
data, err := json.Marshal(body)
209-
if err != nil {
210-
return err
211-
}
212-
213-
return sender.Send(&backend.CallResourceResponse{Body: data, Headers: req.Headers, Status: 200})
214-
}
215-
216-
func (d *PhlareDatasource) isUserAllowedToEditDatasource(ctx context.Context) (bool, error) {
217-
reqCtx := contexthandler.FromContext(ctx)
218-
uidScope := datasources.ScopeProvider.GetResourceScopeUID(accesscontrol.Parameter(":uid"))
219-
220-
if reqCtx == nil || reqCtx.SignedInUser == nil {
221-
return false, nil
222-
}
223-
224-
ok, err := d.ac.Evaluate(ctx, reqCtx.SignedInUser, accesscontrol.EvalPermission(datasources.ActionWrite, uidScope))
225-
if err != nil {
226-
return false, err
227-
}
228-
if !ok {
229-
return false, nil
230-
}
231-
232-
return true, nil
233-
}
234-
235137
// QueryData handles multiple queries and returns multiple responses.
236138
// req contains the queries []DataQuery (where each query contains RefID as a unique identifier).
237139
// The QueryDataResponse contains a map of RefID to the response for each query, and each response

0 commit comments

Comments
 (0)