Skip to content

Commit b573500

Browse files
committed
Merge branch 'master' of github.com:elastic/kibana into telemetry/merge-oss-and-xpack-collectors
2 parents 25d3da5 + 3d9eb2a commit b573500

File tree

67 files changed

+1038
-239
lines changed

Some content is hidden

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

67 files changed

+1038
-239
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
"leaflet.heat": "0.2.0",
206206
"less": "^2.7.3",
207207
"less-loader": "5.0.0",
208-
"lodash": "npm:@elastic/[email protected]kibana3",
208+
"lodash": "npm:@elastic/[email protected]kibana4",
209209
"lodash.clonedeep": "^4.5.0",
210210
"lru-cache": "4.1.5",
211211
"markdown-it": "^10.0.0",

packages/kbn-interpreter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@babel/runtime": "^7.5.5",
1313
"@kbn/i18n": "1.0.0",
14-
"lodash": "npm:@elastic/[email protected]kibana3",
14+
"lodash": "npm:@elastic/[email protected]kibana4",
1515
"lodash.clone": "^4.5.0",
1616
"uuid": "3.3.2"
1717
},

packages/kbn-optimizer/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
// cache buster - https://github.com/elastic/kibana/issues/58077 - 1
2120
export { OptimizerConfig } from './optimizer';
2221
export * from './run_optimizer';
2322
export * from './log_optimizer_state';

packages/kbn-optimizer/src/optimizer/cache_keys.test.ts

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,35 @@
1717
* under the License.
1818
*/
1919

20+
import Path from 'path';
21+
2022
import jestDiff from 'jest-diff';
2123
import { REPO_ROOT, createAbsolutePathSerializer } from '@kbn/dev-utils';
2224

2325
import { reformatJestDiff, getOptimizerCacheKey, diffCacheKey } from './cache_keys';
2426
import { OptimizerConfig } from './optimizer_config';
2527

26-
jest.mock('./get_changes.ts');
28+
jest.mock('./get_changes.ts', () => ({
29+
getChanges: async () =>
30+
new Map([
31+
['/foo/bar/a', 'modified'],
32+
['/foo/bar/b', 'modified'],
33+
['/foo/bar/c', 'deleted'],
34+
]),
35+
}));
36+
37+
jest.mock('./get_mtimes.ts', () => ({
38+
getMtimes: async (paths: string[]) => new Map(paths.map(path => [path, 12345])),
39+
}));
40+
2741
jest.mock('execa');
42+
43+
jest.mock('fs', () => {
44+
const realFs = jest.requireActual('fs');
45+
jest.spyOn(realFs, 'readFile');
46+
return realFs;
47+
});
48+
2849
expect.addSnapshotSerializer(createAbsolutePathSerializer());
2950

