Skip to content

Commit

Permalink
Merge branch 'master' into cases-rbac-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Jun 3, 2021
2 parents d59dbad + 9618fd7 commit 7ef02f4
Show file tree
Hide file tree
Showing 236 changed files with 4,166 additions and 2,257 deletions.
8 changes: 3 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ Delete any items that are not applicable to this PR.

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature release.
Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how
they may potentially impact the change:
When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |
|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. |
| Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. |
| [See more potential risk examples](../RISK_MATRIX.mdx) |
| [See more potential risk examples](https://github.com/elastic/kibana/blob/master/RISK_MATRIX.mdx) |


### For maintainers
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-ui-shared-deps/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const Theme = require('./theme.ts');
export const Lodash = require('lodash');
export const LodashFp = require('lodash/fp');

export const Fflate = require('fflate/esm/browser');
import { unzlibSync, strFromU8 } from 'fflate';
export const Fflate = { unzlibSync, strFromU8 };

// runtime deps which don't need to be copied across all bundles
export const TsLib = require('tslib');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ const setup = () => {
};
};

// FLAKY: https://github.com/elastic/kibana/issues/101126
describe.skip('createStreamingBatchedFunction()', () => {
describe('createStreamingBatchedFunction()', () => {
beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
});
test('returns a function', () => {
const { fetchStreaming } = setup();
const fn = createStreamingBatchedFunction({
Expand Down Expand Up @@ -87,8 +93,8 @@ describe.skip('createStreamingBatchedFunction()', () => {
expect(fetchStreaming).toHaveBeenCalledTimes(0);
fn({ baz: 'quix' });
expect(fetchStreaming).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(6);

await new Promise((r) => setTimeout(r, 6));
expect(fetchStreaming).toHaveBeenCalledTimes(1);
});

Expand All @@ -103,7 +109,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
});

expect(fetchStreaming).toHaveBeenCalledTimes(0);
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);
expect(fetchStreaming).toHaveBeenCalledTimes(0);
});

Expand All @@ -118,7 +124,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
});

fn({ foo: 'bar' });
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

