Skip to content

Commit

Permalink
[teraslice, elasticsearch-store] opensearch2 mappings missing dynamic…
Browse files Browse the repository at this point in the history
…s: false field (#3808)

This PR makes the following changes:

- updates `ensureNoTypeInMapping()` to copy `dynamic` property when
removing type from mapping.
- creates `method-helpers-spec.ts` and adds unit tests for
`ensureNoTypeInMapping()`.
- creates an e2e `storage-spec.ts` to confirm that the jobs state
storage index mapping is created with `dynamic` set to `false`.
- bump teraslice from version 2.6.2 to 2.6.3
- bump elasticsearch-api from 1.3.2 to 1.3.3
- bump elasticsearch-store from 1.3.2 to 1.3.3
- bump terafoundation from 1.5.3 to 1.5.4

Ref: #3809
  • Loading branch information
busma13 authored Oct 28, 2024
1 parent 0d5cf94 commit 0ca4fe7
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 9 deletions.
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@terascope/types": "^1.2.0",
"bunyan": "^1.8.15",
"elasticsearch-store": "^1.3.2",
"elasticsearch-store": "^1.3.3",
"fs-extra": "^11.2.0",
"ms": "^2.1.3",
"nanoid": "^5.0.7",
Expand Down
29 changes: 29 additions & 0 deletions e2e/test/cases/cluster/storage-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { TerasliceHarness } from '../../teraslice-harness.js';
import { TEST_OPENSEARCH } from '../../config.js';

describe('mappings', () => {
let terasliceHarness: TerasliceHarness;

beforeAll(async () => {
terasliceHarness = new TerasliceHarness();
await terasliceHarness.init();
await terasliceHarness.resetState();
});

it('should have a jobs index with dynamic mapping false', async () => {
const mapping = await terasliceHarness.client.indices.getMapping({ index: '*__jobs' });
const indexName = Object.keys(mapping)[0];
const searchVersion = terasliceHarness.client.__meta.version;
if (!TEST_OPENSEARCH && searchVersion.charAt(0) === '6') {
expect(mapping[indexName]).toMatchObject({
mappings: {
job: expect.objectContaining({ dynamic: 'false' })
}
});
} else {
expect(mapping[indexName]).toMatchObject({
mappings: expect.objectContaining({ dynamic: 'false' })
});
}
});
});
3 changes: 2 additions & 1 deletion e2e/test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ export {
MINIO_ACCESS_KEY,
MINIO_SECRET_KEY,
ENCRYPT_MINIO,
ROOT_CERT_PATH
ROOT_CERT_PATH,
TEST_OPENSEARCH
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "teraslice-workspace",
"displayName": "Teraslice",
"version": "2.6.2",
"version": "2.6.3",
"private": true,
"homepage": "https://github.com/terascope/teraslice",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/elasticsearch-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@opensearch-project/opensearch": "^1.2.0",
"@types/elasticsearch": "^5.0.43",
"elasticsearch": "^15.4.1",
"elasticsearch-store": "^1.3.2",
"elasticsearch-store": "^1.3.3",
"elasticsearch6": "npm:@elastic/elasticsearch@^6.7.0",
"elasticsearch7": "npm:@elastic/elasticsearch@^7.0.0",
"elasticsearch8": "npm:@elastic/elasticsearch@^8.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/elasticsearch-store/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elasticsearch-store",
"displayName": "Elasticsearch Store",
"version": "1.3.2",
"version": "1.3.3",
"description": "An API for managing an elasticsearch index, with versioning and migration support.",
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/elasticsearch-store#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export function ensureNoTypeInMapping(mappings: Record<string, any> | undefined)
for (const [k, v] of Object.entries(mappings)) {
if (k === 'properties') parsed[k] = v;
if (k === '_meta') parsed[k] = v;
if (k === 'dynamic') parsed[k] = v;

if (v.properties) parsed.properties = v.properties;
if (v._meta) parsed._meta = v._meta;
if (v.dynamic !== undefined) parsed.dynamic = v.dynamic;
}
}
return parsed;
Expand Down
133 changes: 133 additions & 0 deletions packages/elasticsearch-store/test/method-helpers-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { ensureNoTypeInMapping } from '../src/elasticsearch-client/method-helpers/index.js';

describe('test method helpers', () => {
describe('->ensureNoTypeInMapping', () => {
describe('mappings with type', () => {
const mappingsWithType = {
myType: {
_meta: {
foo: 'foo'
},
_all: {
enabled: false
},
dynamic: false,
properties: {
_context: {
type: 'keyword'
},
_created: {
type: 'date'
},
_updated: {
type: 'date'
},
_deleted: {
type: 'boolean'
},
_deleted_on: {
type: 'date'
}
}
}
};

const newMappings = ensureNoTypeInMapping(mappingsWithType);

it('should remove myType wrapper object from mappingsWithType', () => {
expect(newMappings.myType).toBe(undefined);
});

it('should remove _all from mappingsWithType', () => {
expect(newMappings._all).toBe(undefined);
});

it('should include properties, _meta, and dynamic from mappingsWithType', () => {
expect(newMappings).toMatchObject({
_meta: {
foo: 'foo'
},
dynamic: false,
properties: {
_context: {
type: 'keyword',
},
_created: {
type: 'date',
},
_deleted: {
type: 'boolean',
},
_deleted_on: {
type: 'date',
},
_updated: {
type: 'date',
},
},
});
});
});

describe('mappings without type', () => {
const mappingsWithoutType = {
_meta: {
foo: 'foo'
},
_all: {
enabled: false
},
dynamic: false,
properties: {
_context: {
type: 'keyword'
},
_created: {
type: 'date'
},
_updated: {
type: 'date'
},
_deleted: {
type: 'boolean'
},
_deleted_on: {
type: 'date'
}
}
};

const newMappings = ensureNoTypeInMapping(mappingsWithoutType);

it('should remove _all from mappingsWithoutType', () => {
expect(newMappings._all).toBe(undefined);
});

it('should include properties, _meta, and dynamic from mappingsWithoutType', () => {
expect(newMappings).toMatchObject({
_meta: {
foo: 'foo'
},
dynamic: false,
properties: {
_context: {
type: 'keyword',
},
_created: {
type: 'date',
},
_deleted: {
type: 'boolean',
},
_deleted_on: {
type: 'date',
},
_updated: {
type: 'date',
},
},
});
});
});
});
});
4 changes: 2 additions & 2 deletions packages/terafoundation/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "terafoundation",
"displayName": "Terafoundation",
"version": "1.5.3",
"version": "1.5.4",
"description": "A Clustering and Foundation tool for Terascope Tools",
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/terafoundation#readme",
"bugs": {
Expand Down Expand Up @@ -37,7 +37,7 @@
"convict-format-with-moment": "^6.2.0",
"convict-format-with-validator": "^6.2.0",
"elasticsearch": "^15.4.1",
"elasticsearch-store": "^1.3.2",
"elasticsearch-store": "^1.3.3",
"express": "^4.21.0",
"js-yaml": "^4.1.0",
"nanoid": "^5.0.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/teraslice/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "teraslice",
"displayName": "Teraslice",
"version": "2.6.2",
"version": "2.6.3",
"description": "Distributed computing platform for processing JSON data",
"homepage": "https://github.com/terascope/teraslice#readme",
"bugs": {
Expand Down Expand Up @@ -63,7 +63,7 @@
"semver": "^7.6.3",
"socket.io": "^1.7.4",
"socket.io-client": "^1.7.4",
"terafoundation": "^1.5.3",
"terafoundation": "^1.5.4",
"uuid": "^10.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 0ca4fe7

Please sign in to comment.