Skip to content

Commit

Permalink
[Actions] Add preconfigured actions to our telemetry data (#112514)
Browse files Browse the repository at this point in the history
* Add preconfigured action telemetry

* Revert this change

* Treat the preconfigured action ids the same as the non preconfigured ones

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
chrisronline and kibanamachine authored Sep 27, 2021
1 parent c0d68aa commit 0d3fa76
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 55 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ export class ActionsPlugin implements Plugin<PluginSetupContract, PluginStartCon
this.telemetryLogger,
plugins.taskManager,
core,
this.kibanaIndexConfig.kibana.index
this.kibanaIndexConfig.kibana.index,
this.preconfiguredActions
);
}

Expand Down
223 changes: 215 additions & 8 deletions x-pack/plugins/actions/server/usage/actions_telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,215 @@ Object {
},
},
},
hits: {
hits: [],
preconfigured_actions: {
preconfiguredActionRefIds: {
value: {
total: 1,
actionRefs: {
'preconfigured:preconfigured-alert-history-es-index': {
actionRef: 'preconfigured:preconfigured-alert-history-es-index',
actionTypeId: '.index',
},
},
},
},
},
},
})
);
const actionsBulkGet = jest.fn();
actionsBulkGet.mockReturnValue({
saved_objects: [
{
id: '1',
attributes: {
actionTypeId: '.server-log',
},
},
{
id: '123',
attributes: {
actionTypeId: '.slack',
},
},
],
});
const telemetry = await getInUseTotalCount(mockEsClient, actionsBulkGet, 'test');

expect(mockEsClient.search).toHaveBeenCalledTimes(1);
expect(actionsBulkGet).toHaveBeenCalledTimes(1);

expect(telemetry).toMatchInlineSnapshot(`
Object {
"countByAlertHistoryConnectorType": 1,
"countByType": Object {
"__index": 1,
"__server-log": 1,
"__slack": 1,
},
"countTotal": 4,
}
`);
});

test('getTotalCount accounts for preconfigured connectors', async () => {
const mockEsClient = elasticsearchClientMock.createClusterClient().asScoped().asInternalUser;
mockEsClient.search.mockReturnValue(
// @ts-expect-error not full search response
elasticsearchClientMock.createSuccessTransportRequestPromise({
aggregations: {
byActionTypeId: {
value: {
types: { '.index': 1, '.server-log': 1, 'some.type': 1, 'another.type.': 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',
},
},
{
_id: 'action:00000000-1',
_index: '.kibana_1',
_score: 0,
_source: {
action: {
actionTypeId: 'some.type',
config: {},
name: 'test type',
secrets: {},
},
references: [],
type: 'action',
updated_at: '2020-03-26T18:46:44.449Z',
},
},
{
_id: 'action:00000000-2',
_index: '.kibana_1',
_score: 0,
_source: {
action: {
actionTypeId: 'another.type.',
config: {},
name: 'test another type',
secrets: {},
},
references: [],
type: 'action',
updated_at: '2020-03-26T18:46:44.449Z',
},
},
],
},
})
);
const telemetry = await getTotalCount(mockEsClient, 'test', [
{
id: 'test',
actionTypeId: '.test',
name: 'test',
isPreconfigured: true,
secrets: {},
},
{
id: 'anotherServerLog',
actionTypeId: '.server-log',
name: 'test',
isPreconfigured: true,
secrets: {},
},
]);

expect(mockEsClient.search).toHaveBeenCalledTimes(1);

expect(telemetry).toMatchInlineSnapshot(`
Object {
"countByType": Object {
"__index": 1,
"__server-log": 2,
"__test": 1,
"another.type__": 1,
"some.type": 1,
},
"countTotal": 6,
}
`);
});

test('getInUseTotalCount() accounts for preconfigured connectors', async () => {
const mockEsClient = elasticsearchClientMock.createClusterClient().asScoped().asInternalUser;
mockEsClient.search.mockReturnValue(
// @ts-expect-error not full search response
elasticsearchClientMock.createSuccessTransportRequestPromise({
aggregations: {
refs: {
actionRefIds: {
value: {
connectorIds: {
'1': 'action-0',
'123': 'action-1',
'456': 'action-2',
},
total: 3,
},
},
},
preconfigured_actions: {
preconfiguredActionRefIds: {
value: {
total: 3,
actionRefs: {
'preconfigured:preconfigured-alert-history-es-index': {
actionRef: 'preconfigured:preconfigured-alert-history-es-index',
actionTypeId: '.index',
},
'preconfigured:cloud_email': {
actionRef: 'preconfigured:cloud_email',
actionTypeId: '.email',
},
'preconfigured:cloud_email2': {
actionRef: 'preconfigured:cloud_email2',
actionTypeId: '.email',
},
},
},
},
},
},
})
Expand All @@ -208,11 +415,9 @@ Object {
},
},
{
id: 'preconfigured-alert-history-es-index',
error: {
statusCode: 404,
error: 'Not Found',
message: 'Saved object [action/preconfigured-alert-history-es-index] not found',
id: '456',
attributes: {
actionTypeId: '.email',
},
},
],
Expand All @@ -226,10 +431,12 @@ Object {
Object {
"countByAlertHistoryConnectorType": 1,
"countByType": Object {
"__email": 3,
"__index": 1,
"__server-log": 1,
"__slack": 1,
},
"countTotal": 3,
"countTotal": 6,
}
`);
});
Expand Down
Loading

0 comments on commit 0d3fa76

Please sign in to comment.