Skip to content

Commit

Permalink
Merge branch 'main' into custom_highlighted_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Aug 15, 2023
2 parents 294387d + bf3dc72 commit 9d6c1e3
Show file tree
Hide file tree
Showing 10 changed files with 1,593 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@

import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public';

import { OPTIONS_LIST_CONTROL } from '../../../common';
import { ControlOutput } from '../../types';
import { ControlGroupInput } from '../types';
import { pluginServices } from '../../services';
import { DeleteControlAction } from './delete_control_action';
import { OptionsListEmbeddableInput } from '../../options_list';
import { controlGroupInputBuilder } from '../external_api/control_group_input_builder';
import { ControlGroupContainer } from '../embeddable/control_group_container';
import { OptionsListEmbeddableFactory } from '../../options_list/embeddable/options_list_embeddable_factory';
import { OptionsListEmbeddable } from '../../options_list/embeddable/options_list_embeddable';
import { mockedReduxEmbeddablePackage } from '@kbn/presentation-util-plugin/public/mocks';

let container: ControlGroupContainer;
let embeddable: OptionsListEmbeddable;

beforeAll(async () => {
pluginServices.getServices().controls.getControlFactory = jest
.fn()
.mockImplementation((type: string) => {
if (type === OPTIONS_LIST_CONTROL) return new OptionsListEmbeddableFactory();
});

const controlGroupInput = { chainingSystem: 'NONE', panels: {} } as ControlGroupInput;
controlGroupInputBuilder.addOptionsListControl(controlGroupInput, {
dataViewId: 'test-data-view',
Expand All @@ -34,6 +42,7 @@ beforeAll(async () => {
await container.untilInitialized();

embeddable = container.getChild(container.getChildIds()[0]);
expect(embeddable.type).toBe(OPTIONS_LIST_CONTROL);
});

test('Action is incompatible with Error Embeddables', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public';

import { OPTIONS_LIST_CONTROL } from '../../../common';
import { ControlOutput } from '../../types';
import { ControlGroupInput } from '../types';
import { pluginServices } from '../../services';
Expand Down Expand Up @@ -55,13 +56,14 @@ test('Action is compatible with embeddables that are editable', async () => {
const editControlAction = new EditControlAction(deleteControlAction);
const emptyContainer = new ControlGroupContainer(mockedReduxEmbeddablePackage, controlGroupInput);
await emptyContainer.untilInitialized();
await emptyContainer.addOptionsListControl({
const control = await emptyContainer.addOptionsListControl({
dataViewId: 'test-data-view',
title: 'test',
fieldName: 'test-field',
width: 'medium',
grow: false,
});
expect(emptyContainer.getInput().panels[control.getInput().id].type).toBe(OPTIONS_LIST_CONTROL);

expect(
await editControlAction.isCompatible({
Expand All @@ -88,18 +90,16 @@ test('Execute should open a flyout', async () => {

const emptyContainer = new ControlGroupContainer(mockedReduxEmbeddablePackage, controlGroupInput);
await emptyContainer.untilInitialized();
await emptyContainer.addOptionsListControl({
const control = (await emptyContainer.addOptionsListControl({
dataViewId: 'test-data-view',
title: 'test',
fieldName: 'test-field',
width: 'medium',
grow: false,
});
const embeddable: OptionsListEmbeddable = emptyContainer.getChild(
emptyContainer.getChildIds()[0]
);
})) as OptionsListEmbeddable;
expect(emptyContainer.getInput().panels[control.getInput().id].type).toBe(OPTIONS_LIST_CONTROL);

const editControlAction = new EditControlAction(deleteControlAction);
await editControlAction.execute({ embeddable });
await editControlAction.execute({ embeddable: control });
expect(spyOn).toHaveBeenCalled();
});
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export const reportingScreenshotShareProvider = ({
let capabilityHasDashboardScreenshotReporting = false;
let capabilityHasVisualizeScreenshotReporting = false;
if (usesUiCapabilities) {
// TODO: add abstractions in ExportTypeRegistry to use here?
capabilityHasDashboardScreenshotReporting =
application.capabilities.dashboard?.generateScreenshot === true;
capabilityHasVisualizeScreenshotReporting =
Expand All @@ -106,7 +105,11 @@ export const reportingScreenshotShareProvider = ({
return [];
}

if (isSupportedType && !capabilityHasVisualizeScreenshotReporting) {
if (
isSupportedType &&
!capabilityHasVisualizeScreenshotReporting &&
!capabilityHasDashboardScreenshotReporting
) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { UptimeUrlParams } from '../../../lib/helper/url_params';
const SAMPLE_ES_FILTERS = `{"bool":{"should":[{"match_phrase":{"monitor.id":"NodeServer"}}],"minimum_should_match":1}}`;

// FLAKY: https://github.com/elastic/kibana/issues/112677
describe.skip('useQueryBar', () => {
describe('useQueryBar', () => {
let DEFAULT_URL_PARAMS: UptimeUrlParams;
let wrapper: any;
let useUrlParamsSpy: jest.SpyInstance<[URL.GetUrlParams, URL.UpdateUrlParams]>;
Expand Down
6 changes: 4 additions & 2 deletions x-pack/test/functional/apps/lens/group4/tsdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
log.info(`Indexed ${res.items.length} test data docs.`);
};

describe('lens tsdb', function () {
// Failing ES promotion: https://github.com/elastic/kibana/issues/163970
describe.skip('lens tsdb', function () {
const tsdbIndex = 'kibana_sample_data_logstsdb';
const tsdbDataView = tsdbIndex;
const tsdbEsArchive = 'test/functional/fixtures/es_archiver/kibana_sample_data_logs_tsdb';
Expand Down Expand Up @@ -384,7 +385,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
});

describe('for rolled up metric (downsampled)', () => {
// FAILING ES PROMOTION: https://github.com/elastic/kibana/issues/163971
describe.skip('for rolled up metric (downsampled)', () => {
it('defaults to average for rolled up metric', async () => {
await PageObjects.lens.switchDataPanelIndexPattern(downsampleDataView.dataView);
await PageObjects.lens.removeLayer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { SuperTest, Test } from 'supertest';

interface CreateEsQueryRuleParams {
size: number;
thresholdComparator: string;
threshold: number[];
timeWindowSize?: number;
timeWindowUnit?: string;
esQuery?: string;
timeField?: string;
searchConfiguration?: unknown;
indexName?: string;
excludeHitsFromPreviousRun?: boolean;
aggType?: string;
aggField?: string;
groupBy?: string;
termField?: string;
termSize?: number;
index?: string[];
}

export async function createIndexConnector({
supertest,
name,
indexName,
}: {
supertest: SuperTest<Test>;
name: string;
indexName: string;
}) {
const { body } = await supertest
.post(`/api/actions/connector`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
name,
config: {
index: indexName,
refresh: true,
},
connector_type_id: '.index',
});
return body.id as string;
}

export async function createSlackConnector({
supertest,
name,
}: {
supertest: SuperTest<Test>;
name: string;
}) {
const { body } = await supertest
.post(`/api/actions/connector`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
name,
config: {},
secrets: {
webhookUrl: 'http://test',
},
connector_type_id: '.slack',
});
return body.id as string;
}

export async function createEsQueryRule({
supertest,
name,
ruleTypeId,
params,
actions = [],
tags = [],
schedule,
consumer,
notifyWhen,
enabled = true,
}: {
supertest: SuperTest<Test>;
ruleTypeId: string;
name: string;
params: CreateEsQueryRuleParams;
consumer: string;
actions?: any[];
tags?: any[];
schedule?: { interval: string };
notifyWhen?: string;
enabled?: boolean;
}) {
const { body } = await supertest
.post(`/api/alerting/rule`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
enabled,
params,
consumer,
schedule: schedule || {
interval: '1h',
},
tags,
name,
rule_type_id: ruleTypeId,
actions,
...(notifyWhen ? { notify_when: notifyWhen, throttle: '1m' } : {}),
});
return body;
}

export async function disableRule({
supertest,
ruleId,
}: {
supertest: SuperTest<Test>;
ruleId: string;
}) {
const { body } = await supertest
.post(`/api/alerting/rule/${ruleId}/_disable`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo');
return body;
}

export async function updateEsQueryRule({
supertest,
ruleId,
updates,
}: {
supertest: SuperTest<Test>;
ruleId: string;
updates: any;
}) {
const { body: r } = await supertest
.get(`/api/alerting/rule/${ruleId}`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo');
const body = await supertest
.put(`/api/alerting/rule/${ruleId}`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
...{
name: r.name,
schedule: r.schedule,
throttle: r.throttle,
tags: r.tags,
params: r.params,
notify_when: r.notifyWhen,
actions: r.actions.map((action: any) => ({
group: action.group,
params: action.params,
id: action.id,
frequency: action.frequency,
})),
},
...updates,
});
return body;
}

export async function runRule({
supertest,
ruleId,
}: {
supertest: SuperTest<Test>;
ruleId: string;
}) {
const { body } = await supertest
.post(`/internal/alerting/rule/${ruleId}/_run_soon`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo');
return body;
}

export async function muteRule({
supertest,
ruleId,
}: {
supertest: SuperTest<Test>;
ruleId: string;
}) {
const { body } = await supertest
.post(`/api/alerting/rule/${ruleId}/_mute_all`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo');
return body;
}

export async function enableRule({
supertest,
ruleId,
}: {
supertest: SuperTest<Test>;
ruleId: string;
}) {
const { body } = await supertest
.post(`/api/alerting/rule/${ruleId}/_enable`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo');
return body;
}

export async function muteAlert({
supertest,
ruleId,
alertId,
}: {
supertest: SuperTest<Test>;
ruleId: string;
alertId: string;
}) {
const { body } = await supertest
.post(`/api/alerting/rule/${ruleId}/alert/${alertId}/_mute`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo');
return body;
}

export async function unmuteRule({
supertest,
ruleId,
}: {
supertest: SuperTest<Test>;
ruleId: string;
}) {
const { body } = await supertest
.post(`/api/alerting/rule/${ruleId}/_unmute_all`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo');
return body;
}
Loading

0 comments on commit 9d6c1e3

Please sign in to comment.