Expressions: Create json schema for query types (#84032)

This commit is contained in:
Ryan McKinley
2024-03-26 07:58:56 +03:00
committed by GitHub
parent 2e06677240
commit 4cda34ff7d
40 changed files with 4649 additions and 654 deletions

View File

@@ -3,7 +3,7 @@ import React from 'react';
import { MetadataInspectorProps } from '@grafana/data';
import { Stack } from '@grafana/ui';
import { TestDataDataQuery } from './dataquery.gen';
import { TestDataDataQuery } from './dataquery';
import { TestDataDataSource } from './datasource';
export type Props = MetadataInspectorProps<TestDataDataSource, TestDataDataQuery>;

View File

@@ -5,7 +5,7 @@ import React from 'react';
import { QueryEditor, Props } from './QueryEditor';
import { scenarios } from './__mocks__/scenarios';
import { defaultQuery } from './constants';
import { TestDataQueryType } from './dataquery.gen';
import { TestDataQueryType } from './dataquery';
import { TestDataDataSource } from './datasource';
import { defaultStreamQuery } from './runStreams';

View File

@@ -17,7 +17,7 @@ import { RawFrameEditor } from './components/RawFrameEditor';
import { SimulationQueryEditor } from './components/SimulationQueryEditor';
import { USAQueryEditor, usaQueryModes } from './components/USAQueryEditor';
import { defaultCSVWaveQuery, defaultPulseQuery, defaultQuery } from './constants';
import { CSVWave, NodesQuery, TestDataDataQuery, TestDataQueryType, USAQuery } from './dataquery.gen';
import { CSVWave, NodesQuery, TestDataDataQuery, TestDataQueryType, USAQuery } from './dataquery';
import { TestDataDataSource } from './datasource';
import { defaultStreamQuery } from './runStreams';

View File

@@ -1,4 +1,4 @@
import { TestDataQueryType } from '../dataquery.gen';
import { TestDataQueryType } from '../dataquery';
export const scenarios = [
{

View File

@@ -3,7 +3,7 @@ import React, { PureComponent, useState } from 'react';
import { Button, InlineField, InlineFieldRow, Input } from '@grafana/ui';
import { defaultCSVWaveQuery } from '../constants';
import type { CSVWave } from '../dataquery.gen';
import type { CSVWave } from '../dataquery';
interface WavesProps {
waves?: CSVWave[];

View File

@@ -2,7 +2,7 @@ import React from 'react';
import { Input, InlineFieldRow, InlineField, Select } from '@grafana/ui';
import { NodesQuery, TestDataDataQuery } from '../dataquery.gen';
import { NodesQuery, TestDataDataQuery } from '../dataquery';
export interface Props {
onChange: (value: NodesQuery) => void;

View File

@@ -3,7 +3,7 @@ import React, { ChangeEvent } from 'react';
import { InlineField, InlineFieldRow, Input } from '@grafana/ui';
import { EditorProps } from '../QueryEditor';
import { PulseWaveQuery } from '../dataquery.gen';
import { PulseWaveQuery } from '../dataquery';
const fields: Array<{
label: string;

View File

@@ -4,7 +4,7 @@ import { selectors } from '@grafana/e2e-selectors';
import { InlineField, InlineFieldRow, Input } from '@grafana/ui';
import { EditorProps } from '../QueryEditor';
import { TestDataDataQuery } from '../dataquery.gen';
import { TestDataDataQuery } from '../dataquery';
const randomWalkFields: Array<{
label: string;

View File

@@ -5,7 +5,7 @@ import { DataFrameJSON, SelectableValue } from '@grafana/data';
import { InlineField, InlineFieldRow, InlineSwitch, Input, Label, Select } from '@grafana/ui';
import { EditorProps } from '../QueryEditor';
import { SimulationQuery } from '../dataquery.gen';
import { SimulationQuery } from '../dataquery';
import { SimulationSchemaForm } from './SimulationSchemaForm';

View File

@@ -3,7 +3,7 @@ import React from 'react';
import { SelectableValue } from '@grafana/data';
import { InlineFieldRow, InlineField, Select, MultiSelect, Input } from '@grafana/ui';
import { USAQuery } from '../dataquery.gen';
import { USAQuery } from '../dataquery';
export interface Props {
onChange: (value: USAQuery) => void;

View File

@@ -1,4 +1,4 @@
import { CSVWave, PulseWaveQuery, TestDataDataQuery, TestDataQueryType } from './dataquery.gen';
import { CSVWave, PulseWaveQuery, TestDataDataQuery, TestDataQueryType } from './dataquery';
export const defaultPulseQuery: PulseWaveQuery = {
timeStep: 60,

View File

@@ -1,117 +0,0 @@
// 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"
)
composableKinds: DataQuery: {
maturity: "experimental"
lineage: {
schemas: [{
version: [0, 0]
schema: {
common.DataQuery
alias?: string
scenarioId?: #TestDataQueryType & (*"random_walk" | _)
stringInput?: string
stream?: #StreamingQuery
pulseWave?: #PulseWaveQuery
sim?: #SimulationQuery
csvWave?: [...#CSVWave] //TODO can we prevent partial from being generated
labels?: string
lines?: int64
levelColumn?: bool
channel?: string
nodes?: #NodesQuery
csvFileName?: string
csvContent?: string
rawFrameContent?: string
seriesCount?: int32
usa?: #USAQuery
errorType?: "server_panic" | "frontend_exception" | "frontend_observable"
spanCount?: int32
points?: [...[...string | int64]]
// Drop percentage (the chance we will lose a point 0-100)
dropPercent?: float64
flamegraphDiff?: bool
#TestDataQueryType: "random_walk" | "slow_query" | "random_walk_with_error" | "random_walk_table" | "exponential_heatmap_bucket_data" | "linear_heatmap_bucket_data" | "no_data_points" | "datapoints_outside_range" | "csv_metric_values" | "predictable_pulse" | "predictable_csv_wave" | "streaming_client" | "simulation" | "usa" | "live" | "grafana_api" | "arrow" | "annotations" | "table_static" | "server_error_500" | "logs" | "node_graph" | "flame_graph" | "raw_frame" | "csv_file" | "csv_content" | "trace" | "manual_entry" | "variables-query" @cuetsy(kind="enum", memberNames="RandomWalk|SlowQuery|RandomWalkWithError|RandomWalkTable|ExponentialHeatmapBucketData|LinearHeatmapBucketData|NoDataPoints|DataPointsOutsideRange|CSVMetricValues|PredictablePulse|PredictableCSVWave|StreamingClient|Simulation|USA|Live|GrafanaAPI|Arrow|Annotations|TableStatic|ServerError500|Logs|NodeGraph|FlameGraph|RawFrame|CSVFile|CSVContent|Trace|ManualEntry|VariablesQuery")
#StreamingQuery: {
type: "signal" | "logs" | "fetch" | "traces"
speed: int32
spread: int32
noise: int32
bands?: int32
url?: string
} @cuetsy(kind="interface")
#PulseWaveQuery: {
timeStep?: int64
onCount?: int64
offCount?: int64
onValue?: float64
offValue?: float64
} @cuetsy(kind="interface")
#SimulationQuery: {
key: {
type: string
tick: float64
uid?: string
}
config?: {...}
stream?: bool
last?: bool
} @cuetsy(kind="interface")
#NodesQuery: {
type?: "random" | "response_small" | "response_medium" | "random edges" | "feature_showcase"
count?: int64
seed?: int64
} @cuetsy(kind="interface")
#USAQuery: {
mode?: string
period?: string
fields?: [...string]
states?: [...string]
} @cuetsy(kind="interface")
#CSVWave: {
timeStep?: int64
name?: string
valuesCSV?: string
labels?: string
} @cuetsy(kind="interface")
// TODO: Should this live here given it's not used in the dataquery?
#Scenario: {
id: string
name: string
stringInput: string
description?: string
hideAliasField?: bool
} @cuetsy(kind="interface")
}
}]
lenses: []
}
}

View File

@@ -1,12 +1,5 @@
// 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.
// Code was originally generated from cue
// It must now be updated manually
import * as common from '@grafana/schema';
@@ -47,7 +40,7 @@ export interface StreamingQuery {
noise: number;
speed: number;
spread: number;
type: ('signal' | 'logs' | 'fetch' | 'traces');
type: 'signal' | 'logs' | 'fetch' | 'traces';
url?: string;
}
@@ -73,14 +66,14 @@ export interface SimulationQuery {
export interface NodesQuery {
count?: number;
seed?: number;
type?: ('random' | 'response_small' | 'response_medium' | 'random edges' | 'feature_showcase');
type?: 'random' | 'response_small' | 'response_medium' | 'random edges' | 'feature_showcase';
}
export interface USAQuery {
fields?: Array<string>;
fields?: string[];
mode?: string;
period?: string;
states?: Array<string>;
states?: string[];
}
export const defaultUSAQuery: Partial<USAQuery> = {
@@ -111,18 +104,18 @@ export interface TestDataDataQuery extends common.DataQuery {
channel?: string;
csvContent?: string;
csvFileName?: string;
csvWave?: Array<CSVWave>; // TODO can we prevent partial from being generated
csvWave?: CSVWave[]; // TODO can we prevent partial from being generated
/**
* Drop percentage (the chance we will lose a point 0-100)
*/
dropPercent?: number;
errorType?: ('server_panic' | 'frontend_exception' | 'frontend_observable');
errorType?: 'server_panic' | 'frontend_exception' | 'frontend_observable';
flamegraphDiff?: boolean;
labels?: string;
levelColumn?: boolean;
lines?: number;
nodes?: NodesQuery;
points?: Array<Array<(string | number)>>;
points?: Array<Array<string | number>>;
pulseWave?: PulseWaveQuery;
rawFrameContent?: string;
scenarioId?: TestDataQueryType;

View File

@@ -20,7 +20,7 @@ import {
} from '@grafana/data';
import { DataSourceWithBackend, getBackendSrv, getGrafanaLiveSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
import { Scenario, TestDataDataQuery, TestDataQueryType } from './dataquery.gen';
import { Scenario, TestDataDataQuery, TestDataQueryType } from './dataquery';
import { queryMetricTree } from './metricTree';
import { generateRandomEdges, generateRandomNodes, generateShowcaseData, savedNodesResponse } from './nodeGraphUtils';
import { runStream } from './runStreams';

View File

@@ -20,7 +20,7 @@ import {
} from '@grafana/data';
import { getRandomLine } from './LogIpsum';
import { TestDataDataQuery, StreamingQuery } from './dataquery.gen';
import { TestDataDataQuery, StreamingQuery } from './dataquery';
export const defaultStreamQuery: StreamingQuery = {
type: 'signal',

View File

@@ -1,6 +1,6 @@
import { StandardVariableQuery, StandardVariableSupport } from '@grafana/data';
import { TestDataDataQuery, TestDataQueryType } from './dataquery.gen';
import { TestDataDataQuery, TestDataQueryType } from './dataquery';
import { TestDataDataSource } from './datasource';
export class TestDataVariableSupport extends StandardVariableSupport<TestDataDataSource> {