Pyroscope: Remove "phlare" from variable, types, strings etc (#75140)

This commit is contained in:
Andrej Ocenas 2023-09-20 16:31:22 +02:00 committed by GitHub
parent d1296f7213
commit 15e54df9f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 143 additions and 148 deletions

View File

@ -149,7 +149,7 @@
},
{
"type":"label",
"name":"datasource/Phlare",
"name":"datasource/grafana-pyroscope",
"action":"addToProject",
"addToProject":{
"url":"https://github.com/orgs/grafana/projects/221"

View File

@ -13,9 +13,9 @@ import * as common from '@grafana/schema';
export const pluginVersion = "10.2.0-pre";
export type PhlareQueryType = ('metrics' | 'profile' | 'both');
export type PyroscopeQueryType = ('metrics' | 'profile' | 'both');
export const defaultPhlareQueryType: PhlareQueryType = 'both';
export const defaultPyroscopeQueryType: PyroscopeQueryType = 'both';
export interface GrafanaPyroscopeDataQuery extends common.DataQuery {
/**

View File

@ -95,9 +95,9 @@ func TestIntegrationPluginManager(t *testing.T) {
ms := mssql.ProvideService(cfg)
sv2 := searchV2.ProvideService(cfg, db.InitTestDB(t), nil, nil, tracer, features, nil, nil, nil)
graf := grafanads.ProvideService(sv2, nil)
phlare := pyroscope.ProvideService(hcp, acimpl.ProvideAccessControl(cfg))
pyroscope := pyroscope.ProvideService(hcp, acimpl.ProvideAccessControl(cfg))
parca := parca.ProvideService(hcp)
coreRegistry := coreplugin.ProvideCoreRegistry(am, cw, cm, es, grap, idb, lk, otsdb, pr, tmpo, td, pg, my, ms, graf, phlare, parca)
coreRegistry := coreplugin.ProvideCoreRegistry(am, cw, cm, es, grap, idb, lk, otsdb, pr, tmpo, td, pg, my, ms, graf, pyroscope, parca)
testCtx := CreateIntegrationTestCtx(t, cfg, coreRegistry)

View File

@ -1,4 +1,4 @@
package phlare
package pyroscope
import (
"context"
@ -16,10 +16,10 @@ import (
)
var (
_ backend.QueryDataHandler = (*PhlareDatasource)(nil)
_ backend.CallResourceHandler = (*PhlareDatasource)(nil)
_ backend.CheckHealthHandler = (*PhlareDatasource)(nil)
_ backend.StreamHandler = (*PhlareDatasource)(nil)
_ backend.QueryDataHandler = (*PyroscopeDatasource)(nil)
_ backend.CallResourceHandler = (*PyroscopeDatasource)(nil)
_ backend.CheckHealthHandler = (*PyroscopeDatasource)(nil)
_ backend.StreamHandler = (*PyroscopeDatasource)(nil)
)
type ProfilingClient interface {
@ -30,16 +30,16 @@ type ProfilingClient interface {
GetProfile(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, maxNodes *int64) (*ProfileResponse, error)
}
// PhlareDatasource is a datasource for querying application performance profiles.
type PhlareDatasource struct {
// PyroscopeDatasource is a datasource for querying application performance profiles.
type PyroscopeDatasource struct {
httpClient *http.Client
client ProfilingClient
settings backend.DataSourceInstanceSettings
ac accesscontrol.AccessControl
}
// NewPhlareDatasource creates a new datasource instance.
func NewPhlareDatasource(httpClientProvider httpclient.Provider, settings backend.DataSourceInstanceSettings, ac accesscontrol.AccessControl) (instancemgmt.Instance, error) {
// NewPyroscopeDatasource creates a new datasource instance.
func NewPyroscopeDatasource(httpClientProvider httpclient.Provider, settings backend.DataSourceInstanceSettings, ac accesscontrol.AccessControl) (instancemgmt.Instance, error) {
opt, err := settings.HTTPClientOptions()
if err != nil {
return nil, err
@ -49,15 +49,15 @@ func NewPhlareDatasource(httpClientProvider httpclient.Provider, settings backen
return nil, err
}
return &PhlareDatasource{
return &PyroscopeDatasource{
httpClient: httpClient,
client: NewPhlareClient(httpClient, settings.URL),
client: NewPyroscopeClient(httpClient, settings.URL),
settings: settings,
ac: ac,
}, nil
}
func (d *PhlareDatasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
func (d *PyroscopeDatasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
logger.Debug("CallResource", "Path", req.Path, "Method", req.Method, "Body", req.Body)
if req.Path == "profileTypes" {
return d.profileTypes(ctx, req, sender)
@ -73,7 +73,7 @@ func (d *PhlareDatasource) CallResource(ctx context.Context, req *backend.CallRe
})
}
func (d *PhlareDatasource) profileTypes(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
func (d *PyroscopeDatasource) profileTypes(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
types, err := d.client.ProfileTypes(ctx)
if err != nil {
return err
@ -89,7 +89,7 @@ func (d *PhlareDatasource) profileTypes(ctx context.Context, req *backend.CallRe
return nil
}
func (d *PhlareDatasource) labelNames(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
func (d *PyroscopeDatasource) labelNames(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
res, err := d.client.LabelNames(ctx)
if err != nil {
return fmt.Errorf("error calling LabelNames: %v", err)
@ -112,7 +112,7 @@ type LabelValuesPayload struct {
End int64
}
func (d *PhlareDatasource) labelValues(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
func (d *PyroscopeDatasource) labelValues(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
u, err := url.Parse(req.URL)
if err != nil {
return err
@ -138,7 +138,7 @@ func (d *PhlareDatasource) labelValues(ctx context.Context, req *backend.CallRes
// req contains the queries []DataQuery (where each query contains RefID as a unique identifier).
// The QueryDataResponse contains a map of RefID to the response for each query, and each response
// contains Frames ([]*Frame).
func (d *PhlareDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
func (d *PyroscopeDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
logger.Debug("QueryData called", "Queries", req.Queries)
// create response struct
@ -160,7 +160,7 @@ func (d *PhlareDatasource) QueryData(ctx context.Context, req *backend.QueryData
// The main use case for these health checks is the test button on the
// datasource configuration page which allows users to verify that
// a datasource is working as expected.
func (d *PhlareDatasource) CheckHealth(ctx context.Context, _ *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
func (d *PyroscopeDatasource) CheckHealth(ctx context.Context, _ *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
logger.Debug("CheckHealth called")
status := backend.HealthStatusOk
@ -179,7 +179,7 @@ func (d *PhlareDatasource) CheckHealth(ctx context.Context, _ *backend.CheckHeal
// SubscribeStream is called when a client wants to connect to a stream. This callback
// allows sending the first message.
func (d *PhlareDatasource) SubscribeStream(_ context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
func (d *PyroscopeDatasource) SubscribeStream(_ context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
logger.Debug("SubscribeStream called")
status := backend.SubscribeStreamStatusPermissionDenied
@ -194,7 +194,7 @@ func (d *PhlareDatasource) SubscribeStream(_ context.Context, req *backend.Subsc
// RunStream is called once for any open channel. Results are shared with everyone
// subscribed to the same channel.
func (d *PhlareDatasource) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
func (d *PyroscopeDatasource) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
logger.Debug("RunStream called")
// Create the same data frame as for query data.
@ -231,7 +231,7 @@ func (d *PhlareDatasource) RunStream(ctx context.Context, req *backend.RunStream
}
// PublishStream is called when a client sends a message to the stream.
func (d *PhlareDatasource) PublishStream(_ context.Context, _ *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
func (d *PyroscopeDatasource) PublishStream(_ context.Context, _ *backend.PublishStreamRequest) (*backend.PublishStreamResponse, error) {
logger.Debug("PublishStream called")
// Do not allow publishing at all.

View File

@ -1,4 +1,4 @@
package phlare
package pyroscope
import (
"context"
@ -10,7 +10,7 @@ import (
// This is where the tests for the datasource backend live.
func Test_QueryData(t *testing.T) {
ds := PhlareDatasource{}
ds := PyroscopeDatasource{}
resp, err := ds.QueryData(
context.Background(),
@ -30,7 +30,7 @@ func Test_QueryData(t *testing.T) {
}
func Test_CallResource(t *testing.T) {
ds := &PhlareDatasource{
ds := &PyroscopeDatasource{
client: &FakeClient{},
}

View File

@ -9,11 +9,11 @@
package dataquery
// Defines values for PhlareQueryType.
// Defines values for PyroscopeQueryType.
const (
PhlareQueryTypeBoth PhlareQueryType = "both"
PhlareQueryTypeMetrics PhlareQueryType = "metrics"
PhlareQueryTypeProfile PhlareQueryType = "profile"
PyroscopeQueryTypeBoth PyroscopeQueryType = "both"
PyroscopeQueryTypeMetrics PyroscopeQueryType = "metrics"
PyroscopeQueryTypeProfile PyroscopeQueryType = "profile"
)
// These are the common properties available to all queries in all datasources.
@ -81,5 +81,5 @@ type GrafanaPyroscopeDataQuery struct {
RefId string `json:"refId"`
}
// PhlareQueryType defines model for PhlareQueryType.
type PhlareQueryType string
// PyroscopeQueryType defines model for PyroscopeQueryType.
type PyroscopeQueryType string

View File

@ -1,4 +1,4 @@
package phlare
package pyroscope
import (
"context"
@ -54,17 +54,17 @@ type SeriesResponse struct {
Label string
}
type PhlareClient struct {
type PyroscopeClient struct {
connectClient querierv1connect.QuerierServiceClient
}
func NewPhlareClient(httpClient *http.Client, url string) *PhlareClient {
return &PhlareClient{
func NewPyroscopeClient(httpClient *http.Client, url string) *PyroscopeClient {
return &PyroscopeClient{
connectClient: querierv1connect.NewQuerierServiceClient(httpClient, url),
}
}
func (c *PhlareClient) ProfileTypes(ctx context.Context) ([]*ProfileType, error) {
func (c *PyroscopeClient) ProfileTypes(ctx context.Context) ([]*ProfileType, error) {
res, err := c.connectClient.ProfileTypes(ctx, connect.NewRequest(&querierv1.ProfileTypesRequest{}))
if err != nil {
return nil, err
@ -84,7 +84,7 @@ func (c *PhlareClient) ProfileTypes(ctx context.Context) ([]*ProfileType, error)
}
}
func (c *PhlareClient) GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, step float64) (*SeriesResponse, error) {
func (c *PyroscopeClient) GetSeries(ctx context.Context, profileTypeID string, labelSelector string, start int64, end int64, groupBy []string, step float64) (*SeriesResponse, error) {
req := connect.NewRequest(&querierv1.SelectSeriesRequest{
ProfileTypeID: profileTypeID,
LabelSelector: labelSelector,
@ -133,7 +133,7 @@ func (c *PhlareClient) GetSeries(ctx context.Context, profileTypeID string, labe
}, nil
}
func (c *PhlareClient) GetProfile(ctx context.Context, profileTypeID, labelSelector string, start, end int64, maxNodes *int64) (*ProfileResponse, error) {
func (c *PyroscopeClient) GetProfile(ctx context.Context, profileTypeID, labelSelector string, start, end int64, maxNodes *int64) (*ProfileResponse, error) {
req := &connect.Request[querierv1.SelectMergeStacktracesRequest]{
Msg: &querierv1.SelectMergeStacktracesRequest{
ProfileTypeID: profileTypeID,
@ -179,7 +179,7 @@ func getUnits(profileTypeID string) string {
return unit
}
func (c *PhlareClient) LabelNames(ctx context.Context) ([]string, error) {
func (c *PyroscopeClient) LabelNames(ctx context.Context) ([]string, error) {
resp, err := c.connectClient.LabelNames(ctx, connect.NewRequest(&querierv1.LabelNamesRequest{}))
if err != nil {
return nil, fmt.Errorf("error seding LabelNames request %v", err)
@ -195,7 +195,7 @@ func (c *PhlareClient) LabelNames(ctx context.Context) ([]string, error) {
return filtered, nil
}
func (c *PhlareClient) LabelValues(ctx context.Context, label string) ([]string, error) {
func (c *PyroscopeClient) LabelValues(ctx context.Context, label string) ([]string, error) {
resp, err := c.connectClient.LabelValues(ctx, connect.NewRequest(&querierv1.LabelValuesRequest{Name: label}))
if err != nil {
return nil, err

View File

@ -1,4 +1,4 @@
package phlare
package pyroscope
import (
"context"
@ -11,9 +11,9 @@ import (
"github.com/stretchr/testify/require"
)
func Test_PhlareClient(t *testing.T) {
connectClient := &FakePhlareConnectClient{}
client := &PhlareClient{
func Test_PyroscopeClient(t *testing.T) {
connectClient := &FakePyroscopeConnectClient{}
client := &PyroscopeClient{
connectClient: connectClient,
}
@ -53,27 +53,27 @@ func Test_PhlareClient(t *testing.T) {
})
}
type FakePhlareConnectClient struct {
type FakePyroscopeConnectClient struct {
Req any
}
func (f *FakePhlareConnectClient) ProfileTypes(ctx context.Context, c *connect.Request[querierv1.ProfileTypesRequest]) (*connect.Response[querierv1.ProfileTypesResponse], error) {
func (f *FakePyroscopeConnectClient) ProfileTypes(ctx context.Context, c *connect.Request[querierv1.ProfileTypesRequest]) (*connect.Response[querierv1.ProfileTypesResponse], error) {
panic("implement me")
}
func (f *FakePhlareConnectClient) LabelValues(ctx context.Context, c *connect.Request[querierv1.LabelValuesRequest]) (*connect.Response[querierv1.LabelValuesResponse], error) {
func (f *FakePyroscopeConnectClient) LabelValues(ctx context.Context, c *connect.Request[querierv1.LabelValuesRequest]) (*connect.Response[querierv1.LabelValuesResponse], error) {
panic("implement me")
}
func (f *FakePhlareConnectClient) LabelNames(context.Context, *connect.Request[querierv1.LabelNamesRequest]) (*connect.Response[querierv1.LabelNamesResponse], error) {
func (f *FakePyroscopeConnectClient) LabelNames(context.Context, *connect.Request[querierv1.LabelNamesRequest]) (*connect.Response[querierv1.LabelNamesResponse], error) {
panic("implement me")
}
func (f *FakePhlareConnectClient) Series(ctx context.Context, c *connect.Request[querierv1.SeriesRequest]) (*connect.Response[querierv1.SeriesResponse], error) {
func (f *FakePyroscopeConnectClient) Series(ctx context.Context, c *connect.Request[querierv1.SeriesRequest]) (*connect.Response[querierv1.SeriesResponse], error) {
panic("implement me")
}
func (f *FakePhlareConnectClient) SelectMergeStacktraces(ctx context.Context, c *connect.Request[querierv1.SelectMergeStacktracesRequest]) (*connect.Response[querierv1.SelectMergeStacktracesResponse], error) {
func (f *FakePyroscopeConnectClient) SelectMergeStacktraces(ctx context.Context, c *connect.Request[querierv1.SelectMergeStacktracesRequest]) (*connect.Response[querierv1.SelectMergeStacktracesResponse], error) {
f.Req = c
return &connect.Response[querierv1.SelectMergeStacktracesResponse]{
Msg: &querierv1.SelectMergeStacktracesResponse{
@ -91,7 +91,7 @@ func (f *FakePhlareConnectClient) SelectMergeStacktraces(ctx context.Context, c
}, nil
}
func (f *FakePhlareConnectClient) SelectSeries(ctx context.Context, req *connect.Request[querierv1.SelectSeriesRequest]) (*connect.Response[querierv1.SelectSeriesResponse], error) {
func (f *FakePyroscopeConnectClient) SelectSeries(ctx context.Context, req *connect.Request[querierv1.SelectSeriesRequest]) (*connect.Response[querierv1.SelectSeriesResponse], error) {
f.Req = req
return &connect.Response[querierv1.SelectSeriesResponse]{
Msg: &querierv1.SelectSeriesResponse{
@ -105,6 +105,6 @@ func (f *FakePhlareConnectClient) SelectSeries(ctx context.Context, req *connect
}, nil
}
func (f *FakePhlareConnectClient) SelectMergeProfile(ctx context.Context, c *connect.Request[querierv1.SelectMergeProfileRequest]) (*connect.Response[googlev1.Profile], error) {
func (f *FakePyroscopeConnectClient) SelectMergeProfile(ctx context.Context, c *connect.Request[querierv1.SelectMergeProfileRequest]) (*connect.Response[googlev1.Profile], error) {
panic("implement me")
}

View File

@ -1,4 +1,4 @@
package phlare
package pyroscope
import (
"context"
@ -27,13 +27,13 @@ type dsJsonModel struct {
}
const (
queryTypeProfile = string(dataquery.PhlareQueryTypeProfile)
queryTypeMetrics = string(dataquery.PhlareQueryTypeMetrics)
queryTypeBoth = string(dataquery.PhlareQueryTypeBoth)
queryTypeProfile = string(dataquery.PyroscopeQueryTypeProfile)
queryTypeMetrics = string(dataquery.PyroscopeQueryTypeMetrics)
queryTypeBoth = string(dataquery.PyroscopeQueryTypeBoth)
)
// query processes single Phlare query transforming the response to data.Frame packaged in DataResponse
func (d *PhlareDatasource) query(ctx context.Context, pCtx backend.PluginContext, query backend.DataQuery) backend.DataResponse {
// query processes single Pyroscope query transforming the response to data.Frame packaged in DataResponse
func (d *PyroscopeDatasource) query(ctx context.Context, pCtx backend.PluginContext, query backend.DataQuery) backend.DataResponse {
var qm queryModel
response := backend.DataResponse{}
@ -118,7 +118,7 @@ func (d *PhlareDatasource) query(ctx context.Context, pCtx backend.PluginContext
return response
}
// responseToDataFrames turns Phlare response to data.Frame. We encode the data into a nested set format where we have
// responseToDataFrames turns Pyroscope response to data.Frame. We encode the data into a nested set format where we have
// [level, value, label] columns and by ordering the items in a depth first traversal order we can recreate the whole
// tree back.
func responseToDataFrames(resp *ProfileResponse) *data.Frame {
@ -151,7 +151,7 @@ type ProfileTree struct {
}
// levelsToTree converts flamebearer format into a tree. This is needed to then convert it into nested set format
// dataframe. This should be temporary, and ideally we should get some sort of tree struct directly from Phlare API.
// dataframe. This should be temporary, and ideally we should get some sort of tree struct directly from Pyroscope API.
func levelsToTree(levels []*Level, names []string) *ProfileTree {
if len(levels) == 0 {
return nil

View File

@ -1,4 +1,4 @@
package phlare
package pyroscope
import (
"context"
@ -13,7 +13,7 @@ import (
// This is where the tests for the datasource backend live.
func Test_query(t *testing.T) {
client := &FakeClient{}
ds := &PhlareDatasource{
ds := &PyroscopeDatasource{
client: client,
}

View File

@ -1,4 +1,4 @@
package phlare
package pyroscope
import (
"context"
@ -11,7 +11,7 @@ import (
"github.com/grafana/grafana/pkg/services/accesscontrol"
)
// Make sure PhlareDatasource implements required interfaces. This is important to do
// Make sure PyroscopeDatasource implements required interfaces. This is important to do
// since otherwise we will only get a not implemented error response from plugin in
// runtime. In this example datasource instance implements backend.QueryDataHandler,
// backend.CheckHealthHandler, backend.StreamHandler interfaces. Plugin should not
@ -27,18 +27,18 @@ var (
_ backend.StreamHandler = (*Service)(nil)
)
var logger = log.New("tsdb.phlare")
var logger = log.New("tsdb.pyroscope")
type Service struct {
im instancemgmt.InstanceManager
}
func (s *Service) getInstance(ctx context.Context, pluginCtx backend.PluginContext) (*PhlareDatasource, error) {
func (s *Service) getInstance(ctx context.Context, pluginCtx backend.PluginContext) (*PyroscopeDatasource, error) {
i, err := s.im.Get(ctx, pluginCtx)
if err != nil {
return nil, err
}
in := i.(*PhlareDatasource)
in := i.(*PyroscopeDatasource)
return in, nil
}
@ -50,7 +50,7 @@ func ProvideService(httpClientProvider httpclient.Provider, ac accesscontrol.Acc
func newInstanceSettings(httpClientProvider httpclient.Provider, ac accesscontrol.AccessControl) datasource.InstanceFactoryFunc {
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
return NewPhlareDatasource(httpClientProvider, settings, ac)
return NewPyroscopeDatasource(httpClientProvider, settings, ac)
}
}

View File

@ -4,9 +4,9 @@ import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { DataSourceHttpSettings, EventsWithValidation, LegacyForms, regexValidation } from '@grafana/ui';
import { config } from 'app/core/config';
import { PhlareDataSourceOptions } from './types';
import { PyroscopeDataSourceOptions } from './types';
interface Props extends DataSourcePluginOptionsEditorProps<PhlareDataSourceOptions> {}
interface Props extends DataSourcePluginOptionsEditorProps<PyroscopeDataSourceOptions> {}
export const ConfigEditor = (props: Props) => {
const { options, onOptionsChange } = props;
@ -53,7 +53,7 @@ export const ConfigEditor = (props: Props) => {
}}
/>
}
tooltip="Minimal step used for metric query. Should be the same or higher as the scrape interval setting in the Phlare database."
tooltip="Minimal step used for metric query. Should be the same or higher as the scrape interval setting in the Pyroscope database."
/>
</div>
</div>

View File

@ -4,7 +4,7 @@ import { useAsync, useLatest } from 'react-use';
import { CodeEditor, Monaco, useStyles2, monacoTypes } from '@grafana/ui';
import { languageDefinition } from '../phlareql';
import { languageDefinition } from '../pyroscopeql';
import { CompletionProvider } from './autocomplete';
@ -53,7 +53,7 @@ export function LabelsEditor(props: Props) {
bottom: 5,
},
}}
onBeforeEditorMount={ensurePhlareQL}
onBeforeEditorMount={ensurePyroscopeQL}
onEditorDidMount={(editor, monaco) => {
setupAutocompleteFn(editor, monaco);
@ -125,12 +125,12 @@ function useAutocomplete(getLabelValues: (label: string) => Promise<string[]>, l
}
// we must only run the setup code once
let phlareqlSetupDone = false;
const langId = 'phlareql';
let pyroscopeqlSetupDone = false;
const langId = 'pyroscopeql';
function ensurePhlareQL(monaco: Monaco) {
if (phlareqlSetupDone === false) {
phlareqlSetupDone = true;
function ensurePyroscopeQL(monaco: Monaco) {
if (pyroscopeqlSetupDone === false) {
pyroscopeqlSetupDone = true;
const { aliases, extensions, mimetypes, def } = languageDefinition;
monaco.languages.register({ id: langId, aliases, extensions, mimetypes });
monaco.languages.setMonarchTokensProvider(langId, def.language);

View File

@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { Cascader, CascaderOption } from '@grafana/ui';
import { PhlareDataSource } from '../datasource';
import { PyroscopeDataSource } from '../datasource';
import { ProfileTypeMessage } from '../types';
type Props = {
@ -39,14 +39,9 @@ function useCascaderOptions(profileTypes?: ProfileTypeMessage[]): CascaderOption
// Classify profile types by name then sample type.
// The profileTypes are something like cpu:sample:nanoseconds:sample:count or app.something.something
for (let profileType of profileTypes) {
let parts: string[];
// Phlare uses : as delimiter while Pyro uses .
let parts: string[] = [];
if (profileType.id.indexOf(':') > -1) {
parts = profileType.id.split(':');
} else {
parts = profileType.id.split('.');
const last = parts.pop()!;
parts = [parts.join('.'), last];
}
const [name, type] = parts;
@ -74,7 +69,7 @@ function useCascaderOptions(profileTypes?: ProfileTypeMessage[]): CascaderOption
* the profileTypes before rendering the cascader.
* @param datasource
*/
export function useProfileTypes(datasource: PhlareDataSource) {
export function useProfileTypes(datasource: PyroscopeDataSource) {
const [profileTypes, setProfileTypes] = useState<ProfileTypeMessage[]>();
useEffect(() => {

View File

@ -4,7 +4,7 @@ import React from 'react';
import { CoreApp, PluginType } from '@grafana/data';
import { PhlareDataSource } from '../datasource';
import { PyroscopeDataSource } from '../datasource';
import { ProfileTypeMessage } from '../types';
import { Props, QueryEditor } from './QueryEditor';
@ -62,7 +62,7 @@ async function openOptions() {
}
function setupDs() {
const ds = new PhlareDataSource({
const ds = new PyroscopeDataSource({
name: 'test',
uid: 'test',
type: PluginType.datasource,

View File

@ -5,8 +5,8 @@ import { useAsync } from 'react-use';
import { CoreApp, QueryEditorProps, TimeRange } from '@grafana/data';
import { LoadingPlaceholder } from '@grafana/ui';
import { normalizeQuery, PhlareDataSource } from '../datasource';
import { PhlareDataSourceOptions, ProfileTypeMessage, Query } from '../types';
import { normalizeQuery, PyroscopeDataSource } from '../datasource';
import { PyroscopeDataSourceOptions, ProfileTypeMessage, Query } from '../types';
import { EditorRow } from './EditorRow';
import { EditorRows } from './EditorRows';
@ -14,7 +14,7 @@ import { LabelsEditor } from './LabelsEditor';
import { ProfileTypesCascader, useProfileTypes } from './ProfileTypesCascader';
import { QueryOptions } from './QueryOptions';
export type Props = QueryEditorProps<PhlareDataSource, Query, PhlareDataSourceOptions>;
export type Props = QueryEditorProps<PyroscopeDataSource, Query, PyroscopeDataSourceOptions>;
export function QueryEditor(props: Props) {
const { onChange, onRunQuery, datasource, query, range, app } = props;
@ -106,7 +106,7 @@ function defaultProfileType(profileTypes: ProfileTypeMessage[]): string {
function useLabels(
range: TimeRange | undefined,
datasource: PhlareDataSource,
datasource: PyroscopeDataSource,
query: Query,
onChange: (value: Query) => void
) {

View File

@ -4,7 +4,7 @@ import { monacoTypes, Monaco } from '@grafana/ui';
* Class that implements CompletionItemProvider interface and allows us to provide suggestion for the Monaco
* autocomplete system.
*
* At this moment we just pass it all the labels/values we get from Phlare backend later on we may do something a bit
* At this moment we just pass it all the labels/values we get from Pyroscope backend later on we may do something a bit
* smarter if there will be lots of labels.
*/
export class CompletionProvider implements monacoTypes.languages.CompletionItemProvider {
@ -153,7 +153,7 @@ const inLabelNameRegex = new RegExp(/[{,]\s*[a-zA-Z0-9_]*$/);
/**
* Figure out where is the cursor and what kind of suggestions are appropriate.
* As currently Phlare handles just a simple {foo="bar", baz="zyx"} kind of values we can do with simple regex to figure
* As currently Pyroscope handles just a simple {foo="bar", baz="zyx"} kind of values we can do with simple regex to figure
* out where we are with the cursor.
* @param text
* @param offset

View File

@ -5,8 +5,8 @@ import { DataSourceInstanceSettings } from '@grafana/data';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { VariableQueryEditor } from './VariableQueryEditor';
import { PhlareDataSource } from './datasource';
import { PhlareDataSourceOptions } from './types';
import { PyroscopeDataSource } from './datasource';
import { PyroscopeDataSourceOptions } from './types';
describe('VariableQueryEditor', () => {
it('renders correctly with type profileType', () => {
@ -69,7 +69,7 @@ describe('VariableQueryEditor', () => {
});
function getMockDatasource() {
const ds = new PhlareDataSource({} as DataSourceInstanceSettings<PhlareDataSourceOptions>, new TemplateSrv());
const ds = new PyroscopeDataSource({} as DataSourceInstanceSettings<PyroscopeDataSourceOptions>, new TemplateSrv());
ds.getResource = jest.fn();
(ds.getResource as jest.Mock).mockImplementation(async (type: string) => {
if (type === 'profileTypes') {

View File

@ -4,10 +4,10 @@ import { QueryEditorProps, SelectableValue } from '@grafana/data';
import { InlineField, InlineFieldRow, LoadingPlaceholder, Select } from '@grafana/ui';
import { ProfileTypesCascader, useProfileTypes } from './QueryEditor/ProfileTypesCascader';
import { PhlareDataSource } from './datasource';
import { PyroscopeDataSource } from './datasource';
import { Query, VariableQuery } from './types';
export function VariableQueryEditor(props: QueryEditorProps<PhlareDataSource, Query, {}, VariableQuery>) {
export function VariableQueryEditor(props: QueryEditorProps<PyroscopeDataSource, Query, {}, VariableQuery>) {
return (
<>
<InlineFieldRow>
@ -87,7 +87,7 @@ export function VariableQueryEditor(props: QueryEditorProps<PhlareDataSource, Qu
}
function LabelRow(props: {
datasource: PhlareDataSource;
datasource: PyroscopeDataSource;
value?: string;
profileTypeId?: string;
from: number;
@ -128,7 +128,7 @@ function LabelRow(props: {
}
function ProfileTypeRow(props: {
datasource: PhlareDataSource;
datasource: PyroscopeDataSource;
onChange: (val: string) => void;
initialValue?: string;
}) {

View File

@ -5,7 +5,7 @@ import { CustomVariableSupport, DataQueryRequest, DataQueryResponse, MetricFindV
import { getTimeSrv, TimeSrv } from '../../../features/dashboard/services/TimeSrv';
import { VariableQueryEditor } from './VariableQueryEditor';
import { PhlareDataSource } from './datasource';
import { PyroscopeDataSource } from './datasource';
import { ProfileTypeMessage, VariableQuery } from './types';
export interface DataAPI {
@ -14,7 +14,7 @@ export interface DataAPI {
getLabelValues(query: string, label: string, start: number, end: number): Promise<string[]>;
}
export class VariableSupport extends CustomVariableSupport<PhlareDataSource> {
export class VariableSupport extends CustomVariableSupport<PyroscopeDataSource> {
constructor(
private readonly dataAPI: DataAPI,
private readonly timeSrv: TimeSrv = getTimeSrv()

View File

@ -37,7 +37,7 @@ composableKinds: DataQuery: {
groupBy: [...string]
// Sets the maximum number of nodes in the flamegraph.
maxNodes?: int64
#PhlareQueryType: "metrics" | "profile" | *"both" @cuetsy(kind="type")
#PyroscopeQueryType: "metrics" | "profile" | *"both" @cuetsy(kind="type")
}
}]
lenses: []

View File

@ -10,9 +10,9 @@
import * as common from '@grafana/schema';
export type PhlareQueryType = ('metrics' | 'profile' | 'both');
export type PyroscopeQueryType = ('metrics' | 'profile' | 'both');
export const defaultPhlareQueryType: PhlareQueryType = 'both';
export const defaultPyroscopeQueryType: PyroscopeQueryType = 'both';
export interface GrafanaPyroscope extends common.DataQuery {
/**

View File

@ -1,14 +1,14 @@
import { AbstractLabelOperator, CoreApp, DataSourceInstanceSettings, PluginMetaInfo, PluginType } from '@grafana/data';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { defaultPhlareQueryType } from './dataquery.gen';
import { normalizeQuery, PhlareDataSource } from './datasource';
import { defaultPyroscopeQueryType } from './dataquery.gen';
import { normalizeQuery, PyroscopeDataSource } from './datasource';
import { Query } from './types';
describe('Phlare data source', () => {
let ds: PhlareDataSource;
describe('Pyroscope data source', () => {
let ds: PyroscopeDataSource;
beforeEach(() => {
ds = new PhlareDataSource(defaultSettings);
ds = new PyroscopeDataSource(defaultSettings);
});
describe('importing queries', () => {
@ -56,7 +56,7 @@ describe('Phlare data source', () => {
});
it('should not update labelSelector if there are no template variables', () => {
ds = new PhlareDataSource(defaultSettings, templateSrv);
ds = new PyroscopeDataSource(defaultSettings, templateSrv);
const query = ds.applyTemplateVariables(defaultQuery({ labelSelector: `no var`, profileTypeId: 'no var' }), {});
expect(query).toMatchObject({
labelSelector: `no var`,
@ -65,7 +65,7 @@ describe('Phlare data source', () => {
});
it('should update labelSelector if there are template variables', () => {
ds = new PhlareDataSource(defaultSettings, templateSrv);
ds = new PyroscopeDataSource(defaultSettings, templateSrv);
const query = ds.applyTemplateVariables(
defaultQuery({ labelSelector: `{$var="$var"}`, profileTypeId: '$var' }),
{}
@ -117,20 +117,20 @@ const defaultQuery = (query: Partial<Query>): Query => {
groupBy: [],
labelSelector: '',
profileTypeId: '',
queryType: defaultPhlareQueryType,
queryType: defaultPyroscopeQueryType,
...query,
};
};
const defaultSettings: DataSourceInstanceSettings = {
id: 0,
uid: 'phlare',
uid: 'pyroscope',
type: 'profiling',
name: 'phlare',
name: 'pyroscope',
access: 'proxy',
meta: {
id: 'phlare',
name: 'phlare',
id: 'pyroscope',
name: 'pyroscope',
type: PluginType.datasource,
info: {} as PluginMetaInfo,
module: '',

View File

@ -14,12 +14,12 @@ import { DataSourceWithBackend, getTemplateSrv, TemplateSrv } from '@grafana/run
import { extractLabelMatchers, toPromLikeExpr } from '../prometheus/language_utils';
import { VariableSupport } from './VariableSupport';
import { defaultGrafanaPyroscope, defaultPhlareQueryType } from './dataquery.gen';
import { PhlareDataSourceOptions, Query, ProfileTypeMessage } from './types';
import { defaultGrafanaPyroscope, defaultPyroscopeQueryType } from './dataquery.gen';
import { PyroscopeDataSourceOptions, Query, ProfileTypeMessage } from './types';
export class PhlareDataSource extends DataSourceWithBackend<Query, PhlareDataSourceOptions> {
export class PyroscopeDataSource extends DataSourceWithBackend<Query, PyroscopeDataSourceOptions> {
constructor(
instanceSettings: DataSourceInstanceSettings<PhlareDataSourceOptions>,
instanceSettings: DataSourceInstanceSettings<PyroscopeDataSourceOptions>,
private readonly templateSrv: TemplateSrv = getTemplateSrv()
) {
super(instanceSettings);
@ -92,11 +92,11 @@ export class PhlareDataSource extends DataSourceWithBackend<Query, PhlareDataSou
}
exportToAbstractQuery(query: Query): AbstractQuery {
const phlareQuery = query.labelSelector;
if (!phlareQuery || phlareQuery.length === 0) {
const pyroscopeQuery = query.labelSelector;
if (!pyroscopeQuery || pyroscopeQuery.length === 0) {
return { refId: query.refId, labelMatchers: [] };
}
const tokens = Prism.tokenize(phlareQuery, grammar);
const tokens = Prism.tokenize(pyroscopeQuery, grammar);
return {
refId: query.refId,
labelMatchers: extractLabelMatchers(tokens),
@ -110,7 +110,7 @@ export class PhlareDataSource extends DataSourceWithBackend<Query, PhlareDataSou
export const defaultQuery: Partial<Query> = {
...defaultGrafanaPyroscope,
queryType: defaultPhlareQueryType,
queryType: defaultPyroscopeQueryType,
};
export function normalizeQuery(query: Query, app?: CoreApp | string) {

View File

@ -2,9 +2,9 @@ import { DataSourcePlugin } from '@grafana/data';
import { ConfigEditor } from './ConfigEditor';
import { QueryEditor } from './QueryEditor/QueryEditor';
import { PhlareDataSource } from './datasource';
import { Query, PhlareDataSourceOptions } from './types';
import { PyroscopeDataSource } from './datasource';
import { Query, PyroscopeDataSourceOptions } from './types';
export const plugin = new DataSourcePlugin<PhlareDataSource, Query, PhlareDataSourceOptions>(PhlareDataSource)
export const plugin = new DataSourcePlugin<PyroscopeDataSource, Query, PyroscopeDataSourceOptions>(PyroscopeDataSource)
.setConfigEditor(ConfigEditor)
.setQueryEditor(QueryEditor);

View File

@ -1,12 +0,0 @@
import { language, languageConfiguration } from './phlareql';
export const languageDefinition = {
id: 'phlareql',
extensions: ['.phlareql'],
aliases: ['phlare', 'phlareql'],
mimetypes: [],
def: {
language,
languageConfiguration,
},
};

View File

@ -0,0 +1,12 @@
import { language, languageConfiguration } from './pyroscopeql';
export const languageDefinition = {
id: 'pyroscopeql',
extensions: ['.pyroscopeql'],
aliases: ['pyroscope', 'pyroscopeql'],
mimetypes: [],
def: {
language,
languageConfiguration,
},
};

View File

@ -20,7 +20,7 @@ export const languageConfiguration: languages.LanguageConfiguration = {
export const language: languages.IMonarchLanguage = {
ignoreCase: false,
defaultToken: '',
tokenPostfix: '.phlareql',
tokenPostfix: '.pyroscopeql',
keywords: [],
operators: [],

View File

@ -1,9 +1,9 @@
import { DataSourceJsonData } from '@grafana/data';
import { GrafanaPyroscope, PhlareQueryType } from './dataquery.gen';
import { GrafanaPyroscope, PyroscopeQueryType } from './dataquery.gen';
export interface Query extends GrafanaPyroscope {
queryType: PhlareQueryType;
queryType: PyroscopeQueryType;
}
export interface ProfileTypeMessage {
@ -14,7 +14,7 @@ export interface ProfileTypeMessage {
/**
* These are options configured for each DataSource instance.
*/
export interface PhlareDataSourceOptions extends DataSourceJsonData {
export interface PyroscopeDataSourceOptions extends DataSourceJsonData {
minStep?: string;
}