mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Fix alert and action telemetry reporting to stop sending data that contains dot in the name (#61389) (#61567)
* fix alert and action telemetry reporting to stop sending data that starts or ends with a '.' * Fixed due to comments * fixed test * revert testing data
This commit is contained in:
parent
1d6552c43f
commit
bbe940f911
4 changed files with 136 additions and 3 deletions
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getTotalCount } from './actions_telemetry';
|
||||
|
||||
describe('actions telemetry', () => {
|
||||
test('getTotalCount should replace action types names with . to __', async () => {
|
||||
const mockEsClient = jest.fn();
|
||||
mockEsClient.mockReturnValue({
|
||||
aggregations: {
|
||||
byActionTypeId: {
|
||||
value: {
|
||||
types: { '.index': 1, '.server-log': 1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
hits: {
|
||||
hits: [
|
||||
{
|
||||
_id: 'action:541efb3d-f82a-4d2c-a5c3-636d1ce49b53',
|
||||
_index: '.kibana_1',
|
||||
_score: 0,
|
||||
_source: {
|
||||
action: {
|
||||
actionTypeId: '.index',
|
||||
config: {
|
||||
index: 'kibana_sample_data_ecommerce',
|
||||
refresh: true,
|
||||
executionTimeField: null,
|
||||
},
|
||||
name: 'test',
|
||||
secrets:
|
||||
'UPyn6cit6zBTPMmldfKh/8S2JWypwaLhhEQWBXp+OyTc6TtLHOnW92wehCqTq1FhIY3vA8hwVsggj+tbIoCcfPArpzP5SO7hh8vd6pY13x5TkiM083UgjjaAxbPvKQ==',
|
||||
},
|
||||
references: [],
|
||||
type: 'action',
|
||||
updated_at: '2020-03-26T18:46:44.449Z',
|
||||
},
|
||||
},
|
||||
{
|
||||
_id: 'action:00000000-f82a-4d2c-a5c3-636d1ce49b53',
|
||||
_index: '.kibana_1',
|
||||
_score: 0,
|
||||
_source: {
|
||||
action: {
|
||||
actionTypeId: '.server-log',
|
||||
config: {},
|
||||
name: 'test server log',
|
||||
secrets: '',
|
||||
},
|
||||
references: [],
|
||||
type: 'action',
|
||||
updated_at: '2020-03-26T18:46:44.449Z',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const telemetry = await getTotalCount(mockEsClient, 'test');
|
||||
|
||||
expect(mockEsClient).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(telemetry).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"countByType": Object {
|
||||
"__index": 1,
|
||||
"__server-log": 1,
|
||||
},
|
||||
"countTotal": 2,
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
|
@ -54,7 +54,13 @@ export async function getTotalCount(callCluster: APICaller, kibanaIndex: string)
|
|||
parseInt(searchResult.aggregations.byActionTypeId.value.types[key], 0) + total,
|
||||
0
|
||||
),
|
||||
countByType: searchResult.aggregations.byActionTypeId.value.types,
|
||||
countByType: Object.keys(searchResult.aggregations.byActionTypeId.value.types).reduce(
|
||||
(obj: any, key: string) => ({
|
||||
...obj,
|
||||
[key.replace('.', '__')]: searchResult.aggregations.byActionTypeId.value.types[key],
|
||||
}),
|
||||
{}
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getTotalCountInUse } from './alerts_telemetry';
|
||||
|
||||
describe('alerts telemetry', () => {
|
||||
test('getTotalCountInUse should replace action types names with . to __', async () => {
|
||||
const mockEsClient = jest.fn();
|
||||
mockEsClient.mockReturnValue({
|
||||
aggregations: {
|
||||
byAlertTypeId: {
|
||||
value: {
|
||||
types: { '.index-threshold': 2 },
|
||||
},
|
||||
},
|
||||
},
|
||||
hits: {
|
||||
hits: [],
|
||||
},
|
||||
});
|
||||
|
||||
const telemetry = await getTotalCountInUse(mockEsClient, 'test');
|
||||
|
||||
expect(mockEsClient).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(telemetry).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"countByType": Object {
|
||||
"__index-threshold": 2,
|
||||
},
|
||||
"countTotal": 2,
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
|
@ -245,7 +245,13 @@ export async function getTotalCountAggregations(callCluster: APICaller, kibanaIn
|
|||
|
||||
return {
|
||||
count_total: totalAlertsCount,
|
||||
count_by_type: results.aggregations.byAlertTypeId.value.types,
|
||||
count_by_type: Object.keys(results.aggregations.byAlertTypeId.value.types).reduce(
|
||||
(obj: any, key: string) => ({
|
||||
...obj,
|
||||
[key.replace('.', '__')]: results.aggregations.byAlertTypeId.value.types[key],
|
||||
}),
|
||||
{}
|
||||
),
|
||||
throttle_time: {
|
||||
min: `${results.aggregations.throttleTime.value.min}s`,
|
||||
avg: `${
|
||||
|
@ -298,7 +304,13 @@ export async function getTotalCountInUse(callCluster: APICaller, kibanaInex: str
|
|||
parseInt(searchResult.aggregations.byAlertTypeId.value.types[key], 0) + total,
|
||||
0
|
||||
),
|
||||
countByType: searchResult.aggregations.byAlertTypeId.value.types,
|
||||
countByType: Object.keys(searchResult.aggregations.byAlertTypeId.value.types).reduce(
|
||||
(obj: any, key: string) => ({
|
||||
...obj,
|
||||
[key.replace('.', '__')]: searchResult.aggregations.byAlertTypeId.value.types[key],
|
||||
}),
|
||||
{}
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue