[v11.3.x] Azure: Handle namespace request rejection (#95909)

Azure: Handle namespace request rejection (#95574)

Handle rejection and add test

(cherry picked from commit da1a5426d0)

Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
pull/95911/head
grafana-delivery-bot[bot] 8 months ago committed by GitHub
parent cbf9e323b6
commit a7c1f37435
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 23
      public/app/plugins/datasource/azuremonitor/azure_monitor/azure_monitor_datasource.test.ts
  2. 4
      public/app/plugins/datasource/azuremonitor/azure_monitor/azure_monitor_datasource.ts

@ -247,6 +247,9 @@ describe('AzureMonitorDatasource', () => {
beforeEach(() => {
ctx.ds.azureMonitorDatasource.getResource = jest.fn().mockImplementation((path: string) => {
if (path.includes('westeurope')) {
return Promise.reject('failed to retrieve due to timeout');
}
const basePath = 'azuremonitor/subscriptions/mock-subscription-id/resourceGroups/nodeapp';
const expected =
basePath +
@ -274,6 +277,26 @@ describe('AzureMonitorDatasource', () => {
expect(results[1].value).toEqual('microsoft.insights/components');
});
});
it('should return list of Metric Namespaces even if there is a failure', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation();
return ctx.ds.azureMonitorDatasource
.getMetricNamespaces(
{
resourceUri:
'/subscriptions/mock-subscription-id/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1',
},
true,
'westeurope'
)
.then((results: Array<{ text: string; value: string }>) => {
expect(results.length).toEqual(0);
expect(consoleError).toHaveBeenCalled();
expect(consoleError.mock.calls[0][0]).toContain(
'Failed to get metric namespaces: failed to retrieve due to timeout'
);
});
});
});
describe('When performing getMetricNames', () => {

@ -265,6 +265,10 @@ export default class AzureMonitorDatasource extends DataSourceWithBackend<AzureM
}
}
return result;
})
.catch((reason) => {
console.error(`Failed to get metric namespaces: ${reason}`);
return [];
});
}

Loading…
Cancel
Save