mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Implement schema for query (#62147)
* Elasticsearch: Implement schema for query * Comment out types I am not sure how to do * Manually fix typing for PipelineMetricAggregationWithMultipleBucketPaths and BasePipelineMetricAggregation * Import types to types.ts to have single source of truth * Cleanup, reorder * Remove unnecesary Schema. * Fix test * Refactor
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
---
|
||||
keywords:
|
||||
- grafana
|
||||
- schema
|
||||
title: ElasticsearchDataQuery kind
|
||||
---
|
||||
> Both documentation generation and kinds schemas are in active development and subject to change without prior notice.
|
||||
|
||||
# ElasticsearchDataQuery kind
|
||||
|
||||
## Maturity: merged
|
||||
## Version: 0.0
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Required | Description |
|
||||
|--------------|-------------------------------------------|----------|-------------|
|
||||
| `alias` | string | No | |
|
||||
| `bucketAggs` | [BucketAggregation](#bucketaggregation)[] | No | |
|
||||
| `metrics` | [MetricAggregation](#metricaggregation)[] | No | |
|
||||
| `query` | string | No | |
|
||||
| `timeField` | string | No | |
|
||||
|
||||
## BucketAggregation
|
||||
|
||||
| Property | Type | Required | Description |
|
||||
|----------|------|----------|-------------|
|
||||
|
||||
## MetricAggregation
|
||||
|
||||
| Property | Type | Required | Description |
|
||||
|----------|------|----------|-------------|
|
||||
|
||||
|
||||
@@ -426,7 +426,9 @@
|
||||
},
|
||||
"elasticsearchdataquery": {
|
||||
"category": "composable",
|
||||
"codeowners": [],
|
||||
"codeowners": [
|
||||
"grafana/observability-logs"
|
||||
],
|
||||
"currentVersion": [
|
||||
0,
|
||||
0
|
||||
@@ -434,13 +436,13 @@
|
||||
"grafanaMaturityCount": 0,
|
||||
"lineageIsGroup": false,
|
||||
"links": {
|
||||
"docs": "n/a",
|
||||
"go": "n/a",
|
||||
"schema": "n/a",
|
||||
"ts": "n/a"
|
||||
"docs": "https://grafana.com/docs/grafana/next/developers/kinds/composable/elasticsearchdataquery/schema-reference",
|
||||
"go": "https://github.com/grafana/grafana/tree/main/pkg/tsdb/elasticsearch/kinds/dataquery/types_dataquery_gen.go",
|
||||
"schema": "https://github.com/grafana/grafana/tree/main/public/app/plugins/datasource/elasticsearch/dataquery.cue",
|
||||
"ts": "https://github.com/grafana/grafana/tree/main/public/app/plugins/datasource/elasticsearch/dataquery.gen.ts"
|
||||
},
|
||||
"machineName": "elasticsearchdataquery",
|
||||
"maturity": "planned",
|
||||
"maturity": "merged",
|
||||
"name": "ElasticsearchDataQuery",
|
||||
"pluralMachineName": "elasticsearchdataquerys",
|
||||
"pluralName": "ElasticsearchDataQuerys",
|
||||
@@ -2002,13 +2004,14 @@
|
||||
"name": "merged",
|
||||
"items": [
|
||||
"alertgroupspanelcfg",
|
||||
"elasticsearchdataquery",
|
||||
"playlist",
|
||||
"preferences",
|
||||
"publicdashboard",
|
||||
"serviceaccount",
|
||||
"team"
|
||||
],
|
||||
"count": 6
|
||||
"count": 7
|
||||
},
|
||||
"planned": {
|
||||
"name": "planned",
|
||||
@@ -2025,7 +2028,6 @@
|
||||
"dashboarddatasourcecfg",
|
||||
"datasource",
|
||||
"debugpanelcfg",
|
||||
"elasticsearchdataquery",
|
||||
"elasticsearchdatasourcecfg",
|
||||
"flamegraphpanelcfg",
|
||||
"folder",
|
||||
@@ -2068,7 +2070,7 @@
|
||||
"zipkindataquery",
|
||||
"zipkindatasourcecfg"
|
||||
],
|
||||
"count": 54
|
||||
"count": 53
|
||||
},
|
||||
"stable": {
|
||||
"name": "stable",
|
||||
|
||||
1290
pkg/tsdb/elasticsearch/kinds/dataquery/types_dataquery_gen.go
Normal file
1290
pkg/tsdb/elasticsearch/kinds/dataquery/types_dataquery_gen.go
Normal file
File diff suppressed because it is too large
Load Diff
431
public/app/plugins/datasource/elasticsearch/dataquery.cue
Normal file
431
public/app/plugins/datasource/elasticsearch/dataquery.cue
Normal file
@@ -0,0 +1,431 @@
|
||||
// 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: "merged"
|
||||
|
||||
lineage: {
|
||||
seqs: [
|
||||
{
|
||||
schemas: [
|
||||
{
|
||||
common.DataQuery
|
||||
|
||||
alias?: string
|
||||
query?: string
|
||||
timeField?: string
|
||||
bucketAggs?: [...#BucketAggregation]
|
||||
metrics?: [...#MetricAggregation]
|
||||
|
||||
#BucketAggregation: #DateHistogram | #Histogram | #Terms | #Filters | #GeoHashGrid | #Nested @cuetsy(kind="type")
|
||||
#MetricAggregation: #Count | #PipelineMetricAggregation | #MetricAggregationWithSettings @cuetsy(kind="type")
|
||||
|
||||
#BucketAggregationType: "terms" | "filters" | "geohash_grid" | "date_histogram" | "histogram" | "nested" @cuetsy(kind="type")
|
||||
|
||||
#BaseBucketAggregation: {
|
||||
id: string
|
||||
type: #BucketAggregationType
|
||||
settings?: {...}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#BucketAggregationWithField: {
|
||||
#BaseBucketAggregation
|
||||
field?: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#DateHistogram: {
|
||||
#BucketAggregationWithField
|
||||
type: #BucketAggregationType & "date_histogram"
|
||||
settings?: #DateHistogramSettings
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#DateHistogramSettings: {
|
||||
interval?: string
|
||||
min_doc_count?: string
|
||||
trimEdges?: string
|
||||
offset?: string
|
||||
timeZone?: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Histogram: {
|
||||
#BucketAggregationWithField
|
||||
type: #BucketAggregationType & "histogram"
|
||||
settings?: #HistogramSettings
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#HistogramSettings: {
|
||||
interval?: string
|
||||
min_doc_count?: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#TermsOrder: "desc" | "asc" @cuetsy(kind="type")
|
||||
|
||||
#Nested: {
|
||||
#BucketAggregationWithField
|
||||
type: #BucketAggregationType & "nested"
|
||||
settings?: {}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Terms: {
|
||||
#BucketAggregationWithField
|
||||
type: #BucketAggregationType & "terms"
|
||||
settings?: #TermsSettings
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#TermsSettings: {
|
||||
order?: #TermsOrder
|
||||
size?: string
|
||||
min_doc_count?: string
|
||||
orderBy?: string
|
||||
missing?: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Filters: {
|
||||
#BaseBucketAggregation
|
||||
type: #BucketAggregationType & "filters"
|
||||
settings?: #FiltersSettings
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Filter: {
|
||||
query: string
|
||||
label: string
|
||||
} @cuetsy(kind="type")
|
||||
|
||||
#FiltersSettings: {
|
||||
filters?: [...#Filter]
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#GeoHashGrid: {
|
||||
#BucketAggregationWithField
|
||||
type: #BucketAggregationType & "geohash_grid"
|
||||
settings?: #GeoHashGridSettings
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#GeoHashGridSettings: {
|
||||
precision?: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#PipelineMetricAggregationType: "moving_avg" | "moving_fn" | "derivative" | "serial_diff" | "cumulative_sum" | "bucket_script" @cuetsy(kind="type")
|
||||
#MetricAggregationType: "count" | "avg" | "sum" | "min" | "max" | "extended_stats" | "percentiles" | "cardinality" | "raw_document" | "raw_data" | "logs" | "rate" | "top_metrics" | #PipelineMetricAggregationType @cuetsy(kind="type")
|
||||
|
||||
#BaseMetricAggregation: {
|
||||
type: #MetricAggregationType
|
||||
id: string
|
||||
hide?: bool
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#PipelineVariable: {
|
||||
name: string
|
||||
pipelineAgg: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MetricAggregationWithField: {
|
||||
#BaseMetricAggregation
|
||||
field?: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MetricAggregationWithMissingSupport: {
|
||||
#BaseMetricAggregation
|
||||
settings?: {
|
||||
missing?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#InlineScript: string | {inline?: string} @cuetsy(kind="type")
|
||||
|
||||
#MetricAggregationWithInlineScript: {
|
||||
#BaseMetricAggregation
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Count: {
|
||||
#BaseMetricAggregation
|
||||
type: #MetricAggregationType & "count"
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Average: {
|
||||
#MetricAggregationWithField
|
||||
#MetricAggregationWithMissingSupport
|
||||
#MetricAggregationWithInlineScript
|
||||
type: #MetricAggregationType & "avg"
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
missing?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Sum: {
|
||||
#MetricAggregationWithField
|
||||
#MetricAggregationWithInlineScript
|
||||
type: #MetricAggregationType & "sum"
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
missing?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Max: {
|
||||
#MetricAggregationWithField
|
||||
#MetricAggregationWithInlineScript
|
||||
type: #MetricAggregationType & "max"
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
missing?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Min: {
|
||||
#MetricAggregationWithField
|
||||
#MetricAggregationWithInlineScript
|
||||
type: #MetricAggregationType & "min"
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
missing?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#ExtendedStatMetaType: "avg" | "min" | "max" | "sum" | "count" | "std_deviation" | "std_deviation_bounds_upper" | "std_deviation_bounds_lower" @cuetsy(kind="type")
|
||||
|
||||
#ExtendedStat: {
|
||||
label: string
|
||||
value: #ExtendedStatMetaType
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#ExtendedStats: {
|
||||
#MetricAggregationWithField
|
||||
#MetricAggregationWithInlineScript
|
||||
type: #MetricAggregationType & "extended_stats"
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
missing?: string
|
||||
sigma?: string
|
||||
}
|
||||
meta?: [#ExtendedStatMetaType]: bool
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Percentiles: {
|
||||
#MetricAggregationWithField
|
||||
#MetricAggregationWithInlineScript
|
||||
type: #MetricAggregationType & "percentiles"
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
missing?: string
|
||||
percents?: [...string]
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#UniqueCount: {
|
||||
#MetricAggregationWithField
|
||||
type: #MetricAggregationType & "cardinality"
|
||||
settings?: {
|
||||
precision_threshold?: string
|
||||
missing?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#RawDocument: {
|
||||
#BaseMetricAggregation
|
||||
type: #MetricAggregationType & "raw_document"
|
||||
settings?: {
|
||||
size?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#RawData: {
|
||||
#BaseMetricAggregation
|
||||
type: #MetricAggregationType & "raw_data"
|
||||
settings?: {
|
||||
size?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Logs: {
|
||||
#BaseMetricAggregation
|
||||
type: #MetricAggregationType & "logs"
|
||||
settings?: {
|
||||
limit?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Rate: {
|
||||
#MetricAggregationWithField
|
||||
type: #MetricAggregationType & "rate"
|
||||
settings?: {
|
||||
unit?: string
|
||||
mode?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#BasePipelineMetricAggregation: {
|
||||
#MetricAggregationWithField
|
||||
|
||||
//TODO: Type is temporarily commented out as it causes a type error in the generated code. In the meantime, we decided to manually extend the type in types.ts.
|
||||
//type: #PipelineMetricAggregationType
|
||||
pipelineAgg?: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#PipelineMetricAggregationWithMultipleBucketPaths: {
|
||||
#BaseMetricAggregation
|
||||
|
||||
//TODO: Type is temporarily commented out as it causes a type error in the generated code. In the meantime, we decided to manually extend the type in types.ts.
|
||||
//type: #PipelineMetricAggregationType
|
||||
pipelineVariables?: [...#PipelineVariable]
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MovingAverageModel: "simple" | "linear" | "ewma" | "holt" | "holt_winters" @cuetsy(kind="type")
|
||||
|
||||
#MovingAverageModelOption: {
|
||||
label: string
|
||||
value: #MovingAverageModel
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#BaseMovingAverageModelSettings: {
|
||||
model: #MovingAverageModel
|
||||
window: string
|
||||
predict: string
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MovingAverageSimpleModelSettings: {
|
||||
#BaseMovingAverageModelSettings
|
||||
model: #MovingAverageModel & "simple"
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MovingAverageLinearModelSettings: {
|
||||
#BaseMovingAverageModelSettings
|
||||
model: #MovingAverageModel & "linear"
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MovingAverageEWMAModelSettings: {
|
||||
#BaseMovingAverageModelSettings
|
||||
model: #MovingAverageModel & "ewma"
|
||||
settings?: {
|
||||
alpha?: string
|
||||
}
|
||||
minimize: bool
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MovingAverageHoltModelSettings: {
|
||||
#BaseMovingAverageModelSettings
|
||||
model: #MovingAverageModel & "holt"
|
||||
settings: {
|
||||
alpha?: string
|
||||
beta?: string
|
||||
}
|
||||
minimize: bool
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MovingAverageHoltWintersModelSettings: {
|
||||
#BaseMovingAverageModelSettings
|
||||
model: #MovingAverageModel & "holt_winters"
|
||||
settings: {
|
||||
alpha?: string
|
||||
beta?: string
|
||||
gamma?: string
|
||||
period?: string
|
||||
pad?: bool
|
||||
}
|
||||
minimize: bool
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
// #MovingAverageModelSettings Not sure how to do this one:
|
||||
// export type MovingAverageModelSettings<T extends MovingAverageModel = MovingAverageModel> = Partial<
|
||||
// Extract<
|
||||
// | MovingAverageSimpleModelSettings
|
||||
// | MovingAverageLinearModelSettings
|
||||
// | MovingAverageEWMAModelSettings
|
||||
// | MovingAverageHoltModelSettings
|
||||
// | MovingAverageHoltWintersModelSettings,
|
||||
// { model: T }
|
||||
// >
|
||||
// >;
|
||||
|
||||
// #MovingAverage's settings are overridden in types.ts
|
||||
#MovingAverage: {
|
||||
#BasePipelineMetricAggregation
|
||||
type: "moving_avg"
|
||||
settings?: {...}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#MovingFunction: {
|
||||
#BasePipelineMetricAggregation
|
||||
type: #PipelineMetricAggregationType & "moving_fn"
|
||||
settings?: {
|
||||
window?: string
|
||||
script?: #InlineScript
|
||||
shift?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#Derivative: {
|
||||
#BasePipelineMetricAggregation
|
||||
type: #PipelineMetricAggregationType & "derivative"
|
||||
settings?: {
|
||||
unit?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#SerialDiff: {
|
||||
#BasePipelineMetricAggregation
|
||||
type: #PipelineMetricAggregationType & "serial_diff"
|
||||
settings?: {
|
||||
lag?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#CumulativeSum: {
|
||||
#BasePipelineMetricAggregation
|
||||
type: #PipelineMetricAggregationType & "cumulative_sum"
|
||||
settings?: {
|
||||
format?: string
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#BucketScript: {
|
||||
#PipelineMetricAggregationWithMultipleBucketPaths
|
||||
type: #PipelineMetricAggregationType & "bucket_script"
|
||||
settings?: {
|
||||
script?: #InlineScript
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#TopMetrics: {
|
||||
#BaseMetricAggregation
|
||||
type: #MetricAggregationType & "top_metrics"
|
||||
settings?: {
|
||||
order?: string
|
||||
orderBy?: string
|
||||
metrics?: [...string]
|
||||
}
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
#PipelineMetricAggregation: #MovingAverage | #Derivative | #CumulativeSum | #BucketScript @cuetsy(kind="type")
|
||||
#MetricAggregationWithSettings: #BucketScript | #CumulativeSum | #Derivative | #SerialDiff | #RawData | #RawDocument | #UniqueCount | #Percentiles | #ExtendedStats | #Min | #Max | #Sum | #Average | #MovingAverage | #MovingFunction | #Logs | #Rate | #TopMetrics @cuetsy(kind="type")
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
374
public/app/plugins/datasource/elasticsearch/dataquery.gen.ts
Normal file
374
public/app/plugins/datasource/elasticsearch/dataquery.gen.ts
Normal file
@@ -0,0 +1,374 @@
|
||||
// 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 BucketAggregation = (DateHistogram | Histogram | Terms | Filters | GeoHashGrid | Nested);
|
||||
|
||||
export type MetricAggregation = (Count | PipelineMetricAggregation | MetricAggregationWithSettings);
|
||||
|
||||
export type BucketAggregationType = ('terms' | 'filters' | 'geohash_grid' | 'date_histogram' | 'histogram' | 'nested');
|
||||
|
||||
export interface BaseBucketAggregation {
|
||||
id: string;
|
||||
settings?: Record<string, unknown>;
|
||||
type: BucketAggregationType;
|
||||
}
|
||||
|
||||
export interface BucketAggregationWithField extends BaseBucketAggregation {
|
||||
field?: string;
|
||||
}
|
||||
|
||||
export interface DateHistogram extends BucketAggregationWithField {
|
||||
type: 'date_histogram';
|
||||
}
|
||||
|
||||
export interface DateHistogramSettings {
|
||||
interval?: string;
|
||||
min_doc_count?: string;
|
||||
offset?: string;
|
||||
timeZone?: string;
|
||||
trimEdges?: string;
|
||||
}
|
||||
|
||||
export interface Histogram extends BucketAggregationWithField {
|
||||
type: 'histogram';
|
||||
}
|
||||
|
||||
export interface HistogramSettings {
|
||||
interval?: string;
|
||||
min_doc_count?: string;
|
||||
}
|
||||
|
||||
export type TermsOrder = ('desc' | 'asc');
|
||||
|
||||
export interface Nested extends BucketAggregationWithField {
|
||||
type: 'nested';
|
||||
}
|
||||
|
||||
export interface Terms extends BucketAggregationWithField {
|
||||
type: 'terms';
|
||||
}
|
||||
|
||||
export interface TermsSettings {
|
||||
min_doc_count?: string;
|
||||
missing?: string;
|
||||
order?: TermsOrder;
|
||||
orderBy?: string;
|
||||
size?: string;
|
||||
}
|
||||
|
||||
export interface Filters extends BaseBucketAggregation {
|
||||
type: 'filters';
|
||||
}
|
||||
|
||||
export type Filter = {
|
||||
query: string,
|
||||
label: string,
|
||||
};
|
||||
|
||||
export interface FiltersSettings {
|
||||
filters?: Array<Filter>;
|
||||
}
|
||||
|
||||
export const defaultFiltersSettings: Partial<FiltersSettings> = {
|
||||
filters: [],
|
||||
};
|
||||
|
||||
export interface GeoHashGrid extends BucketAggregationWithField {
|
||||
type: 'geohash_grid';
|
||||
}
|
||||
|
||||
export interface GeoHashGridSettings {
|
||||
precision?: string;
|
||||
}
|
||||
|
||||
export type PipelineMetricAggregationType = ('moving_avg' | 'moving_fn' | 'derivative' | 'serial_diff' | 'cumulative_sum' | 'bucket_script');
|
||||
|
||||
export type MetricAggregationType = ('count' | 'avg' | 'sum' | 'min' | 'max' | 'extended_stats' | 'percentiles' | 'cardinality' | 'raw_document' | 'raw_data' | 'logs' | 'rate' | 'top_metrics' | PipelineMetricAggregationType);
|
||||
|
||||
export interface BaseMetricAggregation {
|
||||
hide?: boolean;
|
||||
id: string;
|
||||
type: MetricAggregationType;
|
||||
}
|
||||
|
||||
export interface PipelineVariable {
|
||||
name: string;
|
||||
pipelineAgg: string;
|
||||
}
|
||||
|
||||
export interface MetricAggregationWithField extends BaseMetricAggregation {
|
||||
field?: string;
|
||||
}
|
||||
|
||||
export interface MetricAggregationWithMissingSupport extends BaseMetricAggregation {
|
||||
settings?: {
|
||||
missing?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type InlineScript = (string | {
|
||||
inline?: string
|
||||
});
|
||||
|
||||
export interface MetricAggregationWithInlineScript extends BaseMetricAggregation {
|
||||
settings?: {
|
||||
script?: InlineScript;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Count extends BaseMetricAggregation {
|
||||
type: 'count';
|
||||
}
|
||||
|
||||
export interface Average extends MetricAggregationWithField, MetricAggregationWithMissingSupport, MetricAggregationWithInlineScript {
|
||||
field?: string;
|
||||
settings?: {
|
||||
script?: (InlineScript | InlineScript);
|
||||
missing?: string;
|
||||
};
|
||||
type: 'avg';
|
||||
}
|
||||
|
||||
export interface Sum extends MetricAggregationWithField, MetricAggregationWithInlineScript {
|
||||
field?: string;
|
||||
settings?: {
|
||||
script?: (InlineScript | InlineScript);
|
||||
missing?: string;
|
||||
};
|
||||
type: 'sum';
|
||||
}
|
||||
|
||||
export interface Max extends MetricAggregationWithField, MetricAggregationWithInlineScript {
|
||||
field?: string;
|
||||
settings?: {
|
||||
script?: (InlineScript | InlineScript);
|
||||
missing?: string;
|
||||
};
|
||||
type: 'max';
|
||||
}
|
||||
|
||||
export interface Min extends MetricAggregationWithField, MetricAggregationWithInlineScript {
|
||||
field?: string;
|
||||
settings?: {
|
||||
script?: (InlineScript | InlineScript);
|
||||
missing?: string;
|
||||
};
|
||||
type: 'min';
|
||||
}
|
||||
|
||||
export type ExtendedStatMetaType = ('avg' | 'min' | 'max' | 'sum' | 'count' | 'std_deviation' | 'std_deviation_bounds_upper' | 'std_deviation_bounds_lower');
|
||||
|
||||
export interface ExtendedStat {
|
||||
label: string;
|
||||
value: ExtendedStatMetaType;
|
||||
}
|
||||
|
||||
export interface ExtendedStats extends MetricAggregationWithField, MetricAggregationWithInlineScript {
|
||||
field?: string;
|
||||
meta?: Record<string, unknown>;
|
||||
settings?: {
|
||||
script?: (InlineScript | InlineScript);
|
||||
missing?: string;
|
||||
sigma?: string;
|
||||
};
|
||||
type: 'extended_stats';
|
||||
}
|
||||
|
||||
export interface Percentiles extends MetricAggregationWithField, MetricAggregationWithInlineScript {
|
||||
field?: string;
|
||||
settings?: {
|
||||
script?: (InlineScript | InlineScript);
|
||||
missing?: string;
|
||||
percents?: Array<string>;
|
||||
};
|
||||
type: 'percentiles';
|
||||
}
|
||||
|
||||
export interface UniqueCount extends MetricAggregationWithField {
|
||||
settings?: {
|
||||
precision_threshold?: string;
|
||||
missing?: string;
|
||||
};
|
||||
type: 'cardinality';
|
||||
}
|
||||
|
||||
export interface RawDocument extends BaseMetricAggregation {
|
||||
settings?: {
|
||||
size?: string;
|
||||
};
|
||||
type: 'raw_document';
|
||||
}
|
||||
|
||||
export interface RawData extends BaseMetricAggregation {
|
||||
settings?: {
|
||||
size?: string;
|
||||
};
|
||||
type: 'raw_data';
|
||||
}
|
||||
|
||||
export interface Logs extends BaseMetricAggregation {
|
||||
settings?: {
|
||||
limit?: string;
|
||||
};
|
||||
type: 'logs';
|
||||
}
|
||||
|
||||
export interface Rate extends MetricAggregationWithField {
|
||||
settings?: {
|
||||
unit?: string;
|
||||
mode?: string;
|
||||
};
|
||||
type: 'rate';
|
||||
}
|
||||
|
||||
export interface BasePipelineMetricAggregation extends MetricAggregationWithField {
|
||||
/**
|
||||
* TODO: Type is temporarily commented out as it causes a type error in the generated code. In the meantime, we decided to manually extend the type in types.ts.
|
||||
* type: #PipelineMetricAggregationType
|
||||
*/
|
||||
pipelineAgg?: string;
|
||||
}
|
||||
|
||||
export interface PipelineMetricAggregationWithMultipleBucketPaths extends BaseMetricAggregation {
|
||||
/**
|
||||
* TODO: Type is temporarily commented out as it causes a type error in the generated code. In the meantime, we decided to manually extend the type in types.ts.
|
||||
* type: #PipelineMetricAggregationType
|
||||
*/
|
||||
pipelineVariables?: Array<PipelineVariable>;
|
||||
}
|
||||
|
||||
export const defaultPipelineMetricAggregationWithMultipleBucketPaths: Partial<PipelineMetricAggregationWithMultipleBucketPaths> = {
|
||||
pipelineVariables: [],
|
||||
};
|
||||
|
||||
export type MovingAverageModel = ('simple' | 'linear' | 'ewma' | 'holt' | 'holt_winters');
|
||||
|
||||
export interface MovingAverageModelOption {
|
||||
label: string;
|
||||
value: MovingAverageModel;
|
||||
}
|
||||
|
||||
export interface BaseMovingAverageModelSettings {
|
||||
model: MovingAverageModel;
|
||||
predict: string;
|
||||
window: string;
|
||||
}
|
||||
|
||||
export interface MovingAverageSimpleModelSettings extends BaseMovingAverageModelSettings {
|
||||
model: 'simple';
|
||||
}
|
||||
|
||||
export interface MovingAverageLinearModelSettings extends BaseMovingAverageModelSettings {
|
||||
model: 'linear';
|
||||
}
|
||||
|
||||
export interface MovingAverageEWMAModelSettings extends BaseMovingAverageModelSettings {
|
||||
minimize: boolean;
|
||||
model: 'ewma';
|
||||
settings?: {
|
||||
alpha?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MovingAverageHoltModelSettings extends BaseMovingAverageModelSettings {
|
||||
minimize: boolean;
|
||||
model: 'holt';
|
||||
settings: {
|
||||
alpha?: string;
|
||||
beta?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MovingAverageHoltWintersModelSettings extends BaseMovingAverageModelSettings {
|
||||
minimize: boolean;
|
||||
model: 'holt_winters';
|
||||
settings: {
|
||||
alpha?: string;
|
||||
beta?: string;
|
||||
gamma?: string;
|
||||
period?: string;
|
||||
pad?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* #MovingAverage's settings are overridden in types.ts
|
||||
*/
|
||||
export interface MovingAverage extends BasePipelineMetricAggregation {
|
||||
settings?: Record<string, unknown>;
|
||||
type: 'moving_avg';
|
||||
}
|
||||
|
||||
export interface MovingFunction extends BasePipelineMetricAggregation {
|
||||
settings?: {
|
||||
window?: string;
|
||||
script?: InlineScript;
|
||||
shift?: string;
|
||||
};
|
||||
type: 'moving_fn';
|
||||
}
|
||||
|
||||
export interface Derivative extends BasePipelineMetricAggregation {
|
||||
settings?: {
|
||||
unit?: string;
|
||||
};
|
||||
type: 'derivative';
|
||||
}
|
||||
|
||||
export interface SerialDiff extends BasePipelineMetricAggregation {
|
||||
settings?: {
|
||||
lag?: string;
|
||||
};
|
||||
type: 'serial_diff';
|
||||
}
|
||||
|
||||
export interface CumulativeSum extends BasePipelineMetricAggregation {
|
||||
settings?: {
|
||||
format?: string;
|
||||
};
|
||||
type: 'cumulative_sum';
|
||||
}
|
||||
|
||||
export interface BucketScript extends PipelineMetricAggregationWithMultipleBucketPaths {
|
||||
settings?: {
|
||||
script?: InlineScript;
|
||||
};
|
||||
type: 'bucket_script';
|
||||
}
|
||||
|
||||
export interface TopMetrics extends BaseMetricAggregation {
|
||||
settings?: {
|
||||
order?: string;
|
||||
orderBy?: string;
|
||||
metrics?: Array<string>;
|
||||
};
|
||||
type: 'top_metrics';
|
||||
}
|
||||
|
||||
export type PipelineMetricAggregation = (MovingAverage | Derivative | CumulativeSum | BucketScript);
|
||||
|
||||
export type MetricAggregationWithSettings = (BucketScript | CumulativeSum | Derivative | SerialDiff | RawData | RawDocument | UniqueCount | Percentiles | ExtendedStats | Min | Max | Sum | Average | MovingAverage | MovingFunction | Logs | Rate | TopMetrics);
|
||||
|
||||
export interface Elasticsearch extends common.DataQuery {
|
||||
alias?: string;
|
||||
bucketAggs?: Array<BucketAggregation>;
|
||||
metrics?: Array<MetricAggregation>;
|
||||
query?: string;
|
||||
timeField?: string;
|
||||
}
|
||||
|
||||
export const defaultElasticsearch: Partial<Elasticsearch> = {
|
||||
bucketAggs: [],
|
||||
metrics: [],
|
||||
};
|
||||
@@ -314,7 +314,7 @@ describe('ElasticDatasource', () => {
|
||||
database: 'mock-index',
|
||||
});
|
||||
|
||||
const query: DataQueryRequest<ElasticsearchQuery> = {
|
||||
const query = {
|
||||
range: createTimeRange(toUtc([2015, 4, 30, 10]), toUtc([2019, 7, 1, 10])),
|
||||
targets: [
|
||||
{
|
||||
@@ -332,7 +332,7 @@ describe('ElasticDatasource', () => {
|
||||
timeField: '@timestamp',
|
||||
},
|
||||
],
|
||||
} as DataQueryRequest<ElasticsearchQuery>;
|
||||
} as unknown as DataQueryRequest<ElasticsearchQuery>;
|
||||
|
||||
const queryBuilderSpy = jest.spyOn(ds.queryBuilder, 'getLogsQuery');
|
||||
let response: DataQueryResponse = { data: [] };
|
||||
|
||||
@@ -1,13 +1,102 @@
|
||||
import { DataQuery, DataSourceJsonData } from '@grafana/data';
|
||||
import { DataSourceJsonData } from '@grafana/data';
|
||||
|
||||
import {
|
||||
BucketAggregation,
|
||||
BucketAggregationType,
|
||||
} from './components/QueryEditor/BucketAggregationsEditor/aggregations';
|
||||
import {
|
||||
Filter,
|
||||
MetricAggregation,
|
||||
MetricAggregationType,
|
||||
} from './components/QueryEditor/MetricAggregationsEditor/aggregations';
|
||||
MovingAverageEWMAModelSettings,
|
||||
MovingAverageHoltModelSettings,
|
||||
MovingAverageHoltWintersModelSettings,
|
||||
MovingAverageLinearModelSettings,
|
||||
MovingAverageModel,
|
||||
MovingAverageSimpleModelSettings,
|
||||
PipelineMetricAggregationType,
|
||||
TermsOrder,
|
||||
BasePipelineMetricAggregation as SchemaBasePipelineMetricAggregation,
|
||||
PipelineMetricAggregationWithMultipleBucketPaths as SchemaPipelineMetricAggregationWithMultipleBucketPaths,
|
||||
MovingAverage as SchemaMovingAverage,
|
||||
Filters as SchemaFilters,
|
||||
Terms as SchemaTerms,
|
||||
DateHistogram as SchemaDateHistogram,
|
||||
Histogram as SchemaHistogram,
|
||||
GeoHashGrid as SchemaGeoHashGrid,
|
||||
Nested as SchemaNested,
|
||||
} from './dataquery.gen';
|
||||
|
||||
export * from './dataquery.gen';
|
||||
export { Elasticsearch as ElasticsearchQuery } from './dataquery.gen';
|
||||
|
||||
// Start of temporary overrides because of incorrect type generation in dataquery.gen.ts
|
||||
export interface BasePipelineMetricAggregation extends SchemaBasePipelineMetricAggregation {
|
||||
type: PipelineMetricAggregationType;
|
||||
}
|
||||
|
||||
export interface PipelineMetricAggregationWithMultipleBucketPaths
|
||||
extends SchemaPipelineMetricAggregationWithMultipleBucketPaths {
|
||||
type: PipelineMetricAggregationType;
|
||||
}
|
||||
|
||||
export type MovingAverageModelSettings<T extends MovingAverageModel = MovingAverageModel> = Partial<
|
||||
Extract<
|
||||
| MovingAverageSimpleModelSettings
|
||||
| MovingAverageLinearModelSettings
|
||||
| MovingAverageEWMAModelSettings
|
||||
| MovingAverageHoltModelSettings
|
||||
| MovingAverageHoltWintersModelSettings,
|
||||
{ model: T }
|
||||
>
|
||||
>;
|
||||
|
||||
export interface MovingAverage<T extends MovingAverageModel = MovingAverageModel> extends SchemaMovingAverage {
|
||||
settings?: MovingAverageModelSettings<T>;
|
||||
}
|
||||
|
||||
export interface Filters extends SchemaFilters {
|
||||
settings?: {
|
||||
filters?: Filter[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface Terms extends SchemaTerms {
|
||||
settings?: {
|
||||
min_doc_count?: string;
|
||||
missing?: string;
|
||||
order?: TermsOrder;
|
||||
orderBy?: string;
|
||||
size?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface DateHistogram extends SchemaDateHistogram {
|
||||
settings?: {
|
||||
interval?: string;
|
||||
min_doc_count?: string;
|
||||
offset?: string;
|
||||
timeZone?: string;
|
||||
trimEdges?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Histogram extends SchemaHistogram {
|
||||
settings?: {
|
||||
interval?: string;
|
||||
min_doc_count?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface GeoHashGrid extends SchemaGeoHashGrid {
|
||||
settings?: {
|
||||
precision?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface Nested extends SchemaNested {
|
||||
settings?: {};
|
||||
}
|
||||
|
||||
export type BucketAggregation = DateHistogram | Histogram | Terms | Filters | GeoHashGrid | Nested;
|
||||
// End of temporary overrides
|
||||
|
||||
export type Interval = 'Hourly' | 'Daily' | 'Weekly' | 'Monthly' | 'Yearly';
|
||||
|
||||
@@ -65,14 +154,6 @@ export interface ElasticsearchAggregation {
|
||||
hide: boolean;
|
||||
}
|
||||
|
||||
export interface ElasticsearchQuery extends DataQuery {
|
||||
alias?: string;
|
||||
query?: string;
|
||||
bucketAggs?: BucketAggregation[];
|
||||
metrics?: MetricAggregation[];
|
||||
timeField?: string;
|
||||
}
|
||||
|
||||
export interface TermsQuery {
|
||||
query?: string;
|
||||
size?: number;
|
||||
|
||||
Reference in New Issue
Block a user