Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into telemetry/mer…
Browse files Browse the repository at this point in the history
…ge-oss-and-xpack-collectors
  • Loading branch information
afharo committed Feb 21, 2020
2 parents 25d3da5 + 3d9eb2a commit b573500
Show file tree
Hide file tree
Showing 67 changed files with 1,038 additions and 239 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
"leaflet.heat": "0.2.0",
"less": "^2.7.3",
"less-loader": "5.0.0",
"lodash": "npm:@elastic/lodash@3.10.1-kibana3",
"lodash": "npm:@elastic/lodash@3.10.1-kibana4",
"lodash.clonedeep": "^4.5.0",
"lru-cache": "4.1.5",
"markdown-it": "^10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-interpreter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@babel/runtime": "^7.5.5",
"@kbn/i18n": "1.0.0",
"lodash": "npm:@elastic/lodash@3.10.1-kibana3",
"lodash": "npm:@elastic/lodash@3.10.1-kibana4",
"lodash.clone": "^4.5.0",
"uuid": "3.3.2"
},
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-optimizer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

// cache buster - https://github.com/elastic/kibana/issues/58077 - 1
export { OptimizerConfig } from './optimizer';
export * from './run_optimizer';
export * from './log_optimizer_state';
52 changes: 40 additions & 12 deletions packages/kbn-optimizer/src/optimizer/cache_keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,35 @@
* under the License.
*/

import Path from 'path';

import jestDiff from 'jest-diff';
import { REPO_ROOT, createAbsolutePathSerializer } from '@kbn/dev-utils';

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

jest.mock('./get_changes.ts');
jest.mock('./get_changes.ts', () => ({
getChanges: async () =>
new Map([
['/foo/bar/a', 'modified'],
['/foo/bar/b', 'modified'],
['/foo/bar/c', 'deleted'],
]),
}));

jest.mock('./get_mtimes.ts', () => ({
getMtimes: async (paths: string[]) => new Map(paths.map(path => [path, 12345])),
}));

jest.mock('execa');

jest.mock('fs', () => {
const realFs = jest.requireActual('fs');
jest.spyOn(realFs, 'readFile');
return realFs;
});

expect.addSnapshotSerializer(createAbsolutePathSerializer());

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

jest.requireMock('./get_changes.ts').getChanges.mockImplementation(
async () =>
new Map([
['/foo/bar/a', 'modified'],
['/foo/bar/b', 'modified'],
['/foo/bar/c', 'deleted'],
])
);

