mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Handling a 404 when the space's telemetry collector runs (#55921)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
7cf33c14dd
commit
7763a6055a
2 changed files with 60 additions and 19 deletions
|
@ -66,6 +66,38 @@ const defaultCallClusterMock = jest.fn().mockResolvedValue({
|
|||
},
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
it('handles a 404 when searching for space usage', async () => {
|
||||
const { features, licensing, usageCollecion } = setup({
|
||||
license: { isAvailable: true, type: 'basic' },
|
||||
});
|
||||
const { fetch: getSpacesUsage } = getSpacesUsageCollector(usageCollecion as any, {
|
||||
kibanaIndex: '.kibana',
|
||||
features,
|
||||
licensing,
|
||||
});
|
||||
|
||||
await getSpacesUsage(jest.fn().mockRejectedValue({ status: 404 }));
|
||||
});
|
||||
|
||||
it('throws error for a non-404', async () => {
|
||||
const { features, licensing, usageCollecion } = setup({
|
||||
license: { isAvailable: true, type: 'basic' },
|
||||
});
|
||||
const { fetch: getSpacesUsage } = getSpacesUsageCollector(usageCollecion as any, {
|
||||
kibanaIndex: '.kibana',
|
||||
features,
|
||||
licensing,
|
||||
});
|
||||
|
||||
const statusCodes = [401, 402, 403, 500];
|
||||
for (const statusCode of statusCodes) {
|
||||
const error = { status: statusCode };
|
||||
await expect(getSpacesUsage(jest.fn().mockRejectedValue(error))).rejects.toBe(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a basic license', () => {
|
||||
let usageStats: UsageStats;
|
||||
beforeAll(async () => {
|
||||
|
|
|
@ -50,31 +50,40 @@ async function getSpacesUsage(
|
|||
|
||||
const knownFeatureIds = features.getFeatures().map(feature => feature.id);
|
||||
|
||||
const resp = await callCluster<SpacesAggregationResponse>('search', {
|
||||
index: kibanaIndex,
|
||||
body: {
|
||||
track_total_hits: true,
|
||||
query: {
|
||||
term: {
|
||||
type: {
|
||||
value: 'space',
|
||||
let resp: SpacesAggregationResponse | undefined;
|
||||
try {
|
||||
resp = await callCluster<SpacesAggregationResponse>('search', {
|
||||
index: kibanaIndex,
|
||||
body: {
|
||||
track_total_hits: true,
|
||||
query: {
|
||||
term: {
|
||||
type: {
|
||||
value: 'space',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
disabledFeatures: {
|
||||
terms: {
|
||||
field: 'space.disabledFeatures',
|
||||
include: knownFeatureIds,
|
||||
size: knownFeatureIds.length,
|
||||
aggs: {
|
||||
disabledFeatures: {
|
||||
terms: {
|
||||
field: 'space.disabledFeatures',
|
||||
include: knownFeatureIds,
|
||||
size: knownFeatureIds.length,
|
||||
},
|
||||
},
|
||||
},
|
||||
size: 0,
|
||||
},
|
||||
size: 0,
|
||||
},
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.status === 404) {
|
||||
return {} as UsageStats;
|
||||
}
|
||||
|
||||
const { hits, aggregations } = resp;
|
||||
throw err;
|
||||
}
|
||||
|
||||
const { hits, aggregations } = resp!;
|
||||
|
||||
const count = get(hits, 'total.value', 0);
|
||||
const disabledFeatureBuckets = get(aggregations, 'disabledFeatures.buckets', []);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue