Parca: Use data query schema (#62840)

* Parca data query schema

* Remove groupBy
This commit is contained in:
Joey Tawadrous 2023-02-07 09:56:21 +00:00 committed by GitHub
parent f6d856f082
commit 121260e0dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 206 additions and 32 deletions

View File

@ -0,0 +1,42 @@
---
keywords:
- grafana
- schema
title: ParcaDataQuery kind
---
> Both documentation generation and kinds schemas are in active development and subject to change without prior notice.
## ParcaDataQuery
#### Maturity: experimental
#### Version: 0.0
It extends [DataQuery](#dataquery).
| Property | Type | Required | Description |
|-----------------|---------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `labelSelector` | string | **Yes** | Specifies the query label selectors. Default: `{}`. |
| `profileTypeId` | string | **Yes** | Specifies the type of profile to query. |
| `refId` | string | **Yes** | *(Inherited from [DataQuery](#dataquery))*<br/>A - Z |
| `datasource` | | No | *(Inherited from [DataQuery](#dataquery))*<br/>For mixed data sources the selected datasource is on the query level.<br/>For non mixed scenarios this is undefined.<br/>TODO find a better way to do this ^ that's friendly to schema<br/>TODO this shouldn't be unknown but DataSourceRef &#124; null |
| `hide` | boolean | No | *(Inherited from [DataQuery](#dataquery))*<br/>true if query is disabled (ie should not be returned to the dashboard) |
| `key` | string | No | *(Inherited from [DataQuery](#dataquery))*<br/>Unique, guid like, string used in explore mode |
| `queryType` | string | No | *(Inherited from [DataQuery](#dataquery))*<br/>Specify the query flavor<br/>TODO make this required and give it a default |
### DataQuery
These are the common properties available to all queries in all datasources.
Specific implementations will *extend* this interface, adding the required
properties for the given context.
| Property | Type | Required | Description |
|--------------|---------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `refId` | string | **Yes** | A - Z |
| `datasource` | | No | For mixed data sources the selected datasource is on the query level.<br/>For non mixed scenarios this is undefined.<br/>TODO find a better way to do this ^ that's friendly to schema<br/>TODO this shouldn't be unknown but DataSourceRef &#124; null |
| `hide` | boolean | No | true if query is disabled (ie should not be returned to the dashboard) |
| `key` | string | No | Unique, guid like, string used in explore mode |
| `queryType` | string | No | Specify the query flavor<br/>TODO make this required and give it a default |

View File

@ -1094,7 +1094,9 @@
},
"parcadataquery": {
"category": "composable",
"codeowners": [],
"codeowners": [
"grafana/observability-traces-and-profiling"
],
"currentVersion": [
0,
0
@ -1102,13 +1104,13 @@
"grafanaMaturityCount": 0,
"lineageIsGroup": false,
"links": {
"docs": "n/a",
"go": "n/a",
"schema": "n/a",
"ts": "n/a"
"docs": "https://grafana.com/docs/grafana/next/developers/kinds/composable/parcadataquery/schema-reference",
"go": "https://github.com/grafana/grafana/tree/main/pkg/tsdb/parca/kinds/dataquery/types_dataquery_gen.go",
"schema": "https://github.com/grafana/grafana/tree/main/public/app/plugins/datasource/parca/dataquery.cue",
"ts": "https://github.com/grafana/grafana/tree/main/public/app/plugins/datasource/parca/dataquery.gen.ts"
},
"machineName": "parcadataquery",
"maturity": "planned",
"maturity": "experimental",
"name": "ParcaDataQuery",
"pluralMachineName": "parcadataquerys",
"pluralName": "ParcaDataQuerys",
@ -1992,6 +1994,7 @@
"lokidataquery",
"newspanelcfg",
"nodegraphpanelcfg",
"parcadataquery",
"phlaredataquery",
"piechartpanelcfg",
"statetimelinepanelcfg",
@ -2002,7 +2005,7 @@
"textpanelcfg",
"xychartpanelcfg"
],
"count": 22
"count": 23
},
"mature": {
"name": "mature",
@ -2057,7 +2060,6 @@
"microsoftsqlserverdatasourcecfg",
"mysqldataquery",
"mysqldatasourcecfg",
"parcadataquery",
"parcadatasourcecfg",
"phlaredatasourcecfg",
"postgresqldataquery",
@ -2076,7 +2078,7 @@
"zipkindataquery",
"zipkindatasourcecfg"
],
"count": 49
"count": 48
},
"stable": {
"name": "stable",

View File

@ -87,15 +87,15 @@ func makeBenchResults(count int) eval.Results {
EvaluatedAt: time.Now().UTC(),
EvaluationDuration: 5 * time.Second,
Values: map[string]eval.NumberValueCapture{
"A": eval.NumberValueCapture{
"A": {
Var: "A",
Value: &one,
},
"B": eval.NumberValueCapture{
"B": {
Var: "B",
Value: &one,
},
"C": eval.NumberValueCapture{
"C": {
Var: "C",
Value: &one,
},

View File

@ -0,0 +1,50 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
//
// Generated by:
// public/app/plugins/gen.go
// Using jennies:
// PluginGoTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
package dataquery
// Defines values for ParcaQueryType.
const (
ParcaQueryTypeBoth ParcaQueryType = "both"
ParcaQueryTypeMetrics ParcaQueryType = "metrics"
ParcaQueryTypeProfile ParcaQueryType = "profile"
)
// ParcaDataQuery defines model for ParcaDataQuery.
type ParcaDataQuery struct {
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
Datasource *interface{} `json:"datasource,omitempty"`
// true if query is disabled (ie should not be returned to the dashboard)
Hide *bool `json:"hide,omitempty"`
// Unique, guid like, string used in explore mode
Key *string `json:"key,omitempty"`
// Specifies the query label selectors.
LabelSelector string `json:"labelSelector"`
// Specifies the type of profile to query.
ProfileTypeId string `json:"profileTypeId"`
// Specify the query flavor
// TODO make this required and give it a default
QueryType *string `json:"queryType,omitempty"`
// A - Z
RefId string `json:"refId"`
}
// ParcaQueryType defines model for ParcaQueryType.
type ParcaQueryType string

View File

@ -11,18 +11,19 @@ import (
"github.com/bufbuild/connect-go"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/tsdb/parca/kinds/dataquery"
"google.golang.org/protobuf/types/known/timestamppb"
)
type queryModel struct {
ProfileTypeID string `json:"profileTypeId"`
LabelSelector string `json:"labelSelector"`
dataquery.ParcaDataQuery
}
// These constants need to match the ones in the frontend.
const queryTypeProfile = "profile"
const queryTypeMetrics = "metrics"
const queryTypeBoth = "both"
const (
queryTypeProfile = string(dataquery.ParcaQueryTypeProfile)
queryTypeMetrics = string(dataquery.ParcaQueryTypeMetrics)
queryTypeBoth = string(dataquery.ParcaQueryTypeBoth)
)
// query processes single Parca query transforming the response to data.Frame packaged in DataResponse
func (d *ParcaDatasource) query(ctx context.Context, pCtx backend.PluginContext, query backend.DataQuery) backend.DataResponse {
@ -41,7 +42,7 @@ func (d *ParcaDatasource) query(ctx context.Context, pCtx backend.PluginContext,
response.Error = err
return response
}
response.Frames = append(response.Frames, seriesToDataFrame(seriesResp, qm.ProfileTypeID)...)
response.Frames = append(response.Frames, seriesToDataFrame(seriesResp, qm.ProfileTypeId)...)
}
if query.QueryType == queryTypeProfile || query.QueryType == queryTypeBoth {
@ -64,7 +65,7 @@ func makeProfileRequest(qm queryModel, query backend.DataQuery) *connect.Request
Mode: v1alpha1.QueryRequest_MODE_MERGE,
Options: &v1alpha1.QueryRequest_Merge{
Merge: &v1alpha1.MergeProfile{
Query: fmt.Sprintf("%s%s", qm.ProfileTypeID, qm.LabelSelector),
Query: fmt.Sprintf("%s%s", qm.ProfileTypeId, qm.LabelSelector),
Start: &timestamppb.Timestamp{
Seconds: query.TimeRange.From.Unix(),
},
@ -83,7 +84,7 @@ func makeProfileRequest(qm queryModel, query backend.DataQuery) *connect.Request
func makeMetricRequest(qm queryModel, query backend.DataQuery) *connect.Request[v1alpha1.QueryRangeRequest] {
return &connect.Request[v1alpha1.QueryRangeRequest]{
Msg: &v1alpha1.QueryRangeRequest{
Query: fmt.Sprintf("%s%s", qm.ProfileTypeID, qm.LabelSelector),
Query: fmt.Sprintf("%s%s", qm.ProfileTypeId, qm.LabelSelector),
Start: &timestamppb.Timestamp{
Seconds: query.TimeRange.From.Unix(),
},

View File

@ -5,8 +5,9 @@ import { useMount } from 'react-use';
import { CoreApp, QueryEditorProps } from '@grafana/data';
import { ButtonCascader, CascaderOption } from '@grafana/ui';
import { defaultParca, defaultParcaQueryType, Parca } from '../dataquery.gen';
import { ParcaDataSource } from '../datasource';
import { defaultQuery, ParcaDataSourceOptions, ProfileTypeMessage, Query } from '../types';
import { ParcaDataSourceOptions, ProfileTypeMessage, Query } from '../types';
import { EditorRow } from './EditorRow';
import { EditorRows } from './EditorRows';
@ -15,6 +16,11 @@ import { QueryOptions } from './QueryOptions';
export type Props = QueryEditorProps<ParcaDataSource, Query, ParcaDataSourceOptions>;
export const defaultQuery: Partial<Parca> = {
...defaultParca,
queryType: defaultParcaQueryType,
};
export function QueryEditor(props: Props) {
const [profileTypes, setProfileTypes] = useState<ProfileTypeMessage[]>([]);

View File

@ -0,0 +1,46 @@
// Copyright 2023 Grafana Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package grafanaplugin
import (
"github.com/grafana/grafana/packages/grafana-schema/src/common"
"github.com/grafana/grafana/pkg/plugins/pfs"
)
// This file (with its sibling .cue files) implements pfs.GrafanaPlugin
pfs.GrafanaPlugin
composableKinds: DataQuery: {
maturity: "experimental"
lineage: {
seqs: [
{
schemas: [
// v0.0
{
common.DataQuery
// Specifies the query label selectors.
labelSelector: string | *"{}"
// Specifies the type of profile to query.
profileTypeId: string
#ParcaQueryType: "metrics" | "profile" | *"both" @cuetsy(kind="type")
},
]
},
]
}
}

View File

@ -0,0 +1,32 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
//
// Generated by:
// public/app/plugins/gen.go
// Using jennies:
// TSTypesJenny
// PluginTSTypesJenny
//
// Run 'make gen-cue' from repository root to regenerate.
import * as common from '@grafana/schema';
export const DataQueryModelVersion = Object.freeze([0, 0]);
export type ParcaQueryType = ('metrics' | 'profile' | 'both');
export const defaultParcaQueryType: ParcaQueryType = 'both';
export interface Parca extends common.DataQuery {
/**
* Specifies the query label selectors.
*/
labelSelector: string;
/**
* Specifies the type of profile to query.
*/
profileTypeId: string;
}
export const defaultParca: Partial<Parca> = {
labelSelector: '{}',
};

View File

@ -1,9 +1,9 @@
import { DataQuery, DataSourceJsonData } from '@grafana/data';
import { DataSourceJsonData } from '@grafana/data';
export interface Query extends DataQuery {
labelSelector: string;
profileTypeId: string;
queryType: 'metrics' | 'profile' | 'both';
import { Parca as ParcaBase, ParcaQueryType } from './dataquery.gen';
export interface Query extends ParcaBase {
queryType: ParcaQueryType;
}
export interface ProfileTypeMessage {
@ -15,11 +15,6 @@ export interface ProfileTypeMessage {
sample_unit: string;
}
export const defaultQuery: Partial<Query> = {
labelSelector: '{}',
queryType: 'both',
};
/**
* These are options configured for each DataSource instance.
*/