Commit a1ee6287 by Sofia Papagiannaki Committed by GitHub

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>
parent 81d1f665
......@@ -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}`);
......
......@@ -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 }) => ({
......
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