DataSourceMeta: add an option to get hidden queries (#17124)

* add an option to get hidden queries

* make sure you have meta

* supportsHiddenQueries

* remove spaces

* DataSources: hidden queries flag

(cherry picked from commit 1033f0f905)
This commit is contained in:
Ryan McKinley
2019-05-21 16:46:52 +02:00
committed by Torkel Ödegaard
parent 7e090ea2a6
commit 98f9dbde95
5 changed files with 25 additions and 14 deletions
@@ -80,6 +80,13 @@ export interface DataSourcePluginMeta extends PluginMeta {
mixed?: boolean;
hasQueryHelp?: boolean;
queryOptions?: PluginMetaQueryOptions;
sort?: number;
/**
* By default, hidden queries are not passed to the datasource
* Set this to true in plugin.json to have hidden queries passed to the
* DataSource query method
*/
hiddenQueries?: boolean;
}
interface PluginMetaQueryOptions {
+11 -10
View File
@@ -18,16 +18,17 @@ import (
// DataSourcePlugin contains all metadata about a datasource plugin
type DataSourcePlugin struct {
FrontendPluginBase
Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"`
Explore bool `json:"explore"`
Table bool `json:"tables"`
Logs bool `json:"logs"`
QueryOptions map[string]bool `json:"queryOptions,omitempty"`
BuiltIn bool `json:"builtIn,omitempty"`
Mixed bool `json:"mixed,omitempty"`
Routes []*AppPluginRoute `json:"routes"`
Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"`
Explore bool `json:"explore"`
Table bool `json:"tables"`
HiddenQueries bool `json:"hiddenQueries"`
Logs bool `json:"logs"`
QueryOptions map[string]bool `json:"queryOptions,omitempty"`
BuiltIn bool `json:"builtIn,omitempty"`
Mixed bool `json:"mixed,omitempty"`
Routes []*AppPluginRoute `json:"routes"`
Backend bool `json:"backend,omitempty"`
Executable string `json:"executable,omitempty"`
@@ -97,9 +97,6 @@ export class PanelQueryRunner {
delayStateNotification,
} = options;
// filter out hidden queries & deep clone them
const clonedAndFilteredQueries = cloneDeep(queries.filter(q => !q.hide));
const request: DataQueryRequest = {
requestId: getNextRequestId(),
timezone,
@@ -109,7 +106,7 @@ export class PanelQueryRunner {
timeInfo,
interval: '',
intervalMs: 0,
targets: clonedAndFilteredQueries,
targets: cloneDeep(queries),
maxDataPoints: maxDataPoints || widthPixels,
scopedVars: scopedVars || {},
cacheTimeout,
@@ -124,6 +121,10 @@ export class PanelQueryRunner {
try {
const ds = await getDataSource(datasource, request.scopedVars);
if (ds.meta && !ds.meta.hiddenQueries) {
request.targets = request.targets.filter(q => !q.hide);
}
// Attach the datasource name to each query
request.targets = request.targets.map(query => {
if (!query.datasource) {
@@ -3,6 +3,7 @@
"name": "CloudWatch",
"id": "cloudwatch",
"hiddenQueries": true,
"metrics": true,
"alerting": true,
"annotations": true,
@@ -5,6 +5,7 @@
"includes": [{ "type": "dashboard", "name": "Graphite Carbon Metrics", "path": "dashboards/carbon_metrics.json" }],
"hiddenQueries": true,
"metrics": true,
"alerting": true,
"annotations": true,