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
This commit is contained in:
Ryan McKinley
2019-05-21 04:46:19 -07:00
committed by Torkel Ödegaard
parent 73e4178aef
commit 1033f0f905
5 changed files with 25 additions and 14 deletions

View File

@ -85,6 +85,13 @@ export interface DataSourcePluginMeta extends PluginMeta {
queryOptions?: PluginMetaQueryOptions; queryOptions?: PluginMetaQueryOptions;
sort?: number; sort?: number;
supportsStreaming?: boolean; supportsStreaming?: boolean;
/**
* 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 { interface PluginMetaQueryOptions {

View File

@ -18,16 +18,17 @@ import (
// DataSourcePlugin contains all metadata about a datasource plugin // DataSourcePlugin contains all metadata about a datasource plugin
type DataSourcePlugin struct { type DataSourcePlugin struct {
FrontendPluginBase FrontendPluginBase
Annotations bool `json:"annotations"` Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"` Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"` Alerting bool `json:"alerting"`
Explore bool `json:"explore"` Explore bool `json:"explore"`
Table bool `json:"tables"` Table bool `json:"tables"`
Logs bool `json:"logs"` HiddenQueries bool `json:"hiddenQueries"`
QueryOptions map[string]bool `json:"queryOptions,omitempty"` Logs bool `json:"logs"`
BuiltIn bool `json:"builtIn,omitempty"` QueryOptions map[string]bool `json:"queryOptions,omitempty"`
Mixed bool `json:"mixed,omitempty"` BuiltIn bool `json:"builtIn,omitempty"`
Routes []*AppPluginRoute `json:"routes"` Mixed bool `json:"mixed,omitempty"`
Routes []*AppPluginRoute `json:"routes"`
Backend bool `json:"backend,omitempty"` Backend bool `json:"backend,omitempty"`
Executable string `json:"executable,omitempty"` Executable string `json:"executable,omitempty"`

View File

@ -108,9 +108,6 @@ export class PanelQueryRunner {
delayStateNotification, delayStateNotification,
} = options; } = options;
// filter out hidden queries & deep clone them
const clonedAndFilteredQueries = cloneDeep(queries.filter(q => !q.hide));
const request: DataQueryRequest = { const request: DataQueryRequest = {
requestId: getNextRequestId(), requestId: getNextRequestId(),
timezone, timezone,
@ -120,7 +117,7 @@ export class PanelQueryRunner {
timeInfo, timeInfo,
interval: '', interval: '',
intervalMs: 0, intervalMs: 0,
targets: clonedAndFilteredQueries, targets: cloneDeep(queries),
maxDataPoints: maxDataPoints || widthPixels, maxDataPoints: maxDataPoints || widthPixels,
scopedVars: scopedVars || {}, scopedVars: scopedVars || {},
cacheTimeout, cacheTimeout,
@ -135,6 +132,10 @@ export class PanelQueryRunner {
try { try {
const ds = await getDataSource(datasource, request.scopedVars); 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 // Attach the datasource name to each query
request.targets = request.targets.map(query => { request.targets = request.targets.map(query => {
if (!query.datasource) { if (!query.datasource) {

View File

@ -4,6 +4,7 @@
"id": "cloudwatch", "id": "cloudwatch",
"category": "cloud", "category": "cloud",
"hiddenQueries": true,
"metrics": true, "metrics": true,
"alerting": true, "alerting": true,
"annotations": true, "annotations": true,

View File

@ -6,6 +6,7 @@
"includes": [{ "type": "dashboard", "name": "Graphite Carbon Metrics", "path": "dashboards/carbon_metrics.json" }], "includes": [{ "type": "dashboard", "name": "Graphite Carbon Metrics", "path": "dashboards/carbon_metrics.json" }],
"hiddenQueries": true,
"metrics": true, "metrics": true,
"alerting": true, "alerting": true,
"annotations": true, "annotations": true,