@terascope/elasticsearch-api 4.12.2 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,96 +0,0 @@
1
- import { jest } from '@jest/globals';
2
- import { debugLogger, cloneDeep, DataEntity } from '@terascope/utils';
3
- import { ElasticsearchTestHelpers } from '@terascope/opensearch-client';
4
- import elasticsearchAPI from '../index.js';
5
-
6
- const {
7
- makeClient, cleanupIndex, EvenDateData,
8
- TEST_INDEX_PREFIX, createMappingFromDatatype,
9
- formatUploadData
10
- } = ElasticsearchTestHelpers;
11
-
12
- const THREE_MINUTES = 3 * 60 * 1000;
13
-
14
- jest.setTimeout(THREE_MINUTES + 60000);
15
-
16
- describe('bulkSend', () => {
17
- let client;
18
- let api;
19
-
20
- beforeAll(async () => {
21
- client = await makeClient();
22
- });
23
-
24
- describe('can return non-retryable records', () => {
25
- const logger = debugLogger('congested_test');
26
- const index = `${TEST_INDEX_PREFIX}_non-retryable-records`;
27
-
28
- beforeAll(async () => {
29
- await cleanupIndex(client, index);
30
- api = elasticsearchAPI(client, logger, { _dead_letter_action: 'kafka_dead_letter' });
31
-
32
- const overrides = {
33
- settings: {
34
- 'index.number_of_shards': 1,
35
- 'index.number_of_replicas': 0,
36
- },
37
- };
38
-
39
- const mapping = await createMappingFromDatatype(
40
- client, EvenDateData.EvenDataType, '_doc', overrides
41
- );
42
-
43
- mapping.index = index;
44
-
45
- await client.indices.create(mapping);
46
- });
47
-
48
- afterAll(async () => {
49
- await cleanupIndex(client, index);
50
- });
51
-
52
- it('should send records if no issues and dlq not set', async () => {
53
- const diffApi = elasticsearchAPI(client, logger);
54
-
55
- const docs = cloneDeep(EvenDateData.data.slice(0, 2));
56
-
57
- const result = await diffApi.bulkSend(formatUploadData(index, docs, true));
58
-
59
- expect(result).toBe(2);
60
- });
61
-
62
- it('should throw an error if dlq is not set', async () => {
63
- const diffApi = elasticsearchAPI(client, logger);
64
-
65
- const docs = cloneDeep(EvenDateData.data.slice(0, 2));
66
-
67
- docs[0].bytes = 'this is a bad value';
68
-
69
- await expect(diffApi.bulkSend(formatUploadData(index, docs, true)))
70
- .rejects.toThrow();
71
- });
72
-
73
- it('should update metadata for records that are not retryable and return results for successful updates if dlq is set', async () => {
74
- const docs = cloneDeep(EvenDateData.data.slice(0, 2))
75
- .map((doc, i) => DataEntity.make(doc, { _key: i + 1 }));
76
-
77
- docs[0].bytes = 'this is a bad value';
78
-
79
- const result = await api.bulkSend(formatUploadData(index, docs, true));
80
-
81
- // 1 good doc - so only 1 row affected
82
- expect(result).toBe(1);
83
-
84
- expect(docs[0].getMetadata('_bulk_sender_rejection')).toInclude('mapper_parsing_exception--failed to parse field [bytes]');
85
- expect(docs[1].getMetadata('_bulk_sender_rejection')).toBeUndefined();
86
- });
87
-
88
- it('should return a count if not un-retryable records if dlq is set', async () => {
89
- const docs = cloneDeep(EvenDateData.data.slice(0, 2));
90
-
91
- const result = await api.bulkSend(formatUploadData(index, docs, true));
92
-
93
- expect(result).toBe(2);
94
- });
95
- });
96
- });
@@ -1,49 +0,0 @@
1
- import { jest } from '@jest/globals';
2
- import { debugLogger, chunk, pMap } from '@terascope/utils';
3
- import { ElasticsearchTestHelpers } from '@terascope/opensearch-client';
4
- import elasticsearchAPI from '../index.js';
5
-
6
- const {
7
- makeClient, cleanupIndex, waitForData,
8
- EvenDateData, TEST_INDEX_PREFIX, formatUploadData
9
- } = ElasticsearchTestHelpers;
10
-
11
- const THREE_MINUTES = 3 * 60 * 1000;
12
-
13
- jest.setTimeout(THREE_MINUTES + 60000);
14
-
15
- describe('bulkSend', () => {
16
- let client;
17
- let api;
18
-
19
- beforeAll(async () => {
20
- client = await makeClient();
21
- });
22
-
23
- describe('can work with congested queues', () => {
24
- const logger = debugLogger('congested_test');
25
- const index = `${TEST_INDEX_PREFIX}_congested_queues_`;
26
-
27
- beforeAll(async () => {
28
- await cleanupIndex(client, index);
29
- api = elasticsearchAPI(client, logger);
30
- });
31
-
32
- afterAll(async () => {
33
- await cleanupIndex(client, index);
34
- });
35
-
36
- it('can get correct data even with congested queues', async () => {
37
- const chunkedData = chunk(EvenDateData.data, 50);
38
-
39
- await pMap(chunkedData, async (cData) => {
40
- const formattedData = formatUploadData(index, cData, true);
41
- return api.bulkSend(formattedData);
42
- }, { concurrency: 9 });
43
-
44
- await expect(
45
- waitForData(client, index, EvenDateData.data.length, logger, THREE_MINUTES)
46
- ).resolves.not.toThrow();
47
- });
48
- });
49
- });
@@ -1,36 +0,0 @@
1
- import { ElasticsearchTestHelpers } from '@terascope/opensearch-client';
2
- import { debugLogger } from '@terascope/utils';
3
- import opensearch from '@opensearch-project/opensearch';
4
- import API from '../index.js';
5
-
6
- const logger = debugLogger('retry spec');
7
- const port = '1111';
8
-
9
- const { data } = ElasticsearchTestHelpers.EvenDateData;
10
-
11
- const body = ElasticsearchTestHelpers.formatUploadData('retry-error-test', data);
12
-
13
- describe('retry behavior', () => {
14
- it('will work with opensearch when connection cannot be established', async () => {
15
- expect.assertions(4);
16
- const client = new opensearch.Client({ node: `http://127.0.0.1:${port}` });
17
- const { isErrorRetryable } = API(client, logger);
18
-
19
- try {
20
- await client.bulk({ body });
21
- throw Error('should have thrown');
22
- } catch (err) {
23
- expect(err).toBeDefined();
24
- expect(isErrorRetryable(err)).toBeTrue();
25
- }
26
-
27
- // we try again as we have seen the second call be marked as unretryable
28
- try {
29
- await client.bulk({ body });
30
- throw Error('should have thrown');
31
- } catch (err) {
32
- expect(err).toBeDefined();
33
- expect(isErrorRetryable(err)).toBeTrue();
34
- }
35
- });
36
- });
package/types/index.d.ts DELETED
@@ -1,81 +0,0 @@
1
- // Type definitions for elasticsearch-api
2
- // Project: @terascope/elasticsearch-api
3
-
4
- import { ClientParams, ClientResponse } from '@terascope/types';
5
- import { Logger } from '@terascope/utils';
6
- import { ClientMetadata } from '@terascope/types'
7
-
8
- export default elasticsearchAPI;
9
-
10
- declare function elasticsearchAPI(client: Client, logger: Logger, config?: elasticsearchAPI.Config): elasticsearchAPI.Client;
11
-
12
- declare namespace elasticsearchAPI {
13
- export interface Config {
14
- index?: string;
15
- full_response?: boolean;
16
- connection?: string;
17
- }
18
-
19
- export interface Client {
20
- search: (query: ClientParams.SearchParams) => Promise<ClientResponse.SearchResponse | any[]>;
21
- count: (query: ClientParams.CountParams) => Promise<number>;
22
- get: (query: ClientParams.GetParams, fullResponse?: boolean) => Promise<any>;
23
- mget: (query: ClientParams.MGetParams) => Promise<any>;
24
- index: (query: ClientParams.IndexParams) => Promise<any>;
25
- indexWithId: (query: ClientParams.IndexParams) => Promise<any>;
26
- isAvailable: (index: string, recordType?: string) => Promise<any>;
27
- create: (query: ClientParams.CreateParams) => Promise<any>;
28
- update: (query: ClientParams.UpdateParams) => Promise<any>;
29
- remove: (query: ClientParams.DeleteParams) => Promise<es.DeleteDocumentResponse>;
30
- version: () => Promise<boolean>;
31
- putTemplate: (template: any, name: string) => Promise<any>;
32
- /**
33
- * The new and improved bulk send with proper retry support
34
- *
35
- * @returns the number of affected rows
36
- */
37
- bulkSend: (data: BulkRecord[]) => Promise<number>;
38
- nodeInfo: (query: any) => Promise<any>;
39
- nodeStats: (query: any) => Promise<any>;
40
- buildQuery: (opConfig: Config, msg: any) => ClientParams.SearchParams;
41
- indexExists: (query: ClientParams.ExistsParams) => Promise<boolean>;
42
- indexCreate: (query: ClientParams.IndicesCreateParams) => Promise<any>;
43
- indexRefresh: (query: ClientParams.IndicesRefreshParams) => Promise<any>;
44
- indexRecovery: (query: ClientParams.IndicesRecoveryParams) => Promise<any>;
45
- indexSetup: (clusterName, newIndex, migrantIndexName, mapping, recordType, clientName) => Promise<boolean>;
46
- verifyClient: () => boolean;
47
- validateGeoParameters: (opConfig: any) => any;
48
- /** This api is deprecated, please use getClientMetadata */
49
- getESVersion: () => number;
50
- getClientMetadata: () => ClientMetadata;
51
- isElasticsearch6: () => boolean
52
- }
53
-
54
- /**
55
- * This is used for improved bulk sending function
56
- */
57
- export interface BulkRecord {
58
- action: AnyBulkAction;
59
- data?: UpdateConfig | DataEntity;
60
- }
61
-
62
- /**
63
- * This is used for improved bulk sending function
64
- */
65
- export interface AnyBulkAction {
66
- update?: Partial<BulkActionMetadata>;
67
- index?: Partial<BulkActionMetadata>;
68
- create?: Partial<BulkActionMetadata>;
69
- delete?: Partial<BulkActionMetadata>;
70
- }
71
-
72
- /**
73
- * This is used for improved bulk sending function
74
- */
75
- export interface BulkActionMetadata {
76
- _index: string;
77
- _type: string;
78
- _id: string | number;
79
- retry_on_conflict?: number;
80
- }
81
- }