describe('getOptimizerCacheKey()', () => {
it('uses latest commit and changes files to create unique value', async () => {
it('uses latest commit, bootstrap cache, and changed files to create unique value', async () => {
jest
.requireMock('fs')
.readFile.mockImplementation(
(path: string, enc: string, cb: (err: null, file: string) => void) => {
expect(path).toBe(
Path.resolve(REPO_ROOT, 'packages/kbn-optimizer/target/.bootstrap-cache')
);
expect(enc).toBe('utf8');
cb(null, '<bootstrap cache>');
}
);

const config = OptimizerConfig.create({
repoRoot: REPO_ROOT,
});

await expect(getOptimizerCacheKey(config)).resolves.toMatchInlineSnapshot(`
Object {
"bootstrap": "<bootstrap cache>",
"deletedPaths": Array [
"/foo/bar/c",
],
"lastCommit": "<last commit sha>",
"modifiedPaths": Object {},
"modifiedTimes": Object {
"/foo/bar/a": 12345,
"/foo/bar/b": 12345,
},
"workerConfig": Object {
"browserslistEnv": "dev",
"cache": true,
Expand Down
43 changes: 35 additions & 8 deletions packages/kbn-optimizer/src/optimizer/cache_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import Path from 'path';
import Fs from 'fs';
import { promisify } from 'util';

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

export interface OptimizerCacheKey {
readonly lastCommit: string | undefined;
readonly bootstrap: string | undefined;
readonly workerConfig: WorkerConfig;
readonly deletedPaths: string[];
readonly modifiedPaths: Record<string, number>;
readonly modifiedTimes: Record<string, number>;
}

async function getLastCommit() {
Expand All @@ -133,21 +136,45 @@ async function getLastCommit() {
return stdout.trim() || undefined;
}

async function getBootstrapCacheKey() {
try {
return await promisify(Fs.readFile)(
Path.resolve(OPTIMIZER_DIR, 'target/.bootstrap-cache'),
'utf8'
);
} catch (error) {
if (error?.code !== 'ENOENT') {
throw error;
}
return undefined;
}
}

export async function getOptimizerCacheKey(config: OptimizerConfig) {
const changes = Array.from((await getChanges(OPTIMIZER_DIR)).entries());
const [changes, lastCommit, bootstrap] = await Promise.all([
getChanges(OPTIMIZER_DIR),
getLastCommit(),
getBootstrapCacheKey(),
] as const);

const deletedPaths: string[] = [];
const modifiedPaths: string[] = [];
for (const [path, type] of changes) {
(type === 'deleted' ? deletedPaths : modifiedPaths).push(path);
}

const cacheKeys: OptimizerCacheKey = {
lastCommit: await getLastCommit(),
workerConfig: config.getWorkerConfig('♻'),
deletedPaths: changes.filter(e => e[1] === 'deleted').map(e => e[0]),
modifiedPaths: {} as Record<string, number>,
lastCommit,
bootstrap,
deletedPaths,
modifiedTimes: {} as Record<string, number>,
};

const modified = changes.filter(e => e[1] === 'modified').map(e => e[0]);
const mtimes = await getMtimes(modified);
const mtimes = await getMtimes(modifiedPaths);
for (const [path, mtime] of Array.from(mtimes.entries()).sort(ascending(e => e[0]))) {
if (typeof mtime === 'number') {
cacheKeys.modifiedPaths[path] = mtime;
cacheKeys.modifiedTimes[path] = mtime;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-ui-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"classnames": "2.2.6",
"focus-trap-react": "^3.1.1",
"lodash": "npm:@elastic/lodash@3.10.1-kibana3",
"lodash": "npm:@elastic/lodash@3.10.1-kibana4",
"prop-types": "15.6.0",
"react": "^16.12.0",
"react-ace": "^5.9.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import simpleloadPng from './simpleload.png';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { seedColors } from '../../../../../../plugins/charts/public/services/colors/seed_colors';

const colors = {
seedColors,
};

describe('tag cloud tests', function() {
const minValue = 1;
const maxValue = 9;
Expand Down Expand Up @@ -102,6 +98,8 @@ describe('tag cloud tests', function() {
let domNode;
let tagCloud;

const colorScale = d3.scale.ordinal().range(seedColors);

function setupDOM() {
domNode = document.createElement('div');
domNode.style.top = '0';
Expand Down Expand Up @@ -132,7 +130,7 @@ describe('tag cloud tests', function() {
)}`, function() {
beforeEach(async function() {
setupDOM();
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(test.data);
tagCloud.setOptions(test.options);
await fromNode(cb => tagCloud.once('renderComplete', cb));
Expand Down Expand Up @@ -164,7 +162,7 @@ describe('tag cloud tests', function() {

//TagCloud takes at least 600ms to complete (due to d3 animation)
//renderComplete should only notify at the last one
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);

Expand Down Expand Up @@ -196,7 +194,7 @@ describe('tag cloud tests', function() {
describe('should use the latest state before notifying (when modifying options multiple times)', function() {
beforeEach(async function() {
setupDOM();
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
tagCloud.setOptions(logScaleTest.options);
Expand All @@ -223,7 +221,7 @@ describe('tag cloud tests', function() {
describe('should use the latest state before notifying (when modifying data multiple times)', function() {
beforeEach(async function() {
setupDOM();
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
tagCloud.setData(trimDataTest.data);
Expand Down Expand Up @@ -253,7 +251,7 @@ describe('tag cloud tests', function() {
counter = 0;
setupDOM();
return new Promise((resolve, reject) => {
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);

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

Expand Down Expand Up @@ -337,7 +335,7 @@ describe('tag cloud tests', function() {
setupDOM();
domNode.style.width = '1px';
domNode.style.height = '1px';
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
await fromNode(cb => tagCloud.once('renderComplete', cb));
Expand All @@ -363,7 +361,7 @@ describe('tag cloud tests', function() {
domNode.style.width = '1px';
domNode.style.height = '1px';

tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
await fromNode(cb => tagCloud.once('renderComplete', cb));
Expand All @@ -388,7 +386,7 @@ describe('tag cloud tests', function() {
describe(`tags should no longer fit after making container smaller`, function() {
beforeEach(async function() {
setupDOM();
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
await fromNode(cb => tagCloud.once('renderComplete', cb));
Expand Down Expand Up @@ -420,7 +418,7 @@ describe('tag cloud tests', function() {
});

it('should render simple image', async function() {
tagCloud = new TagCloud(domNode, colors);
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const D3_SCALING_FUNCTIONS = {
};

export class TagCloud extends EventEmitter {
constructor(domNode, colors) {
constructor(domNode, colorScale) {
super();

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

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

//UTIL
this._colorScale = colorScale;
this._setTimeoutId = null;
this._pendingJob = null;
this._layoutIsUpdating = null;
Expand Down Expand Up @@ -371,8 +371,7 @@ export class TagCloud extends EventEmitter {
}

getFill(tag) {
const colorScale = d3.scale.ordinal().range(this._seedColors);
return colorScale(tag.text);
return this._colorScale(tag.text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import { getFormat } from '../legacy_imports';
import { Label } from './label';
import { TagCloud } from './tag_cloud';
import { FeedbackMessage } from './feedback_message';
import d3 from 'd3';

const MAX_TAG_COUNT = 200;

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

this._vis = vis;
this._truncated = false;
this._tagCloud = new TagCloud(cloudContainer, colors);
this._tagCloud = new TagCloud(cloudContainer, colorScale);
this._tagCloud.on('select', event => {
if (!this._visParams.bucket) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as Rx from 'rxjs';
import { buildPipeline } from 'ui/visualize/loader/pipeline_helpers';
import { npStart } from 'ui/new_platform';
import { IExpressionLoaderParams } from 'src/plugins/expressions/public';
import { EmbeddableVisTriggerContext } from 'src/plugins/embeddable/public';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
import {
IIndexPattern,
Expand All @@ -39,8 +40,8 @@ import {
EmbeddableOutput,
Embeddable,
Container,
VALUE_CLICK_TRIGGER,
SELECT_RANGE_TRIGGER,
selectRangeTrigger,
valueClickTrigger,
} from '../../../../../plugins/embeddable/public';
import { dispatchRenderComplete } from '../../../../../plugins/kibana_utils/public';
import { SavedObject } from '../../../../../plugins/saved_objects/public';
Expand Down Expand Up @@ -301,13 +302,14 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
}

if (!this.input.disableTriggers) {
const eventName = event.name === 'brush' ? SELECT_RANGE_TRIGGER : VALUE_CLICK_TRIGGER;

npStart.plugins.uiActions.executeTriggerActions(eventName, {
const triggerId: 'SELECT_RANGE_TRIGGER' | 'VALUE_CLICK_TRIGGER' =
event.name === 'brush' ? selectRangeTrigger.id : valueClickTrigger.id;
const context: EmbeddableVisTriggerContext = {
embeddable: this,
timeFieldName: this.vis.indexPattern.timeFieldName,
data: event.data,
});
};
npStart.plugins.uiActions.getTrigger(triggerId).exec(context);
}
})
);
Expand Down
Loading

0 comments on commit b573500

Please sign in to comment.