-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Introduce Elasticsearch service. #28344
Merged
azasypkin
merged 46 commits into
elastic:master
from
azasypkin:issue-18841-core-es-server
Feb 28, 2019
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
aded160
Introduce Elasticsearch service.
azasypkin f2d353c
Move config parsing and logging to the core.
azasypkin 7cfbd46
Migrate more code to new `createClister`.
azasypkin 80c55b6
Remove redundant `esRequestTimeout` and `esApiVersion` injected UI va…
azasypkin 5e36d57
Introduce ScopedClusterClient.
azasypkin bf37868
Add docs for the cluster clients.
azasypkin 536f7d4
Switch back to observables.
azasypkin a001ca5
Fix reporting.
azasypkin b1ff21f
Merge branch 'master' into issue-18841-core-es-server
azasypkin 1efb49b
Merge branch 'master' into issue-18841-core-es-server
azasypkin 35af3fb
Merge branch 'master' into issue-18841-core-es-server
azasypkin 00c27a5
Merge branch 'master' into issue-18841-core-es-server
azasypkin ed7824c
Rollback config deprecation handling code from core.
azasypkin c86648a
Get rid of `loggerContext` on ES config. Switch monitoring logging ta…
azasypkin 0dfb081
Use `elasticsearch` instead of `es`.
azasypkin 38ee25d
Make elasticsearch available to plugins.
azasypkin 6fb8436
Fix @kbn/config-schema tests.
azasypkin 884a301
Add `elasticsearch_client_config` parser tests.
azasypkin 9c22b2c
Merge branch 'master' into issue-18841-core-es-server
azasypkin 808bef2
Merge branch 'master' into issue-18841-core-es-server
azasypkin a03fe15
Add JSDocs and tests for `ElasticsearchConfig`.
azasypkin 8d93aca
Merge branch 'master' into issue-18841-core-es-server
azasypkin 433c1b3
Add `ClusterClient` tests.
azasypkin fe18972
Patch new metrics code that depends on `elasticsearch` config.
azasypkin dff904c
Rename `bwc` from ES service start contract to `legacy`.
azasypkin 3d2259c
Add `ScopedClusterClient` tests.
azasypkin 3b3e6ed
Fix `LegacyService` tests.
azasypkin 6903641
Add `ElasticsearchService` tests.
azasypkin 9809342
Fix plugin tests.
azasypkin 3ec803d
Fix remaining core tests.
azasypkin 329d777
Cleanup.
azasypkin b27e89a
Fix legacy tests.
azasypkin 2dca5f5
Merge branch 'master' into issue-18841-core-es-server
azasypkin bb1b0b2
Fix x-pack legacy tests.
azasypkin 66694bd
Clone ES config.
azasypkin 8d0538f
Merge branch 'master' into issue-18841-core-es-server
azasypkin eb5d27c
Handle latest conflicting changes from upstream.
azasypkin d3307ff
Review №2: tweak tests, clone client config if SSL part is not provid…
azasypkin fcc01be
Merge branch 'master' into issue-18841-core-es-server
azasypkin 678c383
Merge branch 'master' into issue-18841-core-es-server
azasypkin 1980439
Review №3: use `hasOwnProperty` in `utils.pick` + fixed other nits.
azasypkin e8b5bbe
Merge branch 'master' into issue-18841-core-es-server
azasypkin ae0e742
Merge branch 'master' into issue-18841-core-es-server
azasypkin 0af2ede
Merge branch 'master' into issue-18841-core-es-server
azasypkin b09ef5f
Merge branch 'master' into issue-18841-core-es-server
azasypkin c236a63
Review №4: fix typo in test name.
azasypkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/kbn-config-schema/src/types/__snapshots__/uri_type.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`#scheme returns error when shorter string 1`] = `"expected URI with scheme [http|https] but but got [ftp://elastic.co]."`; | ||
|
||
exports[`#scheme returns error when shorter string 2`] = `"expected URI with scheme [http|https] but but got [file:///kibana.log]."`; | ||
|
||
exports[`#validate throws when returns string 1`] = `"validator failure"`; | ||
|
||
exports[`is required by default 1`] = `"expected value of type [string] but got [undefined]."`; | ||
|
||
exports[`returns error when not string 1`] = `"expected value of type [string] but got [number]."`; | ||
|
||
exports[`returns error when not string 2`] = `"expected value of type [string] but got [Array]."`; | ||
|
||
exports[`returns error when not string 3`] = `"expected value of type [string] but got [RegExp]."`; | ||
|
||
exports[`returns error when value is not a URI 1`] = `"value is [3domain.local] but it must be a valid URI (see RFC 3986)."`; | ||
|
||
exports[`returns error when value is not a URI 2`] = `"value is [http://8010:0:0:0:9:500:300C:200A] but it must be a valid URI (see RFC 3986)."`; | ||
|
||
exports[`returns error when value is not a URI 3`] = `"value is [-] but it must be a valid URI (see RFC 3986)."`; | ||
|
||
exports[`returns error when value is not a URI 4`] = `"value is [https://example.com?baz[]=foo&baz[]=bar] but it must be a valid URI (see RFC 3986)."`; | ||
|
||
exports[`returns error when value is not a URI 5`] = `"value is [http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] but it must be a valid URI (see RFC 3986)."`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { schema } from '..'; | ||
|
||
test('is required by default', () => { | ||
expect(() => schema.uri().validate(undefined)).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('returns value for valid URI as per RFC3986', () => { | ||
const uriSchema = schema.uri(); | ||
|
||
expect(uriSchema.validate('http://tools.ietf.org/html/rfc3986')).toBe( | ||
'http://tools.ietf.org/html/rfc3986' | ||
); | ||
expect(uriSchema.validate('udp://3domain.local')).toBe('udp://3domain.local'); | ||
expect(uriSchema.validate('urn:elastic:kibana')).toBe('urn:elastic:kibana'); | ||
expect(uriSchema.validate('ftp://ftp.ietf.org/rfc/rfc3986.txt')).toBe( | ||
'ftp://ftp.ietf.org/rfc/rfc3986.txt' | ||
); | ||
expect(uriSchema.validate('mailto:Platform.Kibana@elastic.co')).toBe( | ||
'mailto:Platform.Kibana@elastic.co' | ||
); | ||
expect(uriSchema.validate('tel:+500-111-222-333')).toBe('tel:+500-111-222-333'); | ||
expect(uriSchema.validate('file:///kibana.log')).toBe('file:///kibana.log'); | ||
expect(uriSchema.validate('http://elastic@localhost:9200')).toBe('http://elastic@localhost:9200'); | ||
expect(uriSchema.validate('http://elastic:changeme@localhost:9200')).toBe( | ||
'http://elastic:changeme@localhost:9200' | ||
); | ||
expect(uriSchema.validate('ldap://[2001:db8::7]/c=GB?objectClass?one')).toBe( | ||
'ldap://[2001:db8::7]/c=GB?objectClass?one' | ||
); | ||
|
||
const uriWithMaxAllowedLength = `http://${'a'.repeat(255)}`; | ||
expect(uriSchema.validate(uriWithMaxAllowedLength)).toBe(uriWithMaxAllowedLength); | ||
}); | ||
|
||
test('returns error when value is not a URI', () => { | ||
const uriSchema = schema.uri(); | ||
|
||
expect(() => uriSchema.validate('3domain.local')).toThrowErrorMatchingSnapshot(); | ||
expect(() => | ||
uriSchema.validate('http://8010:0:0:0:9:500:300C:200A') | ||
).toThrowErrorMatchingSnapshot(); | ||
expect(() => uriSchema.validate('-')).toThrowErrorMatchingSnapshot(); | ||
expect(() => | ||
uriSchema.validate('https://example.com?baz[]=foo&baz[]=bar') | ||
).toThrowErrorMatchingSnapshot(); | ||
|
||
const tooLongUri = `http://${'a'.repeat(256)}`; | ||
expect(() => uriSchema.validate(tooLongUri)).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
describe('#scheme', () => { | ||
test('returns value when URI has required scheme', () => { | ||
const uriSchema = schema.uri({ scheme: ['http', 'https'] }); | ||
|
||
expect(uriSchema.validate('http://elastic.co')).toBe('http://elastic.co'); | ||
expect(uriSchema.validate('https://elastic.co')).toBe('https://elastic.co'); | ||
}); | ||
|
||
test('returns error when shorter string', () => { | ||
const uriSchema = schema.uri({ scheme: ['http', 'https'] }); | ||
|
||
expect(() => uriSchema.validate('ftp://elastic.co')).toThrowErrorMatchingSnapshot(); | ||
expect(() => uriSchema.validate('file:///kibana.log')).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('#defaultValue', () => { | ||
test('returns default when URI is undefined', () => { | ||
expect(schema.uri({ defaultValue: 'http://localhost:9200' }).validate(undefined)).toBe( | ||
'http://localhost:9200' | ||
); | ||
}); | ||
|
||
test('returns value when specified', () => { | ||
expect( | ||
schema.uri({ defaultValue: 'http://localhost:9200' }).validate('http://kibana.local') | ||
).toBe('http://kibana.local'); | ||
}); | ||
|
||
test('returns value from context when context reference is specified', () => { | ||
expect( | ||
schema.uri({ defaultValue: schema.contextRef('some_uri') }).validate(undefined, { | ||
some_uri: 'http://kibana.local', | ||
}) | ||
).toBe('http://kibana.local'); | ||
}); | ||
}); | ||
|
||
describe('#validate', () => { | ||
test('is called with input value', () => { | ||
let calledWith; | ||
|
||
const validator = (val: any) => { | ||
calledWith = val; | ||
}; | ||
|
||
schema.uri({ validate: validator }).validate('http://kibana.local'); | ||
|
||
expect(calledWith).toBe('http://kibana.local'); | ||
}); | ||
|
||
test('is not called with default value in no input', () => { | ||
const validate = jest.fn(); | ||
|
||
schema.uri({ validate, defaultValue: 'http://kibana.local' }).validate(undefined); | ||
|
||
expect(validate).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('throws when returns string', () => { | ||
const validate = () => 'validator failure'; | ||
|
||
expect(() => | ||
schema.uri({ validate }).validate('http://kibana.local') | ||
).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
test('returns error when not string', () => { | ||
expect(() => schema.uri().validate(123)).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => schema.uri().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => schema.uri().validate(/abc/)).toThrowErrorMatchingSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import typeDetect from 'type-detect'; | ||
import { internals } from '../internals'; | ||
import { Type, TypeOptions } from './type'; | ||
|
||
export type URIOptions = TypeOptions<string> & { | ||
scheme?: string | string[]; | ||
}; | ||
|
||
export class URIType extends Type<string> { | ||
constructor(options: URIOptions = {}) { | ||
super(internals.string().uri({ scheme: options.scheme }), options); | ||
} | ||
|
||
protected handleError(type: string, { value, scheme }: Record<string, unknown>) { | ||
switch (type) { | ||
case 'any.required': | ||
epixa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case 'string.base': | ||
return `expected value of type [string] but got [${typeDetect(value)}].`; | ||
case 'string.uriCustomScheme': | ||
return `expected URI with scheme [${scheme}] but but got [${value}].`; | ||
case 'string.uri': | ||
return `value is [${value}] but it must be a valid URI (see RFC 3986).`; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.