expect(fetchStreaming.mock.calls[0][0]).toMatchObject({
url: '/test',
Expand All @@ -139,7 +145,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
fn({ foo: 'bar' });
fn({ baz: 'quix' });

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);
const { body } = fetchStreaming.mock.calls[0][0];
expect(JSON.parse(body)).toEqual({
batch: [{ foo: 'bar' }, { baz: 'quix' }],
Expand All @@ -160,13 +166,10 @@ describe.skip('createStreamingBatchedFunction()', () => {

expect(fetchStreaming).toHaveBeenCalledTimes(0);
fn({ foo: 'bar' });
await flushPromises();
expect(fetchStreaming).toHaveBeenCalledTimes(0);
fn({ baz: 'quix' });
await flushPromises();
expect(fetchStreaming).toHaveBeenCalledTimes(0);
fn({ full: 'yep' });
await flushPromises();
expect(fetchStreaming).toHaveBeenCalledTimes(1);
});

Expand All @@ -186,7 +189,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
of(fn({ foo: 'bar' }, abortController.signal));
fn({ baz: 'quix' });

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);
const { body } = fetchStreaming.mock.calls[0][0];
expect(JSON.parse(body)).toEqual({
batch: [{ baz: 'quix' }],
Expand All @@ -206,7 +209,6 @@ describe.skip('createStreamingBatchedFunction()', () => {
fn({ a: '1' });
fn({ b: '2' });
fn({ c: '3' });
await flushPromises();

expect(fetchStreaming.mock.calls[0][0]).toMatchObject({
url: '/test',
Expand All @@ -231,11 +233,9 @@ describe.skip('createStreamingBatchedFunction()', () => {
fn({ a: '1' });
fn({ b: '2' });
fn({ c: '3' });
await flushPromises();
expect(fetchStreaming).toHaveBeenCalledTimes(1);
fn({ d: '4' });
await flushPromises();
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);
expect(fetchStreaming).toHaveBeenCalledTimes(2);
});
});
Expand All @@ -253,7 +253,7 @@ describe.skip('createStreamingBatchedFunction()', () => {

const promise1 = fn({ a: '1' });
const promise2 = fn({ b: '2' });
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

expect(await isPending(promise1)).toBe(true);
expect(await isPending(promise2)).toBe(true);
Expand All @@ -274,7 +274,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = fn({ a: '1' });
const promise2 = fn({ b: '2' });
const promise3 = fn({ c: '3' });
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

expect(await isPending(promise1)).toBe(true);
expect(await isPending(promise2)).toBe(true);
Expand Down Expand Up @@ -316,7 +316,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = fn({ a: '1' });
const promise2 = fn({ b: '2' });
const promise3 = fn({ c: '3' });
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.next(
JSON.stringify({
Expand Down Expand Up @@ -365,7 +365,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = fn({ a: '1' });
const promise2 = fn({ b: '2' });
const promise3 = fn({ c: '3' });
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.next(
JSON.stringify({
Expand Down Expand Up @@ -405,7 +405,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
});

const promise = fn({ a: '1' });
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

expect(await isPending(promise)).toBe(true);

Expand Down Expand Up @@ -437,7 +437,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise2 = of(fn({ a: '2' }));
const promise3 = of(fn({ a: '3' }));

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.next(
JSON.stringify({
Expand All @@ -446,7 +446,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
}) + '\n'
);

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

stream.next(
JSON.stringify({
Expand All @@ -455,7 +455,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
}) + '\n'
);

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

stream.next(
JSON.stringify({
Expand All @@ -464,7 +464,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
}) + '\n'
);

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

const [result1] = await promise1;
const [, error2] = await promise2;
Expand All @@ -489,13 +489,14 @@ describe.skip('createStreamingBatchedFunction()', () => {
const abortController = new AbortController();
const promise = fn({ a: '1' }, abortController.signal);
const promise2 = fn({ a: '2' }, abortController.signal);
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

expect(await isPending(promise)).toBe(true);
expect(await isPending(promise2)).toBe(true);

abortController.abort();
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);
await flushPromises();

expect(await isPending(promise)).toBe(false);
expect(await isPending(promise2)).toBe(false);
Expand All @@ -519,12 +520,13 @@ describe.skip('createStreamingBatchedFunction()', () => {
const abortController = new AbortController();
const promise = fn({ a: '1' }, abortController.signal);
const promise2 = fn({ a: '2' });
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

expect(await isPending(promise)).toBe(true);

abortController.abort();
await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);
await flushPromises();

expect(await isPending(promise)).toBe(false);
const [, error] = await of(promise);
Expand All @@ -537,7 +539,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
}) + '\n'
);

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

const [result2] = await of(promise2);
expect(result2).toEqual({ b: '2' });
Expand All @@ -558,11 +560,11 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = of(fn({ a: '1' }));
const promise2 = of(fn({ a: '2' }));

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.complete();

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

const [, error1] = await promise1;
const [, error2] = await promise2;
Expand All @@ -589,7 +591,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = of(fn({ a: '1' }));
const promise2 = of(fn({ a: '2' }));

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.next(
JSON.stringify({
Expand All @@ -599,7 +601,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
);
stream.complete();

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

const [, error1] = await promise1;
const [result1] = await promise2;
Expand Down Expand Up @@ -627,13 +629,13 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = of(fn({ a: '1' }));
const promise2 = of(fn({ a: '2' }));

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.error({
message: 'something went wrong',
});

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

const [, error1] = await promise1;
const [, error2] = await promise2;
Expand All @@ -660,7 +662,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = of(fn({ a: '1' }));
const promise2 = of(fn({ a: '2' }));

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.next(
JSON.stringify({
Expand All @@ -670,7 +672,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
);
stream.error('oops');

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

const [, error1] = await promise1;
const [result1] = await promise2;
Expand Down Expand Up @@ -698,7 +700,7 @@ describe.skip('createStreamingBatchedFunction()', () => {
const promise1 = of(fn({ a: '1' }));
const promise2 = of(fn({ a: '2' }));

await new Promise((r) => setTimeout(r, 6));
jest.advanceTimersByTime(6);

stream.next(
JSON.stringify({
Expand All @@ -709,7 +711,7 @@ describe.skip('createStreamingBatchedFunction()', () => {

stream.next('Not a JSON\n');

await new Promise((r) => setTimeout(r, 1));
jest.advanceTimersByTime(1);

const [, error1] = await promise1;
const [result1] = await promise2;
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/dashboard/server/usage/dashboard_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ export interface DashboardCollectorData {
visualizationByValue: {
[key: string]: number;
};
embeddable: {
[key: string]: number;
};
}

export const getEmptyTelemetryData = (): DashboardCollectorData => ({
panels: 0,
panelsByValue: 0,
lensByValue: {},
visualizationByValue: {},
embeddable: {},
});

type DashboardCollectorFunction = (
Expand Down Expand Up @@ -115,6 +119,23 @@ export const collectForPanels: DashboardCollectorFunction = (panels, collectorDa
collectByValueLensInfo(panels, collectorData);
};

export const collectEmbeddableData = (
panels: SavedDashboardPanel730ToLatest[],
collectorData: DashboardCollectorData,
embeddableService: EmbeddablePersistableStateService
) => {
for (const panel of panels) {
collectorData.embeddable = embeddableService.telemetry(
{
...panel.embeddableConfig,
id: panel.id || '',
type: panel.type,
},
collectorData.embeddable
);
}
};

export async function collectDashboardTelemetry(
savedObjectClient: Pick<ISavedObjectsRepository, 'find'>,
embeddableService: EmbeddablePersistableStateService
Expand All @@ -134,6 +155,7 @@ export async function collectDashboardTelemetry(
) as unknown) as SavedDashboardPanel730ToLatest[];

collectForPanels(panels, collectorData);
collectEmbeddableData(panels, collectorData, embeddableService);
}

return collectorData;
Expand Down
Loading

0 comments on commit 7ef02f4

Please sign in to comment.