mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Azure: Handle namespace request rejection (#95574)
Handle rejection and add test
This commit is contained in:
parent
a8578484bb
commit
da1a5426d0
@ -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…
Reference in New Issue
Block a user