diff --git a/public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts b/public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts index f314b6b9d31..5b7c5fd2bf8 100644 --- a/public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts +++ b/public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts @@ -11,7 +11,8 @@ export default class StackdriverMetricFindQuery { case 'metricTypes': return this.handleMetricTypesQueryType(query); case 'metricLabels': - return this.handleMetricLabelsQueryType(query); + case 'resourceLabels': + return this.handleLabelQueryType(query); default: return []; } @@ -39,17 +40,19 @@ export default class StackdriverMetricFindQuery { })); } - async handleMetricLabelsQueryType({ metricType, metricLabelKey }) { - if (!metricType || !metricLabelKey) { + async handleLabelQueryType({ type, metricType, metricLabelKey, resourceLabelKey }) { + if (!metricType) { return []; } - const refId = 'handleMetricLabelsQueryType'; + const key = type === 'metricLabels' ? metricLabelKey : resourceLabelKey; + const refId = 'handleLabelsQueryType'; const response = await this.datasource.getLabels(metricType, refId); - return has(response, `meta.metricLabels.${metricLabelKey}`) - ? response.meta.metricLabels[metricLabelKey].map(s => ({ - text: s, - expandable: true, - })) - : []; + if (!has(response, `meta.${type}.${key}`)) { + return []; + } + return response.meta[type][key].map(s => ({ + text: s, + expandable: true, + })); } } diff --git a/public/app/plugins/datasource/stackdriver/components/MetricLabelKeySelector.tsx b/public/app/plugins/datasource/stackdriver/components/SimpleDropdown.tsx similarity index 56% rename from public/app/plugins/datasource/stackdriver/components/MetricLabelKeySelector.tsx rename to public/app/plugins/datasource/stackdriver/components/SimpleDropdown.tsx index 72d1e10e330..bbd99a79488 100644 --- a/public/app/plugins/datasource/stackdriver/components/MetricLabelKeySelector.tsx +++ b/public/app/plugins/datasource/stackdriver/components/SimpleDropdown.tsx @@ -1,18 +1,19 @@ import React, { SFC } from 'react'; interface Props { - onMetricLabelKeyChange: any; - metricLabels: any; - metricLabelKey: string; + onValueChange: any; + options: any; + value: string; + label: string; } -const MetricLabelKeySelector: SFC = props => { +const SimpleDropdown: SFC = props => { return (
- Metric Labels + {props.label}
- + {props.options.map((qt, i) => ( @@ -23,4 +24,4 @@ const MetricLabelKeySelector: SFC = props => { ); }; -export default MetricLabelKeySelector; +export default SimpleDropdown; diff --git a/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx b/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx index a9e1cbc9fc2..c4c7487e029 100644 --- a/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx +++ b/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx @@ -1,7 +1,7 @@ import React, { PureComponent } from 'react'; import ServiceSelector from './ServiceSelector'; import MetricTypeSelector from './MetricTypeSelector'; -import MetricLabelKeySelector from './MetricLabelKeySelector'; +import SimpleDropdown from './SimpleDropdown'; import { TemplateQueryProps } from 'app/types/plugins'; import defaultsDeep from 'lodash/defaultsDeep'; import has from 'lodash/has'; @@ -17,13 +17,16 @@ export class StackdriverTemplateQueryComponent extends PureComponent ); case 'metricLabels': + case 'resourceLabels': + const dropdown = + queryType === 'resourceLabels' ? ( + + ) : ( + + ); return ( @@ -85,11 +119,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent - + {dropdown} ); default: