Skip to content

Commit 12f2049

Browse files
committed
Merge branch 'master' into alerting/consumer-based-rbac
* master: Rename legacy ES mock accessors (elastic#70432) [APM] Adds 'Anomaly detection' settings page to create ML jobs per environment (elastic#70560) Forbid timezones not working in Elasticsearch (elastic#70780)
2 parents 23dafe8 + 648468d commit 12f2049

File tree

82 files changed

+1196
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1196
-318
lines changed

src/core/server/elasticsearch/elasticsearch_service.mock.ts

Lines changed: 20 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,14 @@
1818
*/
1919

2020
import { BehaviorSubject } from 'rxjs';
21-
import { Client } from 'elasticsearch';
22-
import {
23-
ILegacyClusterClient,
24-
ILegacyCustomClusterClient,
25-
ILegacyScopedClusterClient,
26-
} from './legacy';
21+
import { ILegacyClusterClient, ILegacyCustomClusterClient } from './legacy';
22+
import { legacyClientMock } from './legacy/mocks';
2723
import { ElasticsearchConfig } from './elasticsearch_config';
2824
import { ElasticsearchService } from './elasticsearch_service';
2925
import { InternalElasticsearchServiceSetup, ElasticsearchStatusMeta } from './types';
3026
import { NodesVersionCompatibility } from './version_check/ensure_es_version';
3127
import { ServiceStatus, ServiceStatusLevels } from '../status';
3228

33-
const createScopedClusterClientMock = (): jest.Mocked<ILegacyScopedClusterClient> => ({
34-
callAsInternalUser: jest.fn(),
35-
callAsCurrentUser: jest.fn(),
36-
});
37-
38-
const createCustomClusterClientMock = (): jest.Mocked<ILegacyCustomClusterClient> => ({
39-
...createClusterClientMock(),
40-
close: jest.fn(),
41-
});
42-
43-
function createClusterClientMock() {
44-
const client: jest.Mocked<ILegacyClusterClient> = {
45-
callAsInternalUser: jest.fn(),
46-
asScoped: jest.fn(),
47-
};
48-
client.asScoped.mockReturnValue(createScopedClusterClientMock());
49-
return client;
50-
}
51-
5229
interface MockedElasticSearchServiceSetup {
5330
legacy: {
5431
createClient: jest.Mock<ILegacyCustomClusterClient, any>;
@@ -60,11 +37,13 @@ const createSetupContractMock = () => {
6037
const setupContract: MockedElasticSearchServiceSetup = {
6138
legacy: {
6239
createClient: jest.fn(),
63-
client: createClusterClientMock(),
40+
client: legacyClientMock.createClusterClient(),
6441
},
6542
};
66-
setupContract.legacy.createClient.mockReturnValue(createCustomClusterClientMock());
67-
setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
43+
setupContract.legacy.createClient.mockReturnValue(legacyClientMock.createCustomClusterClient());
44+
setupContract.legacy.client.asScoped.mockReturnValue(
45+
legacyClientMock.createScopedClusterClient()
46+
);
6847
return setupContract;
6948
};
7049

@@ -74,11 +53,14 @@ const createStartContractMock = () => {
7453
const startContract: MockedElasticSearchServiceStart = {
7554
legacy: {
7655
createClient: jest.fn(),
77-
client: createClusterClientMock(),
56+
client: legacyClientMock.createClusterClient(),
7857
},
7958
};
80-
startContract.legacy.createClient.mockReturnValue(createCustomClusterClientMock());
81-
startContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
59+
startContract.legacy.createClient.mockReturnValue(legacyClientMock.createCustomClusterClient());
60+
startContract.legacy.client.asScoped.mockReturnValue(
61+
legacyClientMock.createScopedClusterClient()
62+
);
63+
8264
return startContract;
8365
};
8466

@@ -104,7 +86,9 @@ const createInternalSetupContractMock = () => {
10486
...createSetupContractMock().legacy,
10587
},
10688
};
107-
setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
89+
setupContract.legacy.client.asScoped.mockReturnValue(
90+
legacyClientMock.createScopedClusterClient()
91+
);
10892
return setupContract;
10993
};
11094

@@ -121,62 +105,13 @@ const createMock = () => {
121105
return mocked;
122106
};
123107

124-
const createElasticsearchClientMock = () => {
125-
const mocked: jest.Mocked<Client> = {
126-
cat: {} as any,
127-
cluster: {} as any,
128-
indices: {} as any,
129-
ingest: {} as any,
130-
nodes: {} as any,
131-
snapshot: {} as any,
132-
tasks: {} as any,
133-
bulk: jest.fn(),
134-
clearScroll: jest.fn(),
135-
count: jest.fn(),
136-
create: jest.fn(),
137-
delete: jest.fn(),
138-
deleteByQuery: jest.fn(),
139-
deleteScript: jest.fn(),
140-
deleteTemplate: jest.fn(),
141-
exists: jest.fn(),
142-
explain: jest.fn(),
143-
fieldStats: jest.fn(),
144-
get: jest.fn(),
145-
getScript: jest.fn(),
146-
getSource: jest.fn(),
147-
getTemplate: jest.fn(),
148-
index: jest.fn(),
149-
info: jest.fn(),
150-
mget: jest.fn(),
151-
msearch: jest.fn(),
152-
msearchTemplate: jest.fn(),
153-
mtermvectors: jest.fn(),
154-
ping: jest.fn(),
155-
putScript: jest.fn(),
156-
putTemplate: jest.fn(),
157-
reindex: jest.fn(),
158-
reindexRethrottle: jest.fn(),
159-
renderSearchTemplate: jest.fn(),
160-
scroll: jest.fn(),
161-
search: jest.fn(),
162-
searchShards: jest.fn(),
163-
searchTemplate: jest.fn(),
164-
suggest: jest.fn(),
165-
termvectors: jest.fn(),
166-
update: jest.fn(),
167-
updateByQuery: jest.fn(),
168-
close: jest.fn(),
169-
};
170-
return mocked;
171-
};
172-
173108
export const elasticsearchServiceMock = {
174109
create: createMock,
175110
createInternalSetup: createInternalSetupContractMock,
176111
createSetup: createSetupContractMock,
177112
createStart: createStartContractMock,
178-
createClusterClient: createClusterClientMock,
179-
createCustomClusterClient: createCustomClusterClientMock,
180-
createScopedClusterClient: createScopedClusterClientMock,
181-
createElasticsearchClient: createElasticsearchClientMock,
113+
createLegacyClusterClient: legacyClientMock.createClusterClient,
114+
createLegacyCustomClusterClient: legacyClientMock.createCustomClusterClient,
115+
createLegacyScopedClusterClient: legacyClientMock.createScopedClusterClient,
116+
createLegacyElasticsearchClient: legacyClientMock.createElasticsearchClient,
182117
};

src/core/server/elasticsearch/elasticsearch_service.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('#setup', () => {
7575
});
7676

7777
it('returns elasticsearch client as a part of the contract', async () => {
78-
const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient();
78+
const mockClusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient();
7979
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);
8080

8181
const setupContract = await elasticsearchService.setup(deps);
@@ -209,7 +209,7 @@ describe('#setup', () => {
209209
});
210210

211211
it('esNodeVersionCompatibility$ only starts polling when subscribed to', async (done) => {
212-
const clusterClientInstance = elasticsearchServiceMock.createClusterClient();
212+
const clusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient();
213213
MockClusterClient.mockImplementationOnce(() => clusterClientInstance);
214214

215215
clusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());
@@ -225,7 +225,7 @@ describe('#setup', () => {
225225
});
226226

227227
it('esNodeVersionCompatibility$ stops polling when unsubscribed from', async (done) => {
228-
const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient();
228+
const mockClusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient();
229229
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);
230230

231231
mockClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());
@@ -255,7 +255,7 @@ describe('#stop', () => {
255255

256256
it('stops pollEsNodeVersions even if there are active subscriptions', async (done) => {
257257
expect.assertions(2);
258-
const mockClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient();
258+
const mockClusterClientInstance = elasticsearchServiceMock.createLegacyCustomClusterClient();
259259

260260
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);
261261

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Client } from 'elasticsearch';
21+
import { ILegacyScopedClusterClient } from './scoped_cluster_client';
22+
import { ILegacyClusterClient, ILegacyCustomClusterClient } from './cluster_client';
23+
24+
const createScopedClusterClientMock = (): jest.Mocked<ILegacyScopedClusterClient> => ({
25+
callAsInternalUser: jest.fn(),
26+
callAsCurrentUser: jest.fn(),
27+
});
28+
29+
const createCustomClusterClientMock = (): jest.Mocked<ILegacyCustomClusterClient> => ({
30+
...createClusterClientMock(),
31+
close: jest.fn(),
32+
});
33+
34+
function createClusterClientMock() {
35+
const client: jest.Mocked<ILegacyClusterClient> = {
36+
callAsInternalUser: jest.fn(),
37+
asScoped: jest.fn(),
38+
};
39+
client.asScoped.mockReturnValue(createScopedClusterClientMock());
40+
return client;
41+
}
42+
43+
const createElasticsearchClientMock = () => {
44+
const mocked: jest.Mocked<Client> = {
45+
cat: {} as any,
46+
cluster: {} as any,
47+
indices: {} as any,
48+
ingest: {} as any,
49+
nodes: {} as any,
50+
snapshot: {} as any,
51+
tasks: {} as any,
52+
bulk: jest.fn(),
53+
clearScroll: jest.fn(),
54+
count: jest.fn(),
55+
create: jest.fn(),
56+
delete: jest.fn(),
57+
deleteByQuery: jest.fn(),
58+
deleteScript: jest.fn(),
59+
deleteTemplate: jest.fn(),
60+
exists: jest.fn(),
61+
explain: jest.fn(),
62+
fieldStats: jest.fn(),
63+
get: jest.fn(),
64+
getScript: jest.fn(),
65+
getSource: jest.fn(),
66+
getTemplate: jest.fn(),
67+
index: jest.fn(),
68+
info: jest.fn(),
69+
mget: jest.fn(),
70+
msearch: jest.fn(),
71+
msearchTemplate: jest.fn(),
72+
mtermvectors: jest.fn(),
73+
ping: jest.fn(),
74+
putScript: jest.fn(),
75+
putTemplate: jest.fn(),
76+
reindex: jest.fn(),
77+
reindexRethrottle: jest.fn(),
78+
renderSearchTemplate: jest.fn(),
79+
scroll: jest.fn(),
80+
search: jest.fn(),
81+
searchShards: jest.fn(),
82+
searchTemplate: jest.fn(),
83+
suggest: jest.fn(),
84+
termvectors: jest.fn(),
85+
update: jest.fn(),
86+
updateByQuery: jest.fn(),
87+
close: jest.fn(),
88+
};
89+
return mocked;
90+
};
91+
92+
export const legacyClientMock = {
93+
createScopedClusterClient: createScopedClusterClientMock,
94+
createCustomClusterClient: createCustomClusterClientMock,
95+
createClusterClient: createClusterClientMock,
96+
createElasticsearchClient: createElasticsearchClientMock,
97+
};

src/core/server/http/integration_tests/core_service.test.mocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { elasticsearchServiceMock } from '../../elasticsearch/elasticsearch_serv
2121
export const clusterClientMock = jest.fn();
2222
jest.doMock('../../elasticsearch/legacy/scoped_cluster_client', () => ({
2323
LegacyScopedClusterClient: clusterClientMock.mockImplementation(function () {
24-
return elasticsearchServiceMock.createScopedClusterClient();
24+
return elasticsearchServiceMock.createLegacyScopedClusterClient();
2525
}),
2626
}));
2727

@@ -31,7 +31,7 @@ jest.doMock('elasticsearch', () => {
3131
...realES,
3232
// eslint-disable-next-line object-shorthand
3333
Client: function () {
34-
return elasticsearchServiceMock.createElasticsearchClient();
34+
return elasticsearchServiceMock.createLegacyElasticsearchClient();
3535
},
3636
};
3737
});

src/core/server/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function createCoreRequestHandlerContextMock() {
190190
},
191191
elasticsearch: {
192192
legacy: {
193-
client: elasticsearchServiceMock.createScopedClusterClient(),
193+
client: elasticsearchServiceMock.createLegacyScopedClusterClient(),
194194
},
195195
},
196196
uiSettings: {

src/legacy/core_plugins/kibana/server/ui_setting_defaults.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ export function getUiSettingDefaults() {
101101
},
102102
}),
103103
type: 'select',
104-
options: ['Browser', ...moment.tz.names()],
104+
options: [
105+
'Browser',
106+
...moment.tz
107+
.names()
108+
// We need to filter out some time zones, that moment.js knows about, but Elasticsearch
109+
// does not understand and would fail thus with a 400 bad request when using them.
110+
.filter((tz) => !['America/Nuuk', 'EST', 'HST', 'ROC', 'MST'].includes(tz)),
111+
],
105112
requiresPageReload: true,
106113
},
107114
'dateFormat:scaled': {

test/functional/apps/dashboard/time_zones.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function ({ getService, getPageObjects }) {
6565
it('Changing timezone changes dashboard timestamp and shows the same data', async () => {
6666
await PageObjects.settings.navigateTo();
6767
await PageObjects.settings.clickKibanaSettings();
68-
await PageObjects.settings.setAdvancedSettingsSelect('dateFormat:tz', 'EST');
68+
await PageObjects.settings.setAdvancedSettingsSelect('dateFormat:tz', 'Etc/GMT+5');
6969
await PageObjects.common.navigateToApp('dashboard');
7070
await PageObjects.dashboard.loadSavedDashboard('time zone test');
7171
const time = await PageObjects.timePicker.getTimeConfigAsAbsoluteTimes();

x-pack/plugins/actions/server/actions_client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { KibanaRequest } from 'kibana/server';
2525

2626
const defaultKibanaIndex = '.kibana';
2727
const savedObjectsClient = savedObjectsClientMock.create();
28-
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
28+
const scopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
2929
const actionExecutor = actionExecutorMock.create();
3030
const executionEnqueuer = jest.fn();
3131
const request = {} as KibanaRequest;

x-pack/plugins/actions/server/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const createServicesMock = () => {
3737
savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;
3838
}
3939
> = {
40-
callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser,
40+
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
4141
getScopedCallCluster: jest.fn(),
4242
savedObjectsClient: savedObjectsClientMock.create(),
4343
};

x-pack/plugins/alerts/server/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const createAlertServicesMock = () => {
5858
alertInstanceFactory: jest
5959
.fn<jest.Mocked<AlertInstance>, [string]>()
6060
.mockReturnValue(alertInstanceFactoryMock),
61-
callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser,
61+
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
6262
getScopedCallCluster: jest.fn(),
6363
savedObjectsClient: savedObjectsClientMock.create(),
6464
};

0 commit comments

Comments
 (0)