mirror of https://github.com/grafana/grafana
Prometheus schematization (#63878)
* Schematize prometheus * revert changes * close response body * Update report.json * Update pkg/tsdb/prometheus/models/query.go Co-authored-by: sam boyer <sdboyer@grafana.com> * Use without pointers * remove unused * Specify query format * Rename * Clean up schema * Update public/app/plugins/datasource/prometheus/dataquery.cue Co-authored-by: Ryan McKinley <ryantxu@gmail.com> * Update pkg/tsdb/prometheus/models/query.go Co-authored-by: Ryan McKinley <ryantxu@gmail.com> * Clean up tests * Update public/app/plugins/datasource/prometheus/dataquery.cue Co-authored-by: sam boyer <sdboyer@grafana.com> * make gen-cue * Add comments * Make linter happy * Remove editormode override * Update --------- Co-authored-by: sam boyer <sdboyer@grafana.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com>pull/64499/head
parent
473013e3f5
commit
68b588b912
@ -0,0 +1,44 @@ |
||||
--- |
||||
keywords: |
||||
- grafana |
||||
- schema |
||||
title: PrometheusDataQuery kind |
||||
--- |
||||
> Both documentation generation and kinds schemas are in active development and subject to change without prior notice. |
||||
|
||||
## PrometheusDataQuery |
||||
|
||||
#### Maturity: [experimental](../../../maturity/#experimental) |
||||
#### Version: 0.0 |
||||
|
||||
|
||||
|
||||
It extends [DataQuery](#dataquery). |
||||
|
||||
| Property | Type | Required | Description | |
||||
|--------------|---------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
||||
| `expr` | string | **Yes** | The actual expression/query that will be evaluated by Prometheus | |
||||
| `refId` | string | **Yes** | *(Inherited from [DataQuery](#dataquery))*<br/>A unique identifier for the query within the list of targets.<br/>In server side expressions, the refId is used as a variable name to identify results.<br/>By default, the UI will assign A->Z; however setting meaningful names may be useful. | |
||||
| `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 | null | |
||||
| `editorMode` | string | No | Possible values are: `code`, `builder`. | |
||||
| `exemplar` | boolean | No | Execute an additional query to identify interesting raw samples relevant for the given expr | |
||||
| `format` | string | No | Possible values are: `time_series`, `table`, `heatmap`. | |
||||
| `hide` | boolean | No | *(Inherited from [DataQuery](#dataquery))*<br/>true if query is disabled (ie should not be returned to the dashboard)<br/>Note this does not always imply that the query should not be executed since<br/>the results from a hidden query may be used as the input to other queries (SSE etc) | |
||||
| `instant` | boolean | No | Returns only the latest value that Prometheus has scraped for the requested time series | |
||||
| `queryType` | string | No | *(Inherited from [DataQuery](#dataquery))*<br/>Specify the query flavor<br/>TODO make this required and give it a default | |
||||
| `range` | boolean | No | Returns a Range vector, comprised of a set of time series containing a range of data points over time for each time series | |
||||
|
||||
### 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 unique identifier for the query within the list of targets.<br/>In server side expressions, the refId is used as a variable name to identify results.<br/>By default, the UI will assign A->Z; however setting meaningful names may be useful. | |
||||
| `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 | null | |
||||
| `hide` | boolean | No | true if query is disabled (ie should not be returned to the dashboard)<br/>Note this does not always imply that the query should not be executed since<br/>the results from a hidden query may be used as the input to other queries (SSE etc) | |
||||
| `queryType` | string | No | Specify the query flavor<br/>TODO make this required and give it a default | |
||||
|
||||
|
||||
@ -0,0 +1,89 @@ |
||||
// 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 EditorMode.
|
||||
const ( |
||||
EditorModeBuilder EditorMode = "builder" |
||||
EditorModeCode EditorMode = "code" |
||||
) |
||||
|
||||
// Defines values for Format.
|
||||
const ( |
||||
FormatHeatmap Format = "heatmap" |
||||
FormatTable Format = "table" |
||||
FormatTimeSeries Format = "time_series" |
||||
) |
||||
|
||||
// Defines values for QueryEditorMode.
|
||||
const ( |
||||
QueryEditorModeBuilder QueryEditorMode = "builder" |
||||
QueryEditorModeCode QueryEditorMode = "code" |
||||
) |
||||
|
||||
// PromQueryFormat defines model for PromQueryFormat.
|
||||
type PromQueryFormat string |
||||
|
||||
// PrometheusDataQuery defines model for PrometheusDataQuery.
|
||||
type PrometheusDataQuery 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"` |
||||
|
||||
// Specifies which editor is being used to prepare the query. It can be "code" or "builder"
|
||||
EditorMode *EditorMode `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"` |
||||
|
||||
// Query format to determine how to display data points in panel. It can be "time_series", "table", "heatmap"
|
||||
Format *Format `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"` |
||||
|
||||
// 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"` |
||||
} |
||||
|
||||
// Specifies which editor is being used to prepare the query. It can be "code" or "builder"
|
||||
type EditorMode string |
||||
|
||||
// Query format to determine how to display data points in panel. It can be "time_series", "table", "heatmap"
|
||||
type Format string |
||||
|
||||
// QueryEditorMode defines model for QueryEditorMode.
|
||||
type QueryEditorMode string |
||||
@ -0,0 +1,55 @@ |
||||
// 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" |
||||
"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: [ |
||||
{ |
||||
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 |
||||
|
||||
#QueryEditorMode: "code" | "builder" @cuetsy(kind="enum") |
||||
#PromQueryFormat: "time_series" | "table" | "heatmap" @cuetsy(kind="type") |
||||
}, |
||||
] |
||||
}, |
||||
] |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@ |
||||
// 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 enum QueryEditorMode { |
||||
Builder = 'builder', |
||||
Code = 'code', |
||||
} |
||||
|
||||
export type PromQueryFormat = ('time_series' | 'table' | 'heatmap'); |
||||
|
||||
export interface Prometheus 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; |
||||
/** |
||||
* 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; |
||||
} |
||||
Loading…
Reference in new issue