Stackdriver: Fix creating Service Level Objectives (SLO) datasource query variable (#25023)

* Fetch SLOs on SLO service change

* Prevent querying for SLOs if SLO service is empty

Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
This commit is contained in:
Sofia Papagiannaki 2020-05-25 12:34:44 +03:00 committed by GitHub
parent 81d1f6653f
commit a1ee62877e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -144,7 +144,12 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
}
componentDidUpdate(prevProps: Readonly<VariableQueryProps>, prevState: Readonly<VariableQueryData>) {
if (!getConfig().featureToggles.newVariables || prevState.selectedQueryType !== this.state.selectedQueryType) {
const selectSLOServiceChanged = this.state.selectedSLOService !== prevState.selectedSLOService;
if (
!getConfig().featureToggles.newVariables ||
prevState.selectedQueryType !== this.state.selectedQueryType ||
selectSLOServiceChanged
) {
const { metricDescriptors, labels, metricTypes, services, ...queryModel } = this.state;
const query = this.queryTypes.find(q => q.value === this.state.selectedQueryType);
this.props.onChange(queryModel, `Stackdriver - ${query.name}`);

View File

@ -249,6 +249,9 @@ export default class StackdriverDatasource extends DataSourceApi<StackdriverQuer
}
async getServiceLevelObjectives(projectName: string, serviceId: string): Promise<Array<SelectableValue<string>>> {
if (!serviceId) {
return Promise.resolve([]);
}
let { projectName: p, serviceId: s } = this.interpolateProps({ projectName, serviceId });
return this.api.get(`${p}/services/${s}/serviceLevelObjectives`, {
responseMap: ({ name, displayName, goal }: { name: string; displayName: string; goal: number }) => ({