Explorar el Código

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
Ryan McKinley hace 6 años
padre
commit
1033f0f905

+ 7 - 0
packages/grafana-ui/src/types/datasource.ts

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

+ 11 - 10
pkg/plugins/datasource_plugin.go

@@ -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"`

+ 5 - 4
public/app/features/dashboard/state/PanelQueryRunner.ts

@@ -108,9 +108,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,
@@ -120,7 +117,7 @@ export class PanelQueryRunner {
       timeInfo,
       interval: '',
       intervalMs: 0,
-      targets: clonedAndFilteredQueries,
+      targets: cloneDeep(queries),
       maxDataPoints: maxDataPoints || widthPixels,
       scopedVars: scopedVars || {},
       cacheTimeout,
@@ -135,6 +132,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) {

+ 1 - 0
public/app/plugins/datasource/cloudwatch/plugin.json

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

+ 1 - 0
public/app/plugins/datasource/graphite/plugin.json

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