Azure: Handle namespace request rejection (#95574)

Handle rejection and add test
This commit is contained in:
Andreas Christou 2024-11-05 17:54:47 +00:00 committed by GitHub
parent a8578484bb
commit da1a5426d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -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', () => {

View File

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