Skip to content

Commit

Permalink
Merge branch 'master' into actions/rename-getProxyAgents
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 1, 2021
2 parents 8312283 + 51cfa90 commit ca8300a
Show file tree
Hide file tree
Showing 106 changed files with 2,677 additions and 772 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Configuration options to be used to create a [cluster client](./kibana-plugin-co
<b>Signature:</b>

```typescript
export declare type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'logQueries' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password'> & {
export declare type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password'> & {
pingTimeout?: ElasticsearchConfig['pingTimeout'] | ClientOptions['pingTimeout'];
requestTimeout?: ElasticsearchConfig['requestTimeout'] | ClientOptions['requestTimeout'];
ssl?: Partial<ElasticsearchConfig['ssl']>;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export declare class ElasticsearchConfig
| [healthCheckDelay](./kibana-plugin-core-server.elasticsearchconfig.healthcheckdelay.md) | | <code>Duration</code> | The interval between health check requests Kibana sends to the Elasticsearch. |
| [hosts](./kibana-plugin-core-server.elasticsearchconfig.hosts.md) | | <code>string[]</code> | Hosts that the client will connect to. If sniffing is enabled, this list will be used as seeds to discover the rest of your cluster. |
| [ignoreVersionMismatch](./kibana-plugin-core-server.elasticsearchconfig.ignoreversionmismatch.md) | | <code>boolean</code> | Whether to allow kibana to connect to a non-compatible elasticsearch node. |
| [logQueries](./kibana-plugin-core-server.elasticsearchconfig.logqueries.md) | | <code>boolean</code> | Specifies whether all queries to the client should be logged (status code, method, query etc.). |
| [password](./kibana-plugin-core-server.elasticsearchconfig.password.md) | | <code>string</code> | If Elasticsearch is protected with basic authentication, this setting provides the password that the Kibana server uses to perform its administrative functions. |
| [pingTimeout](./kibana-plugin-core-server.elasticsearchconfig.pingtimeout.md) | | <code>Duration</code> | Timeout after which PING HTTP request will be aborted and retried. |
| [requestHeadersWhitelist](./kibana-plugin-core-server.elasticsearchconfig.requestheaderswhitelist.md) | | <code>string[]</code> | List of Kibana client-side headers to send to Elasticsearch when request scoped cluster client is used. If this is an empty array then \*no\* client-side will be sent. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Constructs a new instance of the `LegacyClusterClient` class
<b>Signature:</b>

```typescript
constructor(config: LegacyElasticsearchClientConfig, log: Logger, getAuthHeaders?: GetAuthHeaders);
constructor(config: LegacyElasticsearchClientConfig, log: Logger, type: string, getAuthHeaders?: GetAuthHeaders);
```

## Parameters
Expand All @@ -18,5 +18,6 @@ constructor(config: LegacyElasticsearchClientConfig, log: Logger, getAuthHeaders
| --- | --- | --- |
| config | <code>LegacyElasticsearchClientConfig</code> | |
| log | <code>Logger</code> | |
| type | <code>string</code> | |
| getAuthHeaders | <code>GetAuthHeaders</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export declare class LegacyClusterClient implements ILegacyClusterClient
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(config, log, getAuthHeaders)](./kibana-plugin-core-server.legacyclusterclient._constructor_.md) | | Constructs a new instance of the <code>LegacyClusterClient</code> class |
| [(constructor)(config, log, type, getAuthHeaders)](./kibana-plugin-core-server.legacyclusterclient._constructor_.md) | | Constructs a new instance of the <code>LegacyClusterClient</code> class |
## Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<b>Signature:</b>

```typescript
export declare type LegacyElasticsearchClientConfig = Pick<ConfigOptions, 'keepAlive' | 'log' | 'plugins'> & Pick<ElasticsearchConfig, 'apiVersion' | 'customHeaders' | 'logQueries' | 'requestHeadersWhitelist' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'hosts' | 'username' | 'password'> & {
export declare type LegacyElasticsearchClientConfig = Pick<ConfigOptions, 'keepAlive' | 'log' | 'plugins'> & Pick<ElasticsearchConfig, 'apiVersion' | 'customHeaders' | 'requestHeadersWhitelist' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'hosts' | 'username' | 'password'> & {
pingTimeout?: ElasticsearchConfig['pingTimeout'] | ConfigOptions['pingTimeout'];
requestTimeout?: ElasticsearchConfig['requestTimeout'] | ConfigOptions['requestTimeout'];
sniffInterval?: ElasticsearchConfig['sniffInterval'] | ConfigOptions['sniffInterval'];
Expand Down
2 changes: 1 addition & 1 deletion docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ To enable SSL/TLS for outbound connections to {es}, use the `https` protocol
in this setting.

| `elasticsearch.logQueries:`
| Log queries sent to {es}. Requires <<logging-verbose, `logging.verbose`>> set to `true`.
| *deprecated* This setting is no longer used and will get removed in Kibana 8.0. Instead, set <<logging-verbose, `logging.verbose`>> to `true`
This is useful for seeing the query DSL generated by applications that
currently do not have an inspector, for example Timelion and Monitoring.
*Default: `false`*
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ exports.Cluster = class Cluster {
this._log.info(chalk.bold('Starting'));
this._log.indent(4);

const esArgs = ['indices.query.bool.max_nested_depth=100'].concat(options.esArgs || []);
const esArgs = options.esArgs || [];

// Add to esArgs if ssl is enabled
if (this._ssl) {
Expand Down
8 changes: 2 additions & 6 deletions packages/kbn-es/src/integration_tests/cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ describe('#start(installPath)', () => {
expect(extractConfigFiles.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"indices.query.bool.max_nested_depth=100",
],
Array [],
undefined,
Object {
"log": <ToolingLog>,
Expand Down Expand Up @@ -342,9 +340,7 @@ describe('#run()', () => {
expect(extractConfigFiles.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"indices.query.bool.max_nested_depth=100",
],
Array [],
undefined,
Object {
"log": <ToolingLog>,
Expand Down
1 change: 0 additions & 1 deletion src/core/server/elasticsearch/client/client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const createConfig = (
): ElasticsearchClientConfig => {
return {
customHeaders: {},
logQueries: false,
sniffOnStart: false,
sniffOnConnectionFault: false,
sniffInterval: false,
Expand Down
1 change: 0 additions & 1 deletion src/core/server/elasticsearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { DEFAULT_HEADERS } from '../default_headers';
export type ElasticsearchClientConfig = Pick<
ElasticsearchConfig,
| 'customHeaders'
| 'logQueries'
| 'sniffOnStart'
| 'sniffOnConnectionFault'
| 'requestHeadersWhitelist'
Expand Down
84 changes: 61 additions & 23 deletions src/core/server/elasticsearch/client/cluster_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const createConfig = (
parts: Partial<ElasticsearchClientConfig> = {}
): ElasticsearchClientConfig => {
return {
logQueries: false,
sniffOnStart: false,
sniffOnConnectionFault: false,
sniffInterval: false,
Expand Down Expand Up @@ -57,24 +56,38 @@ describe('ClusterClient', () => {
it('creates a single internal and scoped client during initialization', () => {
const config = createConfig();

new ClusterClient(config, logger, getAuthHeaders);
new ClusterClient(config, logger, 'custom-type', getAuthHeaders);

expect(configureClientMock).toHaveBeenCalledTimes(2);
expect(configureClientMock).toHaveBeenCalledWith(config, { logger });
expect(configureClientMock).toHaveBeenCalledWith(config, { logger, scoped: true });
expect(configureClientMock).toHaveBeenCalledWith(config, { logger, type: 'custom-type' });
expect(configureClientMock).toHaveBeenCalledWith(config, {
logger,
type: 'custom-type',
scoped: true,
});
});

describe('#asInternalUser', () => {
it('returns the internal client', () => {
const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders);
const clusterClient = new ClusterClient(
createConfig(),
logger,
'custom-type',
getAuthHeaders
);

expect(clusterClient.asInternalUser).toBe(internalClient);
});
});

describe('#asScoped', () => {
it('returns a scoped cluster client bound to the request', () => {
const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders);
const clusterClient = new ClusterClient(
createConfig(),
logger,
'custom-type',
getAuthHeaders
);
const request = httpServerMock.createKibanaRequest();

const scopedClusterClient = clusterClient.asScoped(request);
Expand All @@ -87,7 +100,12 @@ describe('ClusterClient', () => {
});

it('returns a distinct scoped cluster client on each call', () => {
const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders);
const clusterClient = new ClusterClient(
createConfig(),
logger,
'custom-type',
getAuthHeaders
);
const request = httpServerMock.createKibanaRequest();

const scopedClusterClient1 = clusterClient.asScoped(request);
Expand All @@ -105,7 +123,7 @@ describe('ClusterClient', () => {
});
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({
headers: {
foo: 'bar',
Expand All @@ -130,7 +148,7 @@ describe('ClusterClient', () => {
other: 'nope',
});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({});

clusterClient.asScoped(request);
Expand All @@ -150,7 +168,7 @@ describe('ClusterClient', () => {
other: 'nope',
});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({
headers: {
authorization: 'override',
Expand All @@ -175,7 +193,7 @@ describe('ClusterClient', () => {
});
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({});

clusterClient.asScoped(request);
Expand All @@ -195,7 +213,7 @@ describe('ClusterClient', () => {
const config = createConfig();
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({
kibanaRequestState: { requestId: 'my-fake-id', requestUuid: 'ignore-this-id' },
});
Expand Down Expand Up @@ -223,7 +241,7 @@ describe('ClusterClient', () => {
foo: 'auth',
});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({});

clusterClient.asScoped(request);
Expand All @@ -249,7 +267,7 @@ describe('ClusterClient', () => {
});
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({
headers: { foo: 'request' },
});
Expand All @@ -276,7 +294,7 @@ describe('ClusterClient', () => {
});
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest();

clusterClient.asScoped(request);
Expand All @@ -297,7 +315,7 @@ describe('ClusterClient', () => {
});
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({
headers: { [headerKey]: 'foo' },
});
Expand All @@ -321,7 +339,7 @@ describe('ClusterClient', () => {
});
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = httpServerMock.createKibanaRequest({
headers: { foo: 'request' },
kibanaRequestState: { requestId: 'from request', requestUuid: 'ignore-this-id' },
Expand All @@ -344,7 +362,7 @@ describe('ClusterClient', () => {
});
getAuthHeaders.mockReturnValue({});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = {
headers: {
authorization: 'auth',
Expand All @@ -368,7 +386,7 @@ describe('ClusterClient', () => {
authorization: 'auth',
});

const clusterClient = new ClusterClient(config, logger, getAuthHeaders);
const clusterClient = new ClusterClient(config, logger, 'custom-type', getAuthHeaders);
const request = {
headers: {
foo: 'bar',
Expand All @@ -387,7 +405,12 @@ describe('ClusterClient', () => {

describe('#close', () => {
it('closes both underlying clients', async () => {
const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders);
const clusterClient = new ClusterClient(
createConfig(),
logger,
'custom-type',
getAuthHeaders
);

await clusterClient.close();

Expand All @@ -398,7 +421,12 @@ describe('ClusterClient', () => {
it('waits for both clients to close', async (done) => {
expect.assertions(4);

const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders);
const clusterClient = new ClusterClient(
createConfig(),
logger,
'custom-type',
getAuthHeaders
);

let internalClientClosed = false;
let scopedClientClosed = false;
Expand Down Expand Up @@ -436,7 +464,12 @@ describe('ClusterClient', () => {
});

it('return a rejected promise is any client rejects', async () => {
const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders);
const clusterClient = new ClusterClient(
createConfig(),
logger,
'custom-type',
getAuthHeaders
);

internalClient.close.mockRejectedValue(new Error('error closing client'));

Expand All @@ -446,7 +479,12 @@ describe('ClusterClient', () => {
});

it('does nothing after the first call', async () => {
const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders);
const clusterClient = new ClusterClient(
createConfig(),
logger,
'custom-type',
getAuthHeaders
);

await clusterClient.close();

Expand Down
5 changes: 3 additions & 2 deletions src/core/server/elasticsearch/client/cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ export class ClusterClient implements ICustomClusterClient {
constructor(
private readonly config: ElasticsearchClientConfig,
logger: Logger,
type: string,
private readonly getAuthHeaders: GetAuthHeaders = noop
) {
this.asInternalUser = configureClient(config, { logger });
this.rootScopedClient = configureClient(config, { logger, scoped: true });
this.asInternalUser = configureClient(config, { logger, type });
this.rootScopedClient = configureClient(config, { logger, type, scoped: true });
}

asScoped(request: ScopeableRequest) {
Expand Down
Loading

0 comments on commit ca8300a

Please sign in to comment.