Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Deprecation] Deprecate the apiVersion: master value and replace with ? #1687

Closed
tmarkley opened this issue Jun 7, 2022 · 0 comments · Fixed by #1799
Closed

[Deprecation] Deprecate the apiVersion: master value and replace with ? #1687

tmarkley opened this issue Jun 7, 2022 · 0 comments · Fixed by #1799

Comments

@tmarkley
Copy link
Contributor

tmarkley commented Jun 7, 2022

Parent: #1318

Open Question: What value for apiVersion should be used? apiVersion: main?

Instances of apiVersion: master

* Version of the OpenSearch (6.7, 7.1 or `master`) client will be connecting to.

const mockOpenSearchClientConfig = { apiVersion: 'opensearch-client-master' };

apiVersion: 'master',
customHeaders: { xsrf: 'something' },
logQueries: false,
sniffOnStart: false,
sniffOnConnectionFault: false,
hosts: ['http://localhost/opensearch'],
requestHeadersWhitelist: [],
},
logger.get()
)
).toMatchInlineSnapshot(`
Object {
"apiVersion": "master",
"hosts": Array [
Object {
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
"path": "/opensearch",
"port": "80",
"protocol": "http:",
"query": null,
},
],
"keepAlive": true,
"log": [Function],
"sniffOnConnectionFault": false,
"sniffOnStart": false,
}
`);
});
test('parses fully specified config', () => {
const opensearchConfig: LegacyOpenSearchClientConfig = {
apiVersion: 'v7.0.0',
customHeaders: { xsrf: 'something' },
logQueries: true,
sniffOnStart: true,
sniffOnConnectionFault: true,
hosts: [
'http://localhost/opensearch',
'http://domain.com:1234/opensearch',
'https://opensearch.local',
],
requestHeadersWhitelist: [],
username: 'opensearch',
password: 'changeme',
pingTimeout: 12345,
requestTimeout: 54321,
sniffInterval: 11223344,
ssl: {
verificationMode: 'certificate',
certificateAuthorities: ['content-of-ca-path-1', 'content-of-ca-path-2'],
certificate: 'content-of-certificate-path',
key: 'content-of-key-path',
keyPassphrase: 'key-pass',
alwaysPresentCertificate: true,
},
};
const opensearchClientConfig = parseOpenSearchClientConfig(opensearchConfig, logger.get());
// Check that original references aren't used.
for (const host of opensearchClientConfig.hosts) {
expect(opensearchConfig.customHeaders).not.toBe(host.headers);
}
expect(opensearchConfig.ssl).not.toBe(opensearchClientConfig.ssl);
expect(opensearchClientConfig).toMatchInlineSnapshot(`
Object {
"apiVersion": "v7.0.0",
"hosts": Array [
Object {
"auth": "opensearch:changeme",
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
"path": "/opensearch",
"port": "80",
"protocol": "http:",
"query": null,
},
Object {
"auth": "opensearch:changeme",
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "domain.com",
"path": "/opensearch",
"port": "1234",
"protocol": "http:",
"query": null,
},
Object {
"auth": "opensearch:changeme",
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
"path": "/",
"port": "443",
"protocol": "https:",
"query": null,
},
],
"keepAlive": true,
"log": [Function],
"pingTimeout": 12345,
"requestTimeout": 54321,
"sniffInterval": 11223344,
"sniffOnConnectionFault": true,
"sniffOnStart": true,
"ssl": Object {
"ca": Array [
"content-of-ca-path-1",
"content-of-ca-path-2",
],
"cert": "content-of-certificate-path",
"checkServerIdentity": [Function],
"key": "content-of-key-path",
"passphrase": "key-pass",
"rejectUnauthorized": true,
},
}
`);
});
test('parses config timeouts of moment.Duration type', () => {
expect(
parseOpenSearchClientConfig(
{
apiVersion: 'master',
customHeaders: { xsrf: 'something' },
logQueries: false,
sniffOnStart: false,
sniffOnConnectionFault: false,
pingTimeout: duration(100, 'ms'),
requestTimeout: duration(30, 's'),
sniffInterval: duration(1, 'minute'),
hosts: ['http://localhost:9200/opensearch'],
requestHeadersWhitelist: [],
},
logger.get()
)
).toMatchInlineSnapshot(`
Object {
"apiVersion": "master",
"hosts": Array [
Object {
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
"path": "/opensearch",
"port": "9200",
"protocol": "http:",
"query": null,
},
],
"keepAlive": true,
"log": [Function],
"pingTimeout": 100,
"requestTimeout": 30000,
"sniffInterval": 60000,
"sniffOnConnectionFault": false,
"sniffOnStart": false,
}
`);
});
describe('#auth', () => {
test('is not set if #auth = false even if username and password are provided', () => {
expect(
parseOpenSearchClientConfig(
{
apiVersion: 'v7.0.0',
customHeaders: { xsrf: 'something' },
logQueries: true,
sniffOnStart: true,
sniffOnConnectionFault: true,
hosts: ['http://user:password@localhost/opensearch', 'https://opensearch.local'],
username: 'opensearch',
password: 'changeme',
requestHeadersWhitelist: [],
},
logger.get(),
{ auth: false }
)
).toMatchInlineSnapshot(`
Object {
"apiVersion": "v7.0.0",
"hosts": Array [
Object {
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
"path": "/opensearch",
"port": "80",
"protocol": "http:",
"query": null,
},
Object {
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
"path": "/",
"port": "443",
"protocol": "https:",
"query": null,
},
],
"keepAlive": true,
"log": [Function],
"sniffOnConnectionFault": true,
"sniffOnStart": true,
}
`);
});
test('is not set if username is not specified', () => {
expect(
parseOpenSearchClientConfig(
{
apiVersion: 'v7.0.0',
customHeaders: { xsrf: 'something' },
logQueries: true,
sniffOnStart: true,
sniffOnConnectionFault: true,
hosts: ['https://opensearch.local'],
requestHeadersWhitelist: [],
password: 'changeme',
},
logger.get(),
{ auth: true }
)
).toMatchInlineSnapshot(`
Object {
"apiVersion": "v7.0.0",
"hosts": Array [
Object {
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
"path": "/",
"port": "443",
"protocol": "https:",
"query": null,
},
],
"keepAlive": true,
"log": [Function],
"sniffOnConnectionFault": true,
"sniffOnStart": true,
}
`);
});
test('is not set if password is not specified', () => {
expect(
parseOpenSearchClientConfig(
{
apiVersion: 'v7.0.0',
customHeaders: { xsrf: 'something' },
logQueries: true,
sniffOnStart: true,
sniffOnConnectionFault: true,
hosts: ['https://opensearch.local'],
requestHeadersWhitelist: [],
username: 'opensearch',
},
logger.get(),
{ auth: true }
)
).toMatchInlineSnapshot(`
Object {
"apiVersion": "v7.0.0",
"hosts": Array [
Object {
"headers": Object {
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
"path": "/",
"port": "443",
"protocol": "https:",
"query": null,
},
],
"keepAlive": true,
"log": [Function],
"sniffOnConnectionFault": true,
"sniffOnStart": true,
}
`);
});
});
describe('#customHeaders', () => {
test('override the default headers', () => {
const headerKey = Object.keys(DEFAULT_HEADERS)[0];
const parsedConfig = parseOpenSearchClientConfig(
{
apiVersion: 'master',
customHeaders: { [headerKey]: 'foo' },
logQueries: false,
sniffOnStart: false,
sniffOnConnectionFault: false,
hosts: ['http://localhost/opensearch'],
requestHeadersWhitelist: [],
},
logger.get()
);
expect(parsedConfig.hosts[0].headers).toEqual({
[headerKey]: 'foo',
});
});
});
describe('#log', () => {
test('default logger with #logQueries = false', () => {
const parsedConfig = parseOpenSearchClientConfig(
{
apiVersion: 'master',
customHeaders: { xsrf: 'something' },
logQueries: false,
sniffOnStart: false,
sniffOnConnectionFault: false,
hosts: ['http://localhost/opensearch'],
requestHeadersWhitelist: [],
},
logger.get()
);
const Logger = new parsedConfig.log();
Logger.error('some-error');
Logger.warning('some-warning');
Logger.trace('some-trace');
Logger.info('some-info');
Logger.debug('some-debug');
expect(typeof Logger.close).toBe('function');
expect(loggingSystemMock.collect(logger)).toMatchInlineSnapshot(`
Object {
"debug": Array [],
"error": Array [
Array [
"some-error",
],
],
"fatal": Array [],
"info": Array [],
"log": Array [],
"trace": Array [],
"warn": Array [
Array [
"some-warning",
],
],
}
`);
});
test('default logger with #logQueries = true', () => {
const parsedConfig = parseOpenSearchClientConfig(
{
apiVersion: 'master',
customHeaders: { xsrf: 'something' },
logQueries: true,
sniffOnStart: false,
sniffOnConnectionFault: false,
hosts: ['http://localhost/opensearch'],
requestHeadersWhitelist: [],
},
logger.get()
);
const Logger = new parsedConfig.log();
Logger.error('some-error');
Logger.warning('some-warning');
Logger.trace('METHOD', { path: '/some-path' }, '?query=2', 'unknown', '304');
Logger.info('some-info');
Logger.debug('some-debug');
expect(typeof Logger.close).toBe('function');
expect(loggingSystemMock.collect(logger)).toMatchInlineSnapshot(`
Object {
"debug": Array [
Array [
"304
METHOD /some-path
?query=2",
Object {
"tags": Array [
"query",
],
},
],
],
"error": Array [
Array [
"some-error",
],
],
"fatal": Array [],
"info": Array [],
"log": Array [],
"trace": Array [],
"warn": Array [
Array [
"some-warning",
],
],
}
`);
});
test('custom logger', () => {
const customLogger = jest.fn();
const parsedConfig = parseOpenSearchClientConfig(
{
apiVersion: 'master',

manasvinibs added a commit to manasvinibs/OpenSearch-Dashboards that referenced this issue Jun 24, 2022
manasvinibs added a commit to manasvinibs/OpenSearch-Dashboards that referenced this issue Jun 24, 2022
manasvinibs added a commit to manasvinibs/OpenSearch-Dashboards that referenced this issue Jun 27, 2022
manasvinibs added a commit to manasvinibs/OpenSearch-Dashboards that referenced this issue Jun 28, 2022
kavilla pushed a commit that referenced this issue Jun 29, 2022
… main (#1799)

Resolves issue - #1687

Signed-off-by: Manasvini B Suryanarayana <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this issue Jun 29, 2022
… main (#1799)

Resolves issue - #1687

Signed-off-by: Manasvini B Suryanarayana <[email protected]>
(cherry picked from commit 2e6293e)
opensearch-trigger-bot bot pushed a commit that referenced this issue Jun 29, 2022
… main (#1799)

Resolves issue - #1687

Signed-off-by: Manasvini B Suryanarayana <[email protected]>
(cherry picked from commit 2e6293e)
kavilla pushed a commit that referenced this issue Jun 29, 2022
… main (#1799) (#1831)

Resolves issue - #1687

Signed-off-by: Manasvini B Suryanarayana <[email protected]>
(cherry picked from commit 2e6293e)

Co-authored-by: Manasvini B Suryanarayana <[email protected]>
kavilla pushed a commit that referenced this issue Jul 5, 2022
… main (#1799) (#1830)

Resolves issue - #1687

Signed-off-by: Manasvini B Suryanarayana <[email protected]>
(cherry picked from commit 2e6293e)

Co-authored-by: Manasvini B Suryanarayana <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants