Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into task/olm-5369-uploa…
Browse files Browse the repository at this point in the history
…d-response-action-api
  • Loading branch information
paul-tavares committed May 3, 2023
2 parents 5ed98c0 + 506806f commit 9969053
Show file tree
Hide file tree
Showing 82 changed files with 1,708 additions and 440 deletions.
33 changes: 17 additions & 16 deletions docs/canvas/canvas-function-reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ Aliases: `q`, `query`
Default: `"-_index:.kibana"`

|`index`

Alias: `dataView`
|`string`
|An index or data view. For example, `"logstash-*"`.

Expand Down Expand Up @@ -1087,6 +1089,8 @@ Default: `1000`
|A comma-separated list of fields. For better performance, use fewer fields.

|`index`

Alias: `dataView`
|`string`
|An index or data view. For example, `"logstash-*"`.

Expand Down Expand Up @@ -1128,7 +1132,7 @@ kibana
----
This retrieves the `Carrier`, `FlightDelayMin`, and `AvgTicketPrice` fields from the "kibana_sample_data_flights" index.

*Accepts:* `filter`
*Accepts:* `kibana_context`, `null`

[cols="3*^<"]
|===
Expand All @@ -1152,6 +1156,12 @@ Alias: `param`
|`string`, `number`, `boolean`
|A parameter to be passed to the SQL query.

|`timeField`

Alias: `timeField`
|`string`
|The time field to use in the time range filter, which is set in the context.

|`timezone`

Alias: `tz`
Expand All @@ -1178,19 +1188,6 @@ exactly "age" value=50 filterGroup="group2"
exactly column="project" value="beats"
----

*Code example*
[source,text]
----
kibana
| selectFilter
| exactly column=project value=elasticsearch
| demodata
| pointseries x=project y="mean(age)"
| plot defaultStyle={seriesStyle bars=1}
| render
----
The `exactly` filter here is added to existing filters retrieved by the `filters` function and further filters down the data to only have `"elasticsearch"` data. The `exactly` filter only applies to this one specific element and will not affect other elements in the workpad.

*Accepts:* `filter`

[cols="3*^<"]
Expand Down Expand Up @@ -1270,7 +1267,7 @@ Aliases: `exp`, `expression`, `fn`, `function`
[[filters_fn]]
=== `filters`

Aggregates element filters from the workpad for use elsewhere, usually a data source.
Aggregates element filters from the workpad for use elsewhere, usually a data source. <<filters_fn>> is deprecated and will be removed in a future release. Use `kibana | selectFilter` instead.

*Expression syntax*
[source,js]
Expand Down Expand Up @@ -1935,7 +1932,7 @@ Alias: `expression`
[[mathColumn_fn]]
=== `mathColumn`

Adds a column by evaluating TinyMath on each row. This function is optimized for math, so it performs better than the mapColumn with a math
Adds a column by evaluating `TinyMath` on each row. This function is optimized for math and performs better than using a math expression in <<mapColumn_fn>>.

*Accepts:* `datatable`

Expand All @@ -1955,6 +1952,10 @@ Alias: `expression`
|`string`
|An evaluated `TinyMath` expression. See https://www.elastic.co/guide/en/kibana/current/canvas-tinymath-functions.html.

|`castColumns` †
|`string`
|The column ids that are cast to numbers before the formula is applied.

|`copyMetaFrom`
|`string`, `null`
|If set, the meta object from the specified column id is copied over to the specified target column. If the column doesn't exist it silently fails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('migration from 7.7.2-xpack with 100k objects', () => {
await esServer.stop();
}

await new Promise((resolve) => setTimeout(resolve, 10000));
await new Promise((resolve) => setTimeout(resolve, 20000));
};

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import React from 'react';

import { EuiSuperDatePicker } from '@elastic/eui';

import { useUrlState } from '@kbn/ml-url-state';
import type { UI_SETTINGS } from '@kbn/data-plugin/common';

