Commit b3edad40 by Erik Sundell

stackdriver: add resource types query

parent cb0d563a
...@@ -13,6 +13,8 @@ export default class StackdriverMetricFindQuery { ...@@ -13,6 +13,8 @@ export default class StackdriverMetricFindQuery {
case 'metricLabels': case 'metricLabels':
case 'resourceLabels': case 'resourceLabels':
return this.handleLabelQueryType(query); return this.handleLabelQueryType(query);
case 'resourceTypes':
return this.handleResourceType(query);
default: default:
return []; return [];
} }
...@@ -40,11 +42,23 @@ export default class StackdriverMetricFindQuery { ...@@ -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) { if (!metricType) {
return []; return [];
} }
const key = type === 'metricLabels' ? metricLabelKey : resourceLabelKey; const key = this.getLabelKey({ type, metricLabelKey, resourceLabelKey });
const refId = 'handleLabelsQueryType'; const refId = 'handleLabelsQueryType';
const response = await this.datasource.getLabels(metricType, refId); const response = await this.datasource.getLabels(metricType, refId);
if (!has(response, `meta.${type}.${key}`)) { if (!has(response, `meta.${type}.${key}`)) {
...@@ -55,4 +69,20 @@ export default class StackdriverMetricFindQuery { ...@@ -55,4 +69,20 @@ export default class StackdriverMetricFindQuery {
expandable: true, 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 ...@@ -44,6 +44,10 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this.setState({ metricDescriptors }); this.setState({ metricDescriptors });
} }
isLabelQuery(queryType) {
return ['metricLabels', 'resourceLabels'].indexOf(queryType) !== -1;
}
async loadTimeSeriesData() { async loadTimeSeriesData() {
const refId = 'StackdriverTemplateQueryComponent'; const refId = 'StackdriverTemplateQueryComponent';
const response = await this.props.datasource.getLabels(this.state.metricType, refId); const response = await this.props.datasource.getLabels(this.state.metricType, refId);
...@@ -52,10 +56,6 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue ...@@ -52,10 +56,6 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
} }
} }
isLabelQuery(queryType) {
return ['metricLabels', 'resourceLabels'].indexOf(queryType) !== -1;
}
handleQueryTypeChange(event) { handleQueryTypeChange(event) {
this.setState({ type: event.target.value }); this.setState({ type: event.target.value });
if (this.isLabelQuery(event.target.value)) { if (this.isLabelQuery(event.target.value)) {
...@@ -87,6 +87,31 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue ...@@ -87,6 +87,31 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this.props.onChange(queryModel); 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) { renderSwitch(queryType) {
switch (queryType) { switch (queryType) {
case 'metricTypes': case 'metricTypes':
...@@ -95,22 +120,8 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue ...@@ -95,22 +120,8 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
); );
case 'metricLabels': case 'metricLabels':
case 'resourceLabels': case 'resourceLabels':
const dropdown = case 'resourceTypes':
queryType === 'resourceLabels' ? ( const dropdown = this.switchMetaType(queryType);
<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"
/>
);
return ( return (
<React.Fragment> <React.Fragment>
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} /> <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