Commit b3edad40 by Erik Sundell

stackdriver: add resource types query

parent cb0d563a
......@@ -13,6 +13,8 @@ export default class StackdriverMetricFindQuery {
case 'metricLabels':
case 'resourceLabels':
return this.handleLabelQueryType(query);
case 'resourceTypes':
return this.handleResourceType(query);
default:
return [];
}
......@@ -40,11 +42,23 @@ export default class StackdriverMetricFindQuery {
}));
}
async handleLabelQueryType({ type, metricType, metricLabelKey, resourceLabelKey }) {
getLabelKey({ type, metricLabelKey, resourceLabelKey }) {
switch (type) {
case 'metricLabels':
return metricLabelKey;
break;
case 'resourceLabels':
return resourceLabelKey;
default:
return '';
}
}
async handleLabelQueryType({ type, metricType, metricLabelKey, resourceLabelKey, resourceTypeKey }) {
if (!metricType) {
return [];
}
const key = type === 'metricLabels' ? metricLabelKey : resourceLabelKey;
const key = this.getLabelKey({ type, metricLabelKey, resourceLabelKey });
const refId = 'handleLabelsQueryType';
const response = await this.datasource.getLabels(metricType, refId);
if (!has(response, `meta.${type}.${key}`)) {
......@@ -55,4 +69,20 @@ export default class StackdriverMetricFindQuery {
expandable: true,
}));
}
async handleResourceType({ metricType }) {
if (!metricType) {
return [];
}
try {
const refId = 'handleResourceTypeQueryType';
const response = await this.datasource.getLabels(metricType, refId);
return response.meta.resourceTypes.map(s => ({
text: s,
expandable: true,
}));
} catch (error) {
return [];
}
}
}
......@@ -44,6 +44,10 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this.setState({ metricDescriptors });
}
isLabelQuery(queryType) {
return ['metricLabels', 'resourceLabels'].indexOf(queryType) !== -1;
}
async loadTimeSeriesData() {
const refId = 'StackdriverTemplateQueryComponent';
const response = await this.props.datasource.getLabels(this.state.metricType, refId);
......@@ -52,10 +56,6 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
}
}
isLabelQuery(queryType) {
return ['metricLabels', 'resourceLabels'].indexOf(queryType) !== -1;
}
handleQueryTypeChange(event) {
this.setState({ type: event.target.value });
if (this.isLabelQuery(event.target.value)) {
......@@ -87,6 +87,31 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this.props.onChange(queryModel);
}
switchMetaType(queryType) {
switch (queryType) {
case 'resourceLabels':
return (
<SimpleDropdown
value={this.state.resourceLabelKey}
options={this.state.resourceLabels}
onValueChange={this.onResourceLabelKeyChange}
label="Resource Labels"
/>
);
case 'metricLabels':
return (
<SimpleDropdown
value={this.state.metricLabelKey}
options={this.state.metricLabels}
onValueChange={this.onMetricLabelKeyChange}
label="Metric Labels"
/>
);
default:
return '';
}
}
renderSwitch(queryType) {
switch (queryType) {
case 'metricTypes':
......@@ -95,22 +120,8 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
);
case 'metricLabels':
case 'resourceLabels':
const dropdown =
queryType === 'resourceLabels' ? (
<SimpleDropdown
value={this.state.resourceLabelKey}
options={this.state.resourceLabels}
onValueChange={this.onResourceLabelKeyChange}
label="Resource Labels"
/>
) : (
<SimpleDropdown
value={this.state.metricLabelKey}
options={this.state.metricLabels}
onValueChange={this.onMetricLabelKeyChange}
label="Metric Labels"
/>
);
case 'resourceTypes':
const dropdown = this.switchMetaType(queryType);
return (
<React.Fragment>
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment