Skip to content

Commit

Permalink
Update usage collectors for connectors to collect full telemetry data (
Browse files Browse the repository at this point in the history
…#176366)

## Summary

This PR updates the usage collectors for plugins `enterprise_search` and
`serverless_search` to collect full telemetry data, via [List connectors
API](https://www.elastic.co/guide/en/elasticsearch/reference/current/list-connector-api.html)
and [List connector sync jobs
API](https://www.elastic.co/guide/en/elasticsearch/reference/current/list-connector-sync-jobs-api.html).


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
wangch079 and kibanamachine authored Mar 5, 2024
1 parent 70f6349 commit 68a2bd7
Show file tree
Hide file tree
Showing 24 changed files with 3,713 additions and 245 deletions.
89 changes: 89 additions & 0 deletions packages/kbn-search-connectors/lib/collect_connector_stats.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { ConnectorSyncJob, Paginate } from '../types';
import { fetchConnectors, fetchSyncJobs } from '..';
import { collectConnectorStats } from './collect_connector_stats';
import {
expectedDeletedConnectorStats,
expectedMysqlConnectorStats,
expectedSpoConnectorStats,
mysqlConnector,
mysqlFullSyncJob,
orphanedSyncJob,
spoAccessControlSyncJob,
spoConnector,
spoFullSyncJob,
spoIncrementalSyncJob,
} from './collect_connector_stats_test_data';

jest.mock('.', () => ({
fetchConnectors: jest.fn(),
fetchSyncJobs: jest.fn(),
}));

describe('collect connector stats', () => {
const mockClient = {
indices: {
stats: jest.fn(),
},
search: jest.fn(),
};
const mockSyncJobsResponse: Paginate<ConnectorSyncJob> = {
_meta: {
page: {
from: 0,
size: 5,
total: 5,
has_more_hits_than_total: false,
},
},
data: [
spoFullSyncJob,
spoIncrementalSyncJob,
spoAccessControlSyncJob,
mysqlFullSyncJob,
orphanedSyncJob,
],
};
it('should collect connector stats', async () => {
(fetchConnectors as jest.Mock).mockImplementation(() => [spoConnector, mysqlConnector]);
(fetchSyncJobs as jest.Mock).mockImplementation(() => mockSyncJobsResponse);
mockClient.indices.stats.mockImplementation((params: { index: any }) =>
Promise.resolve({
_all: {
primaries: {
docs: {
count: params.index === spoConnector.index_name ? 1000 : 2000,
},
store: {
size_in_bytes: params.index === spoConnector.index_name ? 10000 : 20000,
},
},
},
})
);
mockClient.search.mockImplementation(() =>
Promise.resolve({
aggregations: {
table_count: {
value: 7,
},
},
})
);

const collectedConnectorStats = await collectConnectorStats(mockClient as any);

expect(collectedConnectorStats.sort((a, b) => (a.id > b.id ? 1 : -1))).toEqual([
expectedSpoConnectorStats,
expectedMysqlConnectorStats,
expectedDeletedConnectorStats,
]);
});
});
Loading

0 comments on commit 68a2bd7

Please sign in to comment.