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
9 changed files with 206 additions and 32 deletions

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(),
},