Skip to content

Commit

Permalink
Merge branch 'main' into eui/77.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Apr 12, 2023
2 parents 731e120 + 515d270 commit 8043a84
Show file tree
Hide file tree
Showing 86 changed files with 4,111 additions and 1,373 deletions.
7 changes: 7 additions & 0 deletions src/dev/build/tasks/fetch_agent_versions_list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import fetch from 'node-fetch';
import pRetry from 'p-retry';

import { REPO_ROOT } from '@kbn/repo-info';
import { ToolingLog } from '@kbn/tooling-log';
Expand All @@ -14,6 +15,7 @@ import { FetchAgentVersionsList } from './fetch_agent_versions_list';
import { Build, Config, write } from '../lib';

jest.mock('node-fetch');
jest.mock('p-retry');
jest.mock('../lib');

const config = new Config(
Expand Down Expand Up @@ -46,9 +48,14 @@ const config = new Config(
);

const mockedFetch = fetch as jest.MockedFunction<typeof fetch>;
const mockedPRetry = pRetry as jest.MockedFunction<typeof pRetry>;
const mockedWrite = write as jest.MockedFunction<typeof write>;
const mockedBuild = new Build(config);

mockedPRetry.mockImplementation((fn: any) => {
return fn();
});

const processEnv = process.env;

describe('FetchAgentVersionsList', () => {
Expand Down
9 changes: 5 additions & 4 deletions src/dev/build/tasks/fetch_agent_versions_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
*/

import fetch from 'node-fetch';
import pRetry from 'p-retry';

import { ToolingLog } from '@kbn/tooling-log';
import { write, Task } from '../lib';

// Endpoint maintained by the web-team and hosted on the elastic website
const PRODUCT_VERSIONS_URL = 'https://www.elastic.co/api/product_versions';

const isPr = () =>
!!process.env.BUILDKITE_PULL_REQUEST && process.env.BUILDKITE_PULL_REQUEST !== 'false';

Expand All @@ -20,13 +24,10 @@ const getAvailableVersions = async (log: ToolingLog) => {
'Content-Type': 'application/json',
},
};
// Endpoint maintained by the web-team and hosted on the elastic website
// See https://github.com/elastic/website-development/issues/9331
const url = 'https://www.elastic.co/content/product_versions';
log.info('Fetching Elastic Agent versions list');

try {
const results = await fetch(url, options);
const results = await pRetry(() => fetch(PRODUCT_VERSIONS_URL, options), { retries: 3 });
const rawBody = await results.text();

if (results.status >= 400) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export const OptionsListPopoverFooter = ({ isLoading }: { isLoading: boolean })
>
{isLoading && (
<div style={{ position: 'absolute', width: '100%' }}>
<EuiProgress size="xs" color="accent" />
<EuiProgress
data-test-subj="optionsList-control-popover-loading"
size="xs"
color="accent"
/>
</div>
)}
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,13 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
public showPlaceholderUntil = showPlaceholderUntil;
public addOrUpdateEmbeddable = addOrUpdateEmbeddable;

public forceRefresh() {
public forceRefresh(refreshControlGroup: boolean = true) {
const {
dispatch,
actions: { setLastReloadRequestTimeToNow },
} = this.getReduxEmbeddableTools();
dispatch(setLastReloadRequestTimeToNow({}));
this.controlGroup?.reload();
if (refreshControlGroup) this.controlGroup?.reload();
}

public onDataViewsUpdate$ = new Subject<DataView[]>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function startSyncingDashboardControlGroup(this: DashboardContainer) {
),
skip(1) // skip first filter output because it will have been applied in initialize
)
.subscribe(() => this.forceRefresh())
.subscribe(() => this.forceRefresh(false)) // we should not reload the control group when the control group output changes - otherwise, performance is severely impacted
);

subscriptions.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'header',
]);