3051
jest.requireMock('execa').mockImplementation(async (cmd: string, args: string[], opts: object) => {
@@ -46,28 +67,35 @@ jest.requireMock('execa').mockImplementation(async (cmd: string, args: string[],
4667
};
4768
});
4869

49-
jest.requireMock('./get_changes.ts').getChanges.mockImplementation(
50-
async () =>
51-
new Map([
52-
['/foo/bar/a', 'modified'],
53-
['/foo/bar/b', 'modified'],
54-
['/foo/bar/c', 'deleted'],
55-
])
56-
);
57-
5870
describe('getOptimizerCacheKey()', () => {
59-
it('uses latest commit and changes files to create unique value', async () => {
71+
it('uses latest commit, bootstrap cache, and changed files to create unique value', async () => {
72+
jest
73+
.requireMock('fs')
74+
.readFile.mockImplementation(
75+
(path: string, enc: string, cb: (err: null, file: string) => void) => {
76+
expect(path).toBe(
77+
Path.resolve(REPO_ROOT, 'packages/kbn-optimizer/target/.bootstrap-cache')
78+
);
79+
expect(enc).toBe('utf8');
80+
cb(null, '<bootstrap cache>');
81+
}
82+
);
83+
6084
const config = OptimizerConfig.create({
6185
repoRoot: REPO_ROOT,
6286
});
6387

6488
await expect(getOptimizerCacheKey(config)).resolves.toMatchInlineSnapshot(`
6589
Object {
90+
"bootstrap": "<bootstrap cache>",
6691
"deletedPaths": Array [
6792
"/foo/bar/c",
6893
],
6994
"lastCommit": "<last commit sha>",
70-
"modifiedPaths": Object {},
95+
"modifiedTimes": Object {
96+
"/foo/bar/a": 12345,
97+
"/foo/bar/b": 12345,
98+
},
7199
"workerConfig": Object {
72100
"browserslistEnv": "dev",
73101
"cache": true,

packages/kbn-optimizer/src/optimizer/cache_keys.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919

2020
import Path from 'path';
21+
import Fs from 'fs';
22+
import { promisify } from 'util';
2123

2224
import Chalk from 'chalk';
2325
import execa from 'execa';
@@ -116,9 +118,10 @@ export function reformatJestDiff(diff: string | null) {
116118

117119
export interface OptimizerCacheKey {
118120
readonly lastCommit: string | undefined;
121+
readonly bootstrap: string | undefined;
119122
readonly workerConfig: WorkerConfig;
120123
readonly deletedPaths: string[];
121-
readonly modifiedPaths: Record<string, number>;
124+
readonly modifiedTimes: Record<string, number>;
122125
}
123126

124127
async function getLastCommit() {
@@ -133,21 +136,45 @@ async function getLastCommit() {
133136
return stdout.trim() || undefined;
134137
}
135138

139+
async function getBootstrapCacheKey() {
140+
try {
141+
return await promisify(Fs.readFile)(
142+
Path.resolve(OPTIMIZER_DIR, 'target/.bootstrap-cache'),
143+
'utf8'
144+
);
145+
} catch (error) {
146+
if (error?.code !== 'ENOENT') {
147+
throw error;
148+
}
149+
return undefined;
150+
}
151+
}
152+
136153
export async function getOptimizerCacheKey(config: OptimizerConfig) {
137-
const changes = Array.from((await getChanges(OPTIMIZER_DIR)).entries());
154+
const [changes, lastCommit, bootstrap] = await Promise.all([
155+
getChanges(OPTIMIZER_DIR),
156+
getLastCommit(),
157+
getBootstrapCacheKey(),
158+
] as const);
159+
160+
const deletedPaths: string[] = [];
161+
const modifiedPaths: string[] = [];
162+
for (const [path, type] of changes) {
163+
(type === 'deleted' ? deletedPaths : modifiedPaths).push(path);
164+
}
138165

139166
const cacheKeys: OptimizerCacheKey = {
140-
lastCommit: await getLastCommit(),
141167
workerConfig: config.getWorkerConfig('♻'),
142-
deletedPaths: changes.filter(e => e[1] === 'deleted').map(e => e[0]),
143-
modifiedPaths: {} as Record<string, number>,
168+
lastCommit,
169+
bootstrap,
170+
deletedPaths,
171+
modifiedTimes: {} as Record<string, number>,
144172
};
145173

146-
const modified = changes.filter(e => e[1] === 'modified').map(e => e[0]);
147-
const mtimes = await getMtimes(modified);
174+
const mtimes = await getMtimes(modifiedPaths);
148175
for (const [path, mtime] of Array.from(mtimes.entries()).sort(ascending(e => e[0]))) {
149176
if (typeof mtime === 'number') {
150-
cacheKeys.modifiedPaths[path] = mtime;
177+
cacheKeys.modifiedTimes[path] = mtime;
151178
}
152179
}
153180

packages/kbn-ui-framework/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dependencies": {
1818
"classnames": "2.2.6",
1919
"focus-trap-react": "^3.1.1",
20-
"lodash": "npm:@elastic/[email protected]kibana3",
20+
"lodash": "npm:@elastic/[email protected]kibana4",
2121
"prop-types": "15.6.0",
2222
"react": "^16.12.0",
2323
"react-ace": "^5.9.0",

src/legacy/core_plugins/vis_type_tagcloud/public/components/__tests__/tag_cloud.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ import simpleloadPng from './simpleload.png';
3030
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
3131
import { seedColors } from '../../../../../../plugins/charts/public/services/colors/seed_colors';
3232

33-
const colors = {
34-
seedColors,
35-
};
36-
3733
describe('tag cloud tests', function() {
3834
const minValue = 1;
3935
const maxValue = 9;
@@ -102,6 +98,8 @@ describe('tag cloud tests', function() {
10298
let domNode;
10399
let tagCloud;
104100

101+
const colorScale = d3.scale.ordinal().range(seedColors);
102+
105103
function setupDOM() {
106104
domNode = document.createElement('div');
107105
domNode.style.top = '0';
@@ -132,7 +130,7 @@ describe('tag cloud tests', function() {
132130
)}`, function() {
133131
beforeEach(async function() {
134132
setupDOM();
135-
tagCloud = new TagCloud(domNode, colors);
133+
tagCloud = new TagCloud(domNode, colorScale);
136134
tagCloud.setData(test.data);
137135
tagCloud.setOptions(test.options);
138136
await fromNode(cb => tagCloud.once('renderComplete', cb));
@@ -164,7 +162,7 @@ describe('tag cloud tests', function() {
164162

165163
//TagCloud takes at least 600ms to complete (due to d3 animation)
166164
//renderComplete should only notify at the last one
167-
tagCloud = new TagCloud(domNode, colors);
165+
tagCloud = new TagCloud(domNode, colorScale);
168166
tagCloud.setData(baseTest.data);
169167
tagCloud.setOptions(baseTest.options);
170168

@@ -196,7 +194,7 @@ describe('tag cloud tests', function() {
196194
describe('should use the latest state before notifying (when modifying options multiple times)', function() {
197195
beforeEach(async function() {
198196
setupDOM();
199-
tagCloud = new TagCloud(domNode, colors);
197+
tagCloud = new TagCloud(domNode, colorScale);
200198
tagCloud.setData(baseTest.data);
201199
tagCloud.setOptions(baseTest.options);
202200
tagCloud.setOptions(logScaleTest.options);
@@ -223,7 +221,7 @@ describe('tag cloud tests', function() {
223221
describe('should use the latest state before notifying (when modifying data multiple times)', function() {
224222
beforeEach(async function() {
225223
setupDOM();
226-
tagCloud = new TagCloud(domNode, colors);
224+
tagCloud = new TagCloud(domNode, colorScale);
227225
tagCloud.setData(baseTest.data);
228226
tagCloud.setOptions(baseTest.options);
229227
tagCloud.setData(trimDataTest.data);
@@ -253,7 +251,7 @@ describe('tag cloud tests', function() {
253251
counter = 0;
254252
setupDOM();
255253
return new Promise((resolve, reject) => {
256-
tagCloud = new TagCloud(domNode, colors);
254+
tagCloud = new TagCloud(domNode, colorScale);
257255
tagCloud.setData(baseTest.data);
258256
tagCloud.setOptions(baseTest.options);
259257

@@ -299,7 +297,7 @@ describe('tag cloud tests', function() {
299297
describe('should show correct data when state-updates are interleaved with resize event', function() {
300298
beforeEach(async function() {
301299
setupDOM();
302-
tagCloud = new TagCloud(domNode, colors);
300+
tagCloud = new TagCloud(domNode, colorScale);
303301
tagCloud.setData(logScaleTest.data);
304302
tagCloud.setOptions(logScaleTest.options);
305303

@@ -337,7 +335,7 @@ describe('tag cloud tests', function() {
337335
setupDOM();
338336
domNode.style.width = '1px';
339337
domNode.style.height = '1px';
340-
tagCloud = new TagCloud(domNode, colors);
338+
tagCloud = new TagCloud(domNode, colorScale);
341339
tagCloud.setData(baseTest.data);
342340
tagCloud.setOptions(baseTest.options);
343341
await fromNode(cb => tagCloud.once('renderComplete', cb));
@@ -363,7 +361,7 @@ describe('tag cloud tests', function() {
363361
domNode.style.width = '1px';
364362
domNode.style.height = '1px';
365363

366-
tagCloud = new TagCloud(domNode, colors);
364+
tagCloud = new TagCloud(domNode, colorScale);
367365
tagCloud.setData(baseTest.data);
368366
tagCloud.setOptions(baseTest.options);
369367
await fromNode(cb => tagCloud.once('renderComplete', cb));
@@ -388,7 +386,7 @@ describe('tag cloud tests', function() {
388386
describe(`tags should no longer fit after making container smaller`, function() {
389387
beforeEach(async function() {
390388
setupDOM();
391-
tagCloud = new TagCloud(domNode, colors);
389+
tagCloud = new TagCloud(domNode, colorScale);
392390
tagCloud.setData(baseTest.data);
393391
tagCloud.setOptions(baseTest.options);
394392
await fromNode(cb => tagCloud.once('renderComplete', cb));
@@ -420,7 +418,7 @@ describe('tag cloud tests', function() {
420418
});
421419

422420
it('should render simple image', async function() {
423-
tagCloud = new TagCloud(domNode, colors);
421+
tagCloud = new TagCloud(domNode, colorScale);
424422
tagCloud.setData(baseTest.data);
425423
tagCloud.setOptions(baseTest.options);
426424

src/legacy/core_plugins/vis_type_tagcloud/public/components/tag_cloud.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const D3_SCALING_FUNCTIONS = {
3737
};
3838

3939
export class TagCloud extends EventEmitter {
40-
constructor(domNode, colors) {
40+
constructor(domNode, colorScale) {
4141
super();
4242

4343
//DOM
@@ -54,7 +54,6 @@ export class TagCloud extends EventEmitter {
5454
this._spiral = 'archimedean'; //layout shape
5555
this._timeInterval = 1000; //time allowed for layout algorithm
5656
this._padding = 5;
57-
this._seedColors = colors.seedColors;
5857

5958
//OPTIONS
6059
this._orientation = 'single';
@@ -67,6 +66,7 @@ export class TagCloud extends EventEmitter {
6766
this._words = null;
6867

6968
//UTIL
69+
this._colorScale = colorScale;
7070
this._setTimeoutId = null;
7171
this._pendingJob = null;
7272
this._layoutIsUpdating = null;
@@ -371,8 +371,7 @@ export class TagCloud extends EventEmitter {
371371
}
372372

373373
getFill(tag) {
374-
const colorScale = d3.scale.ordinal().range(this._seedColors);
375-
return colorScale(tag.text);
374+
return this._colorScale(tag.text);
376375
}
377376
}
378377

src/legacy/core_plugins/vis_type_tagcloud/public/components/tag_cloud_visualization.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ import { getFormat } from '../legacy_imports';
2828
import { Label } from './label';
2929
import { TagCloud } from './tag_cloud';
3030
import { FeedbackMessage } from './feedback_message';
31+
import d3 from 'd3';
3132

3233
const MAX_TAG_COUNT = 200;
3334

3435
export function createTagCloudVisualization({ colors }) {
36+
const colorScale = d3.scale.ordinal().range(colors.seedColors);
3537
return class TagCloudVisualization {
3638
constructor(node, vis) {
3739
this._containerNode = node;
@@ -48,7 +50,7 @@ export function createTagCloudVisualization({ colors }) {
4850

4951
this._vis = vis;
5052
this._truncated = false;
51-
this._tagCloud = new TagCloud(cloudContainer, colors);
53+
this._tagCloud = new TagCloud(cloudContainer, colorScale);
5254
this._tagCloud.on('select', event => {
5355
if (!this._visParams.bucket) {
5456
return;

src/legacy/core_plugins/visualizations/public/embeddable/visualize_embeddable.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as Rx from 'rxjs';
2424
import { buildPipeline } from 'ui/visualize/loader/pipeline_helpers';
2525
import { npStart } from 'ui/new_platform';
2626
import { IExpressionLoaderParams } from 'src/plugins/expressions/public';
27+
import { EmbeddableVisTriggerContext } from 'src/plugins/embeddable/public';
2728
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
2829
import {
2930
IIndexPattern,
@@ -39,8 +40,8 @@ import {
3940
EmbeddableOutput,
4041
Embeddable,
4142
Container,
42-
VALUE_CLICK_TRIGGER,
43-
SELECT_RANGE_TRIGGER,
43+
selectRangeTrigger,
44+
valueClickTrigger,
4445
} from '../../../../../plugins/embeddable/public';
4546
import { dispatchRenderComplete } from '../../../../../plugins/kibana_utils/public';
4647
import { SavedObject } from '../../../../../plugins/saved_objects/public';
@@ -301,13 +302,14 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
301302
}
302303

303304
if (!this.input.disableTriggers) {
304-
const eventName = event.name === 'brush' ? SELECT_RANGE_TRIGGER : VALUE_CLICK_TRIGGER;
305-
306-
npStart.plugins.uiActions.executeTriggerActions(eventName, {
305+
const triggerId: 'SELECT_RANGE_TRIGGER' | 'VALUE_CLICK_TRIGGER' =
306+
event.name === 'brush' ? selectRangeTrigger.id : valueClickTrigger.id;
307+
const context: EmbeddableVisTriggerContext = {
307308
embeddable: this,
308309
timeFieldName: this.vis.indexPattern.timeFieldName,
309310
data: event.data,
310-
});
311+
};
312+
npStart.plugins.uiActions.getTrigger(triggerId).exec(context);
311313
}
312314
})
313315
);

0 commit comments

Comments
 (0)