import { useDatePickerContext } from '../hooks/use_date_picker_context';
import { mlTimefilterRefresh$ } from '../services/timefilter_refresh_service';

import { DatePickerWrapper } from './date_picker_wrapper';
import { useRefreshIntervalUpdates } from '../..';

jest.mock('@elastic/eui', () => {
const EuiButtonMock = jest.fn(() => {
Expand Down Expand Up @@ -51,7 +51,12 @@ jest.mock('@kbn/ml-url-state', () => {
});

jest.mock('../hooks/use_timefilter', () => ({
useRefreshIntervalUpdates: jest.fn(),
useRefreshIntervalUpdates: jest.fn(() => {
return {
pause: false,
};
}),

useTimefilter: () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { of } = require('rxjs');
Expand Down Expand Up @@ -152,7 +157,7 @@ describe('<DatePickerWrapper />', () => {

test('should set interval to default of 5s when pause is disabled and refresh interval is 0', () => {
// arrange
(useUrlState as jest.Mock).mockReturnValue([{ refreshInterval: { pause: false, value: 0 } }]);
(useRefreshIntervalUpdates as jest.Mock).mockReturnValue({ pause: false, value: 0 });

const displayWarningSpy = jest.fn(() => {});

Expand All @@ -171,7 +176,7 @@ describe('<DatePickerWrapper />', () => {

test('should show a warning when configured interval is too short', () => {
// arrange
(useUrlState as jest.Mock).mockReturnValue([{ refreshInterval: { pause: false, value: 10 } }]);
(useRefreshIntervalUpdates as jest.Mock).mockReturnValue({ pause: false, value: 10 });

const displayWarningSpy = jest.fn(() => {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const DatePickerWrapper: FC<DatePickerWrapperProps> = (props) => {
const time = useTimeRangeUpdates();

useEffect(
function syncTimRangeFromUrlState() {
function syncTimeRangeFromUrlState() {
if (globalState?.time !== undefined) {
timefilter.setTime({
from: globalState.time.from,
Expand Down Expand Up @@ -162,11 +162,7 @@ export const DatePickerWrapper: FC<DatePickerWrapperProps> = (props) => {
timefilter.isTimeRangeSelectorEnabled()
);

const refreshInterval = useMemo(
(): RefreshInterval => globalState?.refreshInterval ?? timeFilterRefreshInterval,
// eslint-disable-next-line react-hooks/exhaustive-deps
[JSON.stringify(globalState?.refreshInterval), timeFilterRefreshInterval]
);
const refreshInterval = timeFilterRefreshInterval;

useEffect(
function warnAboutShortRefreshInterval() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { type FC, useMemo, useState } from 'react';
import React, { type FC, useMemo, useState, useEffect, useRef } from 'react';
import {
EuiBadge,
EuiDescriptionList,
Expand All @@ -21,7 +21,9 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { SelectedChangePoint } from './change_point_detection_context';
import { useTimefilter } from '@kbn/ml-date-picker';
import { type RefreshInterval } from '@kbn/data-plugin/common';
import { type SelectedChangePoint } from './change_point_detection_context';
import { ChartComponent } from './chart_component';

const CHARTS_PER_PAGE = 6;
Expand All @@ -31,6 +33,28 @@ interface ChartsGridProps {
}

export const ChartsGrid: FC<ChartsGridProps> = ({ changePoints: changePointsDict }) => {
const timefilter = useTimefilter();

const initialRefreshSetting = useRef<RefreshInterval>();

useEffect(
function pauseRefreshOnMount() {
initialRefreshSetting.current = timefilter.getRefreshInterval();

timefilter.setRefreshInterval({
...initialRefreshSetting.current,
pause: true,
});
return () => {
if (initialRefreshSetting.current) {
// reset initial settings
timefilter.setRefreshInterval(initialRefreshSetting.current);
}
};
},
[timefilter]
);

const changePoints = useMemo(() => {
return Object.values(changePointsDict).flat();
}, [changePointsDict]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { FilterStateStore } from '@kbn/es-query';
import moment from 'moment';
import { FilterStateStore, type TimeRange } from '@kbn/es-query';
import { type TypedLensByValueInput } from '@kbn/lens-plugin/public';
import { useTimeRangeUpdates } from '@kbn/ml-date-picker';
import { useMemo } from 'react';
Expand Down Expand Up @@ -33,6 +34,17 @@ export const useCommonChartProps = ({
const { dataView } = useDataSource();
const { bucketInterval, resultQuery, resultFilters } = useChangePointDetectionContext();

/**
* In order to correctly render annotations for change points at the edges,
* we need to adjust time bound based on the change point timestamp.
*/
const chartTimeRange = useMemo<TimeRange>(() => {
return {
from: moment.min(moment(timeRange.from), moment(annotation.timestamp)).toISOString(),
to: moment.max(moment(timeRange.to), moment(annotation.timestamp)).toISOString(),
};
}, [timeRange, annotation.timestamp]);

const filters = useMemo(() => {
return [
...resultFilters,
Expand Down Expand Up @@ -214,7 +226,7 @@ export const useCommonChartProps = ({
]);

return {
timeRange,
timeRange: chartTimeRange,
filters,
query: resultQuery,
attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ describe('useFindMaintenanceWindows', () => {
expect(mockAddDanger).toBeCalledWith('Unable to load maintenance windows.')
);
});

it('should not try to find maintenance windows if not enabled', async () => {
renderHook(() => useFindMaintenanceWindows({ enabled: false }), {
wrapper: appMockRenderer.AppWrapper,
});

await waitFor(() => expect(findMaintenanceWindows).toHaveBeenCalledTimes(0));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import { useQuery } from '@tanstack/react-query';
import { useKibana } from '../utils/kibana_react';
import { findMaintenanceWindows } from '../services/maintenance_windows_api/find';

export const useFindMaintenanceWindows = () => {
interface UseFindMaintenanceWindowsProps {
enabled?: boolean;
}

export const useFindMaintenanceWindows = (props?: UseFindMaintenanceWindowsProps) => {
const { enabled = true } = props || {};

const {
http,
notifications: { toasts },
Expand All @@ -32,6 +38,7 @@ export const useFindMaintenanceWindows = () => {

const {
isLoading,
isFetching,
data = [],
refetch,
} = useQuery({
Expand All @@ -41,11 +48,12 @@ export const useFindMaintenanceWindows = () => {
refetchOnWindowFocus: false,
retry: false,
cacheTime: 0,
enabled,
});

return {
maintenanceWindows: data,
isLoading,
isLoading: enabled && (isLoading || isFetching),
refetch,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const LicensePrompt = React.memo(() => {
>
{i18n.UPGRADE_SUBSCRIPTION}
</EuiButtonEmpty>
,
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
Expand All @@ -58,7 +57,6 @@ export const LicensePrompt = React.memo(() => {
>
{i18n.START_TRIAL}
</EuiButton>
,
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ export const MaintenanceWindowsPage = React.memo(() => {
docLinks,
} = useKibana().services;
const { isAtLeastPlatinum } = useLicense();
const hasLicense = isAtLeastPlatinum();

const { navigateToCreateMaintenanceWindow } = useCreateMaintenanceWindowNavigation();

const { isLoading, maintenanceWindows, refetch } = useFindMaintenanceWindows();
const { isLoading, maintenanceWindows, refetch } = useFindMaintenanceWindows({
enabled: hasLicense,
});

useBreadcrumbs(AlertingDeepLinkId.maintenanceWindows);

Expand All @@ -56,7 +59,6 @@ export const MaintenanceWindowsPage = React.memo(() => {
maintenanceWindows.length === 0 &&
showWindowMaintenance &&
writeWindowMaintenance;
const hasLicense = isAtLeastPlatinum();

const readOnly = showWindowMaintenance && !writeWindowMaintenance;

Expand Down
Loading

0 comments on commit 9969053

Please sign in to comment.