From 5aa965b9e948a30cc9fa71becabc81d8f2d97b65 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 4 Mar 2024 10:23:32 -0800 Subject: [PATCH] Prometheus: remove cue definition (#83808) Co-authored-by: ismail simsek --- packages/grafana-prometheus/src/dataquery.cue | 58 ---------- .../grafana-prometheus/src/dataquery.ts | 12 +- packages/grafana-prometheus/src/index.ts | 2 +- .../components/PromQueryBuilderOptions.tsx | 2 +- .../components/PromQueryEditorSelector.tsx | 2 +- packages/grafana-prometheus/src/types.ts | 2 +- .../x/PrometheusDataQuery_types.gen.ts | 60 ---------- pkg/tsdb/prometheus/healthcheck.go | 12 +- .../kinds/dataquery/types_dataquery_gen.go | 106 ------------------ pkg/tsdb/prometheus/models/query.go | 101 ++++++++++++----- pkg/tsdb/prometheus/models/result.go | 1 + .../querydata/framing_bench_test.go | 7 +- pkg/tsdb/prometheus/querydata/framing_test.go | 18 +-- pkg/tsdb/prometheus/querydata/request_test.go | 46 ++++---- .../datasource/prometheus/dataquery.cue | 58 ---------- .../datasource/prometheus/dataquery.ts | 12 +- .../components/PromQueryBuilderOptions.tsx | 2 +- .../components/PromQueryEditorSelector.tsx | 2 +- .../plugins/datasource/prometheus/types.ts | 2 +- 19 files changed, 120 insertions(+), 385 deletions(-) delete mode 100644 packages/grafana-prometheus/src/dataquery.cue rename public/app/plugins/datasource/prometheus/dataquery.gen.ts => packages/grafana-prometheus/src/dataquery.ts (82%) delete mode 100644 packages/grafana-schema/src/raw/composable/prometheus/dataquery/x/PrometheusDataQuery_types.gen.ts delete mode 100644 pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go delete mode 100644 public/app/plugins/datasource/prometheus/dataquery.cue rename packages/grafana-prometheus/src/dataquery.gen.ts => public/app/plugins/datasource/prometheus/dataquery.ts (82%) diff --git a/packages/grafana-prometheus/src/dataquery.cue b/packages/grafana-prometheus/src/dataquery.cue deleted file mode 100644 index 177af1929c6..00000000000 --- a/packages/grafana-prometheus/src/dataquery.cue +++ /dev/null @@ -1,58 +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 ( - common "github.com/grafana/grafana/packages/grafana-schema/src/common" -) - -composableKinds: DataQuery: { - maturity: "experimental" - - lineage: { - schemas: [{ - version: [0, 0] - schema: { - common.DataQuery - - // The actual expression/query that will be evaluated by Prometheus - expr: string - // Returns only the latest value that Prometheus has scraped for the requested time series - instant?: bool - // Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series - range?: bool - // Execute an additional query to identify interesting raw samples relevant for the given expr - exemplar?: bool - // Specifies which editor is being used to prepare the query. It can be "code" or "builder" - editorMode?: #QueryEditorMode - // Query format to determine how to display data points in panel. It can be "time_series", "table", "heatmap" - format?: #PromQueryFormat - // Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname - legendFormat?: string - // @deprecated Used to specify how many times to divide max data points by. We use max data points under query options - // See https://github.com/grafana/grafana/issues/48081 - intervalFactor?: number - - scope?: { - matchers: string - } - - #QueryEditorMode: "code" | "builder" @cuetsy(kind="enum") - #PromQueryFormat: "time_series" | "table" | "heatmap" @cuetsy(kind="type") - } - }] - lenses: [] - } -} diff --git a/public/app/plugins/datasource/prometheus/dataquery.gen.ts b/packages/grafana-prometheus/src/dataquery.ts similarity index 82% rename from public/app/plugins/datasource/prometheus/dataquery.gen.ts rename to packages/grafana-prometheus/src/dataquery.ts index 3ba622cecff..8609fc78914 100644 --- a/public/app/plugins/datasource/prometheus/dataquery.gen.ts +++ b/packages/grafana-prometheus/src/dataquery.ts @@ -1,13 +1,3 @@ -// 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 enum QueryEditorMode { @@ -15,7 +5,7 @@ export enum QueryEditorMode { Code = 'code', } -export type PromQueryFormat = ('time_series' | 'table' | 'heatmap'); +export type PromQueryFormat = 'time_series' | 'table' | 'heatmap'; export interface Prometheus extends common.DataQuery { /** diff --git a/packages/grafana-prometheus/src/index.ts b/packages/grafana-prometheus/src/index.ts index 978ddc79b0d..76302ec9570 100644 --- a/packages/grafana-prometheus/src/index.ts +++ b/packages/grafana-prometheus/src/index.ts @@ -62,7 +62,7 @@ export { PromQail } from './querybuilder/components/promQail/PromQail'; export { PrometheusDatasource } from './datasource'; // The parts export { addLabelToQuery } from './add_label_to_query'; -export { type QueryEditorMode, type PromQueryFormat, type Prometheus } from './dataquery.gen'; +export { type QueryEditorMode, type PromQueryFormat, type Prometheus } from './dataquery'; export { PrometheusMetricFindQuery } from './metric_find_query'; export { promqlGrammar } from './promql'; export { getQueryHints, getInitHints } from './query_hints'; diff --git a/packages/grafana-prometheus/src/querybuilder/components/PromQueryBuilderOptions.tsx b/packages/grafana-prometheus/src/querybuilder/components/PromQueryBuilderOptions.tsx index 5a6b8273799..50788f2c629 100644 --- a/packages/grafana-prometheus/src/querybuilder/components/PromQueryBuilderOptions.tsx +++ b/packages/grafana-prometheus/src/querybuilder/components/PromQueryBuilderOptions.tsx @@ -6,7 +6,7 @@ import { EditorField, EditorRow, EditorSwitch } from '@grafana/experimental'; import { AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui'; import { getQueryTypeChangeHandler, getQueryTypeOptions } from '../../components/PromExploreExtraField'; -import { PromQueryFormat } from '../../dataquery.gen'; +import { PromQueryFormat } from '../../dataquery'; import { PromQuery } from '../../types'; import { QueryOptionGroup } from '../shared/QueryOptionGroup'; diff --git a/packages/grafana-prometheus/src/querybuilder/components/PromQueryEditorSelector.tsx b/packages/grafana-prometheus/src/querybuilder/components/PromQueryEditorSelector.tsx index a0016b986e8..f85090e0cad 100644 --- a/packages/grafana-prometheus/src/querybuilder/components/PromQueryEditorSelector.tsx +++ b/packages/grafana-prometheus/src/querybuilder/components/PromQueryEditorSelector.tsx @@ -8,7 +8,7 @@ import { reportInteraction } from '@grafana/runtime'; import { Button, ConfirmModal, Space } from '@grafana/ui'; import { PromQueryEditorProps } from '../../components/types'; -import { PromQueryFormat } from '../../dataquery.gen'; +import { PromQueryFormat } from '../../dataquery'; import { PromQuery } from '../../types'; import { QueryPatternsModal } from '../QueryPatternsModal'; import { promQueryEditorExplainKey, useFlag } from '../hooks/useFlag'; diff --git a/packages/grafana-prometheus/src/types.ts b/packages/grafana-prometheus/src/types.ts index 5ddb69d811b..f3c5730b380 100644 --- a/packages/grafana-prometheus/src/types.ts +++ b/packages/grafana-prometheus/src/types.ts @@ -1,7 +1,7 @@ import { DataSourceJsonData } from '@grafana/data'; import { DataQuery } from '@grafana/schema'; -import { Prometheus as GenPromQuery } from './dataquery.gen'; +import { Prometheus as GenPromQuery } from './dataquery'; import { QueryBuilderLabelFilter, QueryEditorMode } from './querybuilder/shared/types'; export interface PromQuery extends GenPromQuery, DataQuery { diff --git a/packages/grafana-schema/src/raw/composable/prometheus/dataquery/x/PrometheusDataQuery_types.gen.ts b/packages/grafana-schema/src/raw/composable/prometheus/dataquery/x/PrometheusDataQuery_types.gen.ts deleted file mode 100644 index 0d3806b34e6..00000000000 --- a/packages/grafana-schema/src/raw/composable/prometheus/dataquery/x/PrometheusDataQuery_types.gen.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Code generated - EDITING IS FUTILE. DO NOT EDIT. -// -// Generated by: -// public/app/plugins/gen.go -// Using jennies: -// TSTypesJenny -// LatestMajorsOrXJenny -// PluginEachMajorJenny -// -// Run 'make gen-cue' from repository root to regenerate. - -import * as common from '@grafana/schema'; - -export const pluginVersion = "11.0.0-pre"; - -export enum QueryEditorMode { - Builder = 'builder', - Code = 'code', -} - -export type PromQueryFormat = ('time_series' | 'table' | 'heatmap'); - -export interface PrometheusDataQuery extends common.DataQuery { - /** - * Specifies which editor is being used to prepare the query. It can be "code" or "builder" - */ - editorMode?: QueryEditorMode; - /** - * Execute an additional query to identify interesting raw samples relevant for the given expr - */ - exemplar?: boolean; - /** - * The actual expression/query that will be evaluated by Prometheus - */ - expr: string; - /** - * Query format to determine how to display data points in panel. It can be "time_series", "table", "heatmap" - */ - format?: PromQueryFormat; - /** - * Returns only the latest value that Prometheus has scraped for the requested time series - */ - instant?: boolean; - /** - * @deprecated Used to specify how many times to divide max data points by. We use max data points under query options - * See https://github.com/grafana/grafana/issues/48081 - */ - intervalFactor?: number; - /** - * Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname - */ - legendFormat?: string; - /** - * Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series - */ - range?: boolean; - scope?: { - matchers: string; - }; -} diff --git a/pkg/tsdb/prometheus/healthcheck.go b/pkg/tsdb/prometheus/healthcheck.go index 4041d9c08e0..1f5e6324c09 100644 --- a/pkg/tsdb/prometheus/healthcheck.go +++ b/pkg/tsdb/prometheus/healthcheck.go @@ -7,12 +7,9 @@ import ( "fmt" "time" - "github.com/grafana/kindsys" - "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/log" - "github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery" "github.com/grafana/grafana/pkg/tsdb/prometheus/models" ) @@ -59,12 +56,13 @@ func (s *Service) CheckHealth(ctx context.Context, req *backend.CheckHealthReque func healthcheck(ctx context.Context, req *backend.CheckHealthRequest, i *instance) (*backend.CheckHealthResult, error) { qm := models.QueryModel{ - LegendFormat: "", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ + CommonQueryProperties: models.CommonQueryProperties{ + RefId: refID, + }, + PrometheusQueryProperties: models.PrometheusQueryProperties{ Expr: "1+1", - Instant: kindsys.Ptr(true), - RefId: refID, + Instant: true, }, } b, _ := json.Marshal(&qm) diff --git a/pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go deleted file mode 100644 index b31c9eee626..00000000000 --- a/pkg/tsdb/prometheus/kinds/dataquery/types_dataquery_gen.go +++ /dev/null @@ -1,106 +0,0 @@ -// 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 PromQueryFormat. -const ( - PromQueryFormatHeatmap PromQueryFormat = "heatmap" - PromQueryFormatTable PromQueryFormat = "table" - PromQueryFormatTimeSeries PromQueryFormat = "time_series" -) - -// Defines values for QueryEditorMode. -const ( - QueryEditorModeBuilder QueryEditorMode = "builder" - QueryEditorModeCode QueryEditorMode = "code" -) - -// 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. -type DataQuery 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 *any `json:"datasource,omitempty"` - - // Hide true if query is disabled (ie should not be returned to the dashboard) - // Note this does not always imply that the query should not be executed since - // the results from a hidden query may be used as the input to other queries (SSE etc) - Hide *bool `json:"hide,omitempty"` - - // Specify the query flavor - // TODO make this required and give it a default - QueryType *string `json:"queryType,omitempty"` - - // A unique identifier for the query within the list of targets. - // In server side expressions, the refId is used as a variable name to identify results. - // By default, the UI will assign A->Z; however setting meaningful names may be useful. - RefId string `json:"refId"` -} - -// PromQueryFormat defines model for PromQueryFormat. -type PromQueryFormat string - -// PrometheusDataQuery defines model for PrometheusDataQuery. -type PrometheusDataQuery struct { - // 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. - DataQuery - - // 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 *any `json:"datasource,omitempty"` - EditorMode *QueryEditorMode `json:"editorMode,omitempty"` - - // Execute an additional query to identify interesting raw samples relevant for the given expr - Exemplar *bool `json:"exemplar,omitempty"` - - // The actual expression/query that will be evaluated by Prometheus - Expr string `json:"expr"` - Format *PromQueryFormat `json:"format,omitempty"` - - // Hide true if query is disabled (ie should not be returned to the dashboard) - // Note this does not always imply that the query should not be executed since - // the results from a hidden query may be used as the input to other queries (SSE etc) - Hide *bool `json:"hide,omitempty"` - - // Returns only the latest value that Prometheus has scraped for the requested time series - Instant *bool `json:"instant,omitempty"` - - // @deprecated Used to specify how many times to divide max data points by. We use max data points under query options - // See https://github.com/grafana/grafana/issues/48081 - IntervalFactor *float32 `json:"intervalFactor,omitempty"` - - // Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname - LegendFormat *string `json:"legendFormat,omitempty"` - - // Specify the query flavor - // TODO make this required and give it a default - QueryType *string `json:"queryType,omitempty"` - - // Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series - Range *bool `json:"range,omitempty"` - - // A unique identifier for the query within the list of targets. - // In server side expressions, the refId is used as a variable name to identify results. - // By default, the UI will assign A->Z; however setting meaningful names may be useful. - RefId string `json:"refId"` - Scope *struct { - Matchers string `json:"matchers"` - } `json:"scope,omitempty"` -} - -// QueryEditorMode defines model for QueryEditorMode. -type QueryEditorMode string diff --git a/pkg/tsdb/prometheus/models/query.go b/pkg/tsdb/prometheus/models/query.go index 6c155810fb7..b510b769e01 100644 --- a/pkg/tsdb/prometheus/models/query.go +++ b/pkg/tsdb/prometheus/models/query.go @@ -14,9 +14,61 @@ import ( "github.com/prometheus/prometheus/promql/parser" "github.com/grafana/grafana/pkg/tsdb/prometheus/intervalv2" - "github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery" ) +// PromQueryFormat defines model for PromQueryFormat. +// +enum +type PromQueryFormat string + +const ( + PromQueryFormatTimeSeries PromQueryFormat = "time_series" + PromQueryFormatTable PromQueryFormat = "table" + PromQueryFormatHeatmap PromQueryFormat = "heatmap" +) + +// QueryEditorMode defines model for QueryEditorMode. +// +enum +type QueryEditorMode string + +const ( + QueryEditorModeBuilder QueryEditorMode = "builder" + QueryEditorModeCode QueryEditorMode = "code" +) + +// PrometheusQueryProperties defines the specific properties used for prometheus +type PrometheusQueryProperties struct { + // The response format + Format PromQueryFormat `json:"format,omitempty"` + + // The actual expression/query that will be evaluated by Prometheus + Expr string `json:"expr"` + + // Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series + Range bool `json:"range,omitempty"` + + // Returns only the latest value that Prometheus has scraped for the requested time series + Instant bool `json:"instant,omitempty"` + + // Execute an additional query to identify interesting raw samples relevant for the given expr + Exemplar bool `json:"exemplar,omitempty"` + + // what we should show in the editor + EditorMode QueryEditorMode `json:"editorMode,omitempty"` + + // Used to specify how many times to divide max data points by. We use max data points under query options + // See https://github.com/grafana/grafana/issues/48081 + // Deprecated: use interval + IntervalFactor int64 `json:"intervalFactor,omitempty"` + + // Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname + LegendFormat string `json:"legendFormat,omitempty"` + + // ??? + Scope *struct { + Matchers string `json:"matchers"` + } `json:"scope,omitempty"` +} + // Internal interval and range variables const ( varInterval = "$__interval" @@ -51,15 +103,22 @@ const ( var safeResolution = 11000 +// QueryModel includes both the common and specific values type QueryModel struct { - dataquery.PrometheusDataQuery + PrometheusQueryProperties `json:",inline"` + CommonQueryProperties `json:",inline"` + // The following properties may be part of the request payload, however they are not saved in panel JSON // Timezone offset to align start & end time on backend - UtcOffsetSec int64 `json:"utcOffsetSec,omitempty"` - LegendFormat string `json:"legendFormat,omitempty"` - Interval string `json:"interval,omitempty"` - IntervalMs int64 `json:"intervalMs,omitempty"` - IntervalFactor int64 `json:"intervalFactor,omitempty"` + UtcOffsetSec int64 `json:"utcOffsetSec,omitempty"` + Interval string `json:"interval,omitempty"` +} + +// CommonQueryProperties is properties applied to all queries +// NOTE: this will soon be replaced with a struct from the SDK +type CommonQueryProperties struct { + RefId string `json:"refId,omitempty"` + IntervalMs int64 `json:"intervalMs,omitempty"` } type TimeRange struct { @@ -68,6 +127,7 @@ type TimeRange struct { Step time.Duration } +// The internal query object type Query struct { Expr string Step time.Duration @@ -119,29 +179,14 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator return nil, err } } - var rangeQuery, instantQuery bool - if model.Instant == nil { - instantQuery = false - } else { - instantQuery = *model.Instant - } - if model.Range == nil { - rangeQuery = false - } else { - rangeQuery = *model.Range - } - if !instantQuery && !rangeQuery { + if !model.Instant && !model.Range { // In older dashboards, we were not setting range query param and !range && !instant was run as range query - rangeQuery = true + model.Range = true } // We never want to run exemplar query for alerting - exemplarQuery := false - if model.Exemplar != nil { - exemplarQuery = *model.Exemplar - } if fromAlert { - exemplarQuery = false + model.Exemplar = false } return &Query{ @@ -151,9 +196,9 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator Start: query.TimeRange.From, End: query.TimeRange.To, RefId: query.RefID, - InstantQuery: instantQuery, - RangeQuery: rangeQuery, - ExemplarQuery: exemplarQuery, + InstantQuery: model.Instant, + RangeQuery: model.Range, + ExemplarQuery: model.Exemplar, UtcOffsetSec: model.UtcOffsetSec, }, nil } diff --git a/pkg/tsdb/prometheus/models/result.go b/pkg/tsdb/prometheus/models/result.go index ea5e5c8934f..3cefc7fb3d6 100644 --- a/pkg/tsdb/prometheus/models/result.go +++ b/pkg/tsdb/prometheus/models/result.go @@ -6,6 +6,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" ) +// +enum type ResultType string const ( diff --git a/pkg/tsdb/prometheus/querydata/framing_bench_test.go b/pkg/tsdb/prometheus/querydata/framing_bench_test.go index 295810ed9f6..2b4cd28545b 100644 --- a/pkg/tsdb/prometheus/querydata/framing_bench_test.go +++ b/pkg/tsdb/prometheus/querydata/framing_bench_test.go @@ -15,11 +15,8 @@ import ( "time" "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/kindsys" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery" - "github.com/grafana/grafana/pkg/tsdb/prometheus/models" ) @@ -127,8 +124,8 @@ func createJsonTestData(start int64, step int64, timestampCount int, seriesCount bytes := []byte(fmt.Sprintf(`{"status":"success","data":{"resultType":"matrix","result":[%v]}}`, strings.Join(allSeries, ","))) qm := models.QueryModel{ - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Range: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Range: true, Expr: "test", }, } diff --git a/pkg/tsdb/prometheus/querydata/framing_test.go b/pkg/tsdb/prometheus/querydata/framing_test.go index 0bf8ed7284c..7138ba19e9e 100644 --- a/pkg/tsdb/prometheus/querydata/framing_test.go +++ b/pkg/tsdb/prometheus/querydata/framing_test.go @@ -16,8 +16,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/experimental" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery" - "github.com/grafana/grafana/pkg/tsdb/prometheus/models" ) @@ -109,14 +107,16 @@ func loadStoredQuery(fileName string) (*backend.QueryDataRequest, error) { } qm := models.QueryModel{ - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Range: &sq.RangeQuery, - Exemplar: &sq.ExemplarQuery, - Expr: sq.Expr, + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Range: sq.RangeQuery, + Exemplar: sq.ExemplarQuery, + Expr: sq.Expr, + LegendFormat: sq.LegendFormat, }, - Interval: fmt.Sprintf("%ds", sq.Step), - IntervalMs: sq.Step * 1000, - LegendFormat: sq.LegendFormat, + CommonQueryProperties: models.CommonQueryProperties{ + IntervalMs: sq.Step * 1000, + }, + Interval: fmt.Sprintf("%ds", sq.Step), } data, err := json.Marshal(&qm) diff --git a/pkg/tsdb/prometheus/querydata/request_test.go b/pkg/tsdb/prometheus/querydata/request_test.go index 79163a59905..cd3ba0f8672 100644 --- a/pkg/tsdb/prometheus/querydata/request_test.go +++ b/pkg/tsdb/prometheus/querydata/request_test.go @@ -15,10 +15,6 @@ import ( p "github.com/prometheus/common/model" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery" - - "github.com/grafana/kindsys" - "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" "github.com/grafana/grafana-plugin-sdk-go/backend/log" @@ -68,10 +64,10 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) { require.NoError(t, err) qm := models.QueryModel{ - LegendFormat: "legend {{app}}", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Exemplar: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + LegendFormat: "legend {{app}}", + Exemplar: true, }, } b, err := json.Marshal(&qm) @@ -115,10 +111,10 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) { } qm := models.QueryModel{ - LegendFormat: "legend {{app}}", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Range: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Range: true, + LegendFormat: "legend {{app}}", }, } b, err := json.Marshal(&qm) @@ -164,10 +160,10 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) { } qm := models.QueryModel{ - LegendFormat: "", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Range: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Range: true, + LegendFormat: "", }, } b, err := json.Marshal(&qm) @@ -209,10 +205,10 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) { } qm := models.QueryModel{ - LegendFormat: "", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Range: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Range: true, + LegendFormat: "", }, } b, err := json.Marshal(&qm) @@ -252,10 +248,10 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) { } qm := models.QueryModel{ - LegendFormat: "", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Range: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Range: true, + LegendFormat: "", }, } b, err := json.Marshal(&qm) @@ -289,10 +285,10 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) { }, } qm := models.QueryModel{ - LegendFormat: "legend {{app}}", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Instant: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Instant: true, + LegendFormat: "legend {{app}}", }, } b, err := json.Marshal(&qm) @@ -330,10 +326,10 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) { }, } qm := models.QueryModel{ - LegendFormat: "", UtcOffsetSec: 0, - PrometheusDataQuery: dataquery.PrometheusDataQuery{ - Instant: kindsys.Ptr(true), + PrometheusQueryProperties: models.PrometheusQueryProperties{ + Instant: true, + LegendFormat: "", }, } b, err := json.Marshal(&qm) diff --git a/public/app/plugins/datasource/prometheus/dataquery.cue b/public/app/plugins/datasource/prometheus/dataquery.cue deleted file mode 100644 index 177af1929c6..00000000000 --- a/public/app/plugins/datasource/prometheus/dataquery.cue +++ /dev/null @@ -1,58 +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 ( - common "github.com/grafana/grafana/packages/grafana-schema/src/common" -) - -composableKinds: DataQuery: { - maturity: "experimental" - - lineage: { - schemas: [{ - version: [0, 0] - schema: { - common.DataQuery - - // The actual expression/query that will be evaluated by Prometheus - expr: string - // Returns only the latest value that Prometheus has scraped for the requested time series - instant?: bool - // Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series - range?: bool - // Execute an additional query to identify interesting raw samples relevant for the given expr - exemplar?: bool - // Specifies which editor is being used to prepare the query. It can be "code" or "builder" - editorMode?: #QueryEditorMode - // Query format to determine how to display data points in panel. It can be "time_series", "table", "heatmap" - format?: #PromQueryFormat - // Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname - legendFormat?: string - // @deprecated Used to specify how many times to divide max data points by. We use max data points under query options - // See https://github.com/grafana/grafana/issues/48081 - intervalFactor?: number - - scope?: { - matchers: string - } - - #QueryEditorMode: "code" | "builder" @cuetsy(kind="enum") - #PromQueryFormat: "time_series" | "table" | "heatmap" @cuetsy(kind="type") - } - }] - lenses: [] - } -} diff --git a/packages/grafana-prometheus/src/dataquery.gen.ts b/public/app/plugins/datasource/prometheus/dataquery.ts similarity index 82% rename from packages/grafana-prometheus/src/dataquery.gen.ts rename to public/app/plugins/datasource/prometheus/dataquery.ts index 3ba622cecff..8609fc78914 100644 --- a/packages/grafana-prometheus/src/dataquery.gen.ts +++ b/public/app/plugins/datasource/prometheus/dataquery.ts @@ -1,13 +1,3 @@ -// 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 enum QueryEditorMode { @@ -15,7 +5,7 @@ export enum QueryEditorMode { Code = 'code', } -export type PromQueryFormat = ('time_series' | 'table' | 'heatmap'); +export type PromQueryFormat = 'time_series' | 'table' | 'heatmap'; export interface Prometheus extends common.DataQuery { /** diff --git a/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryBuilderOptions.tsx b/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryBuilderOptions.tsx index 27beaafb4d8..c6fd8395c89 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryBuilderOptions.tsx +++ b/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryBuilderOptions.tsx @@ -6,7 +6,7 @@ import { EditorField, EditorRow, EditorSwitch } from '@grafana/experimental'; import { AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui'; import { getQueryTypeChangeHandler, getQueryTypeOptions } from '../../components/PromExploreExtraField'; -import { PromQueryFormat } from '../../dataquery.gen'; +import { PromQueryFormat } from '../../dataquery'; import { PromQuery } from '../../types'; import { QueryOptionGroup } from '../shared/QueryOptionGroup'; diff --git a/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryEditorSelector.tsx b/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryEditorSelector.tsx index a0016b986e8..f85090e0cad 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryEditorSelector.tsx +++ b/public/app/plugins/datasource/prometheus/querybuilder/components/PromQueryEditorSelector.tsx @@ -8,7 +8,7 @@ import { reportInteraction } from '@grafana/runtime'; import { Button, ConfirmModal, Space } from '@grafana/ui'; import { PromQueryEditorProps } from '../../components/types'; -import { PromQueryFormat } from '../../dataquery.gen'; +import { PromQueryFormat } from '../../dataquery'; import { PromQuery } from '../../types'; import { QueryPatternsModal } from '../QueryPatternsModal'; import { promQueryEditorExplainKey, useFlag } from '../hooks/useFlag'; diff --git a/public/app/plugins/datasource/prometheus/types.ts b/public/app/plugins/datasource/prometheus/types.ts index 5ddb69d811b..f3c5730b380 100644 --- a/public/app/plugins/datasource/prometheus/types.ts +++ b/public/app/plugins/datasource/prometheus/types.ts @@ -1,7 +1,7 @@ import { DataSourceJsonData } from '@grafana/data'; import { DataQuery } from '@grafana/schema'; -import { Prometheus as GenPromQuery } from './dataquery.gen'; +import { Prometheus as GenPromQuery } from './dataquery'; import { QueryBuilderLabelFilter, QueryEditorMode } from './querybuilder/shared/types'; export interface PromQuery extends GenPromQuery, DataQuery {