mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Phlare: Use data query schema (#62112)
* Create cue file and gen ts/go types * Use generated schema in ts/go * Run make den-cue to update report * Manually extend Phlare query * Updates * Add default queryType * Run make gen-cue to Update report.json
This commit is contained in:
@@ -5,8 +5,9 @@ import { useAsync } from 'react-use';
|
||||
import { CoreApp, QueryEditorProps } from '@grafana/data';
|
||||
import { ButtonCascader, CascaderOption } from '@grafana/ui';
|
||||
|
||||
import { defaultPhlare, defaultPhlareQueryType, Phlare } from '../dataquery.gen';
|
||||
import { PhlareDataSource } from '../datasource';
|
||||
import { defaultQuery, PhlareDataSourceOptions, ProfileTypeMessage, Query } from '../types';
|
||||
import { PhlareDataSourceOptions, ProfileTypeMessage, Query } from '../types';
|
||||
|
||||
import { EditorRow } from './EditorRow';
|
||||
import { EditorRows } from './EditorRows';
|
||||
@@ -15,6 +16,11 @@ import { QueryOptions } from './QueryOptions';
|
||||
|
||||
export type Props = QueryEditorProps<PhlareDataSource, Query, PhlareDataSourceOptions>;
|
||||
|
||||
export const defaultQuery: Partial<Phlare> = {
|
||||
...defaultPhlare,
|
||||
queryType: defaultPhlareQueryType,
|
||||
};
|
||||
|
||||
export function QueryEditor(props: Props) {
|
||||
const profileTypes = useProfileTypes(props.datasource);
|
||||
|
||||
|
||||
48
public/app/plugins/datasource/phlare/dataquery.cue
Normal file
48
public/app/plugins/datasource/phlare/dataquery.cue
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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
|
||||
// Allows to group the results.
|
||||
groupBy: [...string]
|
||||
#PhlareQueryType: "metrics" | "profile" | *"both" @cuetsy(kind="type")
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
37
public/app/plugins/datasource/phlare/dataquery.gen.ts
Normal file
37
public/app/plugins/datasource/phlare/dataquery.gen.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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 PhlareQueryType = ('metrics' | 'profile' | 'both');
|
||||
|
||||
export const defaultPhlareQueryType: PhlareQueryType = 'both';
|
||||
|
||||
export interface Phlare extends common.DataQuery {
|
||||
/**
|
||||
* Allows to group the results.
|
||||
*/
|
||||
groupBy: Array<string>;
|
||||
/**
|
||||
* Specifies the query label selectors.
|
||||
*/
|
||||
labelSelector: string;
|
||||
/**
|
||||
* Specifies the type of profile to query.
|
||||
*/
|
||||
profileTypeId: string;
|
||||
}
|
||||
|
||||
export const defaultPhlare: Partial<Phlare> = {
|
||||
groupBy: [],
|
||||
labelSelector: '{}',
|
||||
};
|
||||
@@ -1,10 +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';
|
||||
groupBy: string[];
|
||||
import { Phlare as PhlareBase, PhlareQueryType } from './dataquery.gen';
|
||||
|
||||
export interface Query extends PhlareBase {
|
||||
queryType: PhlareQueryType;
|
||||
}
|
||||
|
||||
export interface ProfileTypeMessage {
|
||||
@@ -18,12 +17,6 @@ export interface ProfileTypeMessage {
|
||||
|
||||
export type SeriesMessage = Array<{ labels: Array<{ name: string; value: string }> }>;
|
||||
|
||||
export const defaultQuery: Partial<Query> = {
|
||||
labelSelector: '{}',
|
||||
queryType: 'both',
|
||||
groupBy: [],
|
||||
};
|
||||
|
||||
/**
|
||||
* These are options configured for each DataSource instance.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user