// FLAKY: https://github.com/elastic/kibana/issues/154146
describe.skip('Dashboard control group hierarchical chaining', () => {
describe('Dashboard control group hierarchical chaining', () => {
const newDocuments: Array<{ index: string; id: string }> = [];
let controlIds: string[];

Expand All @@ -44,7 +43,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

/* start by adding some incomplete data so that we can test `exists` query */
await common.navigateToApp('console');
await console.collapseHelp();
await console.closeHelpIfExists();
await console.clearTextArea();
await addDocument(
'animals-cats-2018-01-01',
Expand Down Expand Up @@ -88,7 +87,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

after(async () => {
await common.navigateToApp('console');
await console.collapseHelp();
await console.closeHelpIfExists();
await console.clearTextArea();
for (const { index, id } of newDocuments) {
await console.enterRequest(`\nDELETE /${index}/_doc/${id}`);
Expand Down
13 changes: 8 additions & 5 deletions test/functional/page_objects/dashboard_page_controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,14 @@ export class DashboardPageControls extends FtrService {
this.log.debug(`searching for ${search} in options list`);
await this.optionsListPopoverAssertOpen();
await this.testSubjects.setValue(`optionsList-control-search-input`, search);
await this.optionsListPopoverWaitForLoading();
}

public async optionsListPopoverClearSearch() {
this.log.debug(`clearing search from options list`);
await this.optionsListPopoverAssertOpen();
await this.find.clickByCssSelector('.euiFormControlLayoutClearButton');
await this.optionsListPopoverWaitForLoading();
}

public async optionsListPopoverSetSort(sort: OptionsListSortingType) {
Expand All @@ -464,14 +466,14 @@ export class DashboardPageControls extends FtrService {
await this.retry.try(async () => {
await this.testSubjects.existOrFail('optionsListControl__sortingOptionsPopover');
});

await this.testSubjects.click(`optionsList__sortOrder_${sort.direction}`);
await this.testSubjects.click(`optionsList__sortBy_${sort.by}`);

await this.testSubjects.click('optionsListControl__sortingOptionsButton');
await this.retry.try(async () => {
await this.testSubjects.missingOrFail(`optionsListControl__sortingOptionsPopover`);
});

await this.optionsListPopoverWaitForLoading();
}

public async optionsListPopoverSelectExists() {
Expand All @@ -484,15 +486,13 @@ export class DashboardPageControls extends FtrService {
public async optionsListPopoverSelectOption(availableOption: string) {
this.log.debug(`selecting ${availableOption} from options list`);
await this.optionsListPopoverSearchForOption(availableOption);
await this.optionsListPopoverWaitForLoading();

await this.retry.try(async () => {
await this.testSubjects.existOrFail(`optionsList-control-selection-${availableOption}`);
await this.testSubjects.click(`optionsList-control-selection-${availableOption}`);
});

await this.optionsListPopoverClearSearch();
await this.optionsListPopoverWaitForLoading();
}

public async optionsListPopoverClearSelections() {
Expand All @@ -516,7 +516,10 @@ export class DashboardPageControls extends FtrService {

public async optionsListWaitForLoading(controlId: string) {
this.log.debug(`wait for ${controlId} to load`);
await this.testSubjects.waitForEnabled(`optionsList-control-${controlId}`);
const enabled = await this.testSubjects.waitForEnabled(`optionsList-control-${controlId}`);
if (!enabled) {
throw new Error(`${controlId} did not finish loading within the given time limit`);
}
}

public async optionsListPopoverWaitForLoading() {
Expand Down
5 changes: 3 additions & 2 deletions test/functional/services/common/test_subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,12 @@ export class TestSubjects extends FtrService {
await this.findService.waitForElementHidden(element, timeout);
}

public async waitForEnabled(selector: string, timeout: number = this.TRY_TIME): Promise<void> {
await this.retry.tryForTime(timeout, async () => {
public async waitForEnabled(selector: string, timeout: number = this.TRY_TIME): Promise<boolean> {
const success = await this.retry.tryForTime(timeout, async () => {
const element = await this.find(selector);
return (await element.isDisplayed()) && (await element.isEnabled());
});
return success;
}

public getCssSelector(selector: string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import type { Filter, Query } from '@kbn/es-query';
import { usePageUrlState } from '@kbn/ml-url-state';
import { useTimefilter, useTimeRangeUpdates } from '@kbn/ml-date-picker';
import { ES_FIELD_TYPES } from '@kbn/field-types';
import { DEFAULT_AGG_FUNCTION } from './constants';
import { useSplitFieldCardinality } from './use_split_field_cardinality';
import { type QueryDslQueryContainer } from '@kbn/data-views-plugin/common/types';
import { type ChangePointType, DEFAULT_AGG_FUNCTION } from './constants';
import {
createMergedEsQuery,
getEsQueryFromSavedSearch,
} from '../../application/utils/search_utils';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import { useChangePointResults } from './use_change_point_agg_request';
import { type TimeBuckets, TimeBucketsInterval } from '../../../common/time_buckets';
import { useDataSource } from '../../hooks/use_data_source';
import { useTimeBuckets } from '../../hooks/use_time_buckets';
Expand All @@ -37,10 +36,14 @@ export interface ChangePointDetectionPageUrlState {
pageUrlState: ChangePointDetectionRequestParams;
}

export interface ChangePointDetectionRequestParams {
export interface FieldConfig {
fn: string;
splitField?: string;
metricField: string;
}

export interface ChangePointDetectionRequestParams {
fieldConfigs: FieldConfig[];
interval: string;
query: Query;
filters: Filter[];
Expand All @@ -54,50 +57,29 @@ export const ChangePointDetectionContext = createContext<{
metricFieldOptions: DataViewField[];
splitFieldsOptions: DataViewField[];
updateRequestParams: (update: Partial<ChangePointDetectionRequestParams>) => void;
isLoading: boolean;
annotations: ChangePointAnnotation[];
resultFilters: Filter[];
updateFilters: (update: Filter[]) => void;
resultQuery: Query;
progress: number;
pagination: {
activePage: number;
pageCount: number;
updatePagination: (newPage: number) => void;
};
splitFieldCardinality: number | null;
combinedQuery: QueryDslQueryContainer;
selectedChangePoints: Record<number, SelectedChangePoint[]>;
setSelectedChangePoints: (update: Record<number, SelectedChangePoint[]>) => void;
}>({
isLoading: false,
splitFieldsOptions: [],
metricFieldOptions: [],
requestParams: {} as ChangePointDetectionRequestParams,
timeBuckets: {} as TimeBuckets,
bucketInterval: {} as TimeBucketsInterval,
updateRequestParams: () => {},
annotations: [],
resultFilters: [],
updateFilters: () => {},
resultQuery: { query: '', language: 'kuery' },
progress: 0,
pagination: {
activePage: 0,
pageCount: 1,
updatePagination: () => {},
},
splitFieldCardinality: null,
combinedQuery: {},
selectedChangePoints: {},
setSelectedChangePoints: () => {},
});

export type ChangePointType =
| 'dip'
| 'spike'
| 'distribution_change'
| 'step_change'
| 'trend_change'
| 'stationary'
| 'non_stationary'
| 'indeterminable';

export interface ChangePointAnnotation {
id: string;
label: string;
reason: string;
timestamp: string;
Expand All @@ -109,6 +91,8 @@ export interface ChangePointAnnotation {
p_value: number;
}

export type SelectedChangePoint = FieldConfig & ChangePointAnnotation;

export const ChangePointDetectionContextProvider: FC = ({ children }) => {
const { dataView, savedSearch } = useDataSource();
const {
Expand All @@ -129,8 +113,11 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {

const timefilter = useTimefilter();
const timeBuckets = useTimeBuckets();
const [resultFilters, setResultFilter] = useState<Filter[]>([]);

const [resultFilters, setResultFilter] = useState<Filter[]>([]);
const [selectedChangePoints, setSelectedChangePoints] = useState<
Record<number, SelectedChangePoint[]>
>({});
const [bucketInterval, setBucketInterval] = useState<TimeBucketsInterval>();

const timeRange = useTimeRangeUpdates();
Expand Down Expand Up @@ -184,11 +171,13 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {

const requestParams = useMemo(() => {
const params = { ...requestParamsFromUrl };
if (!params.fn) {
params.fn = DEFAULT_AGG_FUNCTION;
}
if (!params.metricField && metricFieldOptions.length > 0) {
params.metricField = metricFieldOptions[0].name;
if (!params.fieldConfigs) {
params.fieldConfigs = [
{
fn: DEFAULT_AGG_FUNCTION,
metricField: metricFieldOptions[0]?.name,
},
];
}
params.interval = bucketInterval?.expression!;
return params;
Expand Down Expand Up @@ -246,32 +235,21 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {
return mergedQuery;
}, [resultFilters, resultQuery, uiSettings, dataView, timeRange]);

const splitFieldCardinality = useSplitFieldCardinality(requestParams.splitField, combinedQuery);

const {
results: annotations,
isLoading: annotationsLoading,
progress,
pagination,
} = useChangePointResults(requestParams, combinedQuery, splitFieldCardinality);

if (!bucketInterval) return null;

const value = {
isLoading: annotationsLoading,
progress,
timeBuckets,
requestParams,
updateRequestParams,
metricFieldOptions,
splitFieldsOptions,
annotations,
bucketInterval,
resultFilters,
updateFilters,
resultQuery,
pagination,
splitFieldCardinality,
combinedQuery,
selectedChangePoints,
setSelectedChangePoints,
};

return (
Expand Down
Loading

0 comments on commit 8043a84

Please sign in to comment.