Skip to content

Commit

Permalink
Merge branch 'master' into vis_type_timeseries_enchanced
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jan 26, 2021
2 parents 7ea188e + 3121e47 commit 40d4af8
Show file tree
Hide file tree
Showing 39 changed files with 420 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface CallCluster {
(path: 'bulk', opts: { body: object[] }): Promise<BulkResult>;
(path: 'count', opts: CountOpts): Promise<{ count: number; _shards: ShardsInfo }>;
(path: 'clearScroll', opts: { scrollId: string }): Promise<any>;
(path: 'indices.create' | 'indices.delete', opts: IndexCreationOpts): Promise<any>;
(path: 'indices.create', opts: IndexCreationOpts): Promise<any>;
(path: 'indices.exists', opts: IndexOpts): Promise<boolean>;
(path: 'indices.existsAlias', opts: { name: string }): Promise<boolean>;
(path: 'indices.get', opts: IndexOpts & Ignorable): Promise<IndicesInfo | NotFound>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ describe('ElasticIndex', () => {
});
});

describe('deleteIndex', () => {
test('calls indices.delete', async () => {
await Index.deleteIndex(client, '.lotr');

expect(client.indices.delete).toHaveBeenCalledTimes(1);
expect(client.indices.delete).toHaveBeenCalledWith({
index: '.lotr',
});
});
});

describe('claimAlias', () => {
test('handles unaliased indices', async () => {
client.indices.getAlias.mockResolvedValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,6 @@ export async function createIndex(
});
}

export async function deleteIndex(client: MigrationEsClient, index: string) {
await client.indices.delete({ index });
}

/**
* Converts an index to an alias. The `alias` parameter is the desired alias name which currently
* is a concrete index. This function will reindex `alias` into a new index, delete the `alias`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const methods = [
'clearScroll',
'count',
'indices.create',
'indices.delete',
'indices.deleteTemplate',
'indices.get',
'indices.getAlias',
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/data_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export class DataEnhancedPlugin

this.config = this.initializerContext.config.get<ConfigSchema>();
if (this.config.search.sessions.enabled) {
const { management: sessionsMgmtConfig } = this.config.search.sessions;
registerSearchSessionsMgmt(core, sessionsMgmtConfig, { management });
const sessionsConfig = this.config.search.sessions;
registerSearchSessionsMgmt(core, sessionsConfig, { management });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
AppDependencies,
IManagementSectionsPluginsSetup,
IManagementSectionsPluginsStart,
SessionsMgmtConfigSchema,
SessionsConfigSchema,
} from '../';
import { APP } from '../';
import { SearchSessionsMgmtAPI } from '../lib/api';
Expand All @@ -20,7 +20,7 @@ import { renderApp } from './render';
export class SearchSessionsMgmtApp {
constructor(
private coreSetup: CoreSetup<IManagementSectionsPluginsStart>,
private config: SessionsMgmtConfigSchema,
private config: SessionsConfigSchema,
private params: ManagementAppMountParams,
private pluginsSetup: IManagementSectionsPluginsSetup
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { useState } from 'react';
import { Duration } from 'moment';
import moment from 'moment';
import { SearchSessionsMgmtAPI } from '../../lib/api';
import { TableText } from '../';
import { OnActionComplete } from './types';

interface ExtendButtonProps {
id: string;
name: string;
expires: string | null;
extendBy: Duration;
api: SearchSessionsMgmtAPI;
onActionComplete: OnActionComplete;
}
Expand All @@ -23,8 +27,11 @@ const ExtendConfirm = ({
onConfirmDismiss,
...props
}: ExtendButtonProps & { onConfirmDismiss: () => void }) => {
const { id, name, api, onActionComplete } = props;
const { id, name, expires, api, extendBy, onActionComplete } = props;
const [isLoading, setIsLoading] = useState(false);
const extendByDuration = moment.duration(extendBy);

const newExpiration = moment(expires).add(extendByDuration);

const title = i18n.translate('xpack.data.mgmt.searchSessions.extendModal.title', {
defaultMessage: 'Extend search session expiration',
Expand All @@ -36,9 +43,10 @@ const ExtendConfirm = ({
defaultMessage: 'Cancel',
});
const message = i18n.translate('xpack.data.mgmt.searchSessions.extendModal.extendMessage', {
defaultMessage: "When would you like the search session '{name}' to expire?",
defaultMessage: "The search session '{name}' expiration would be extended until {newExpires}.",
values: {
name,
newExpires: newExpiration.toLocaleString(),
},
});

Expand All @@ -49,7 +57,7 @@ const ExtendConfirm = ({
onCancel={onConfirmDismiss}
onConfirm={async () => {
setIsLoading(true);
await api.sendExtend(id, '1');
await api.sendExtend(id, `${extendByDuration.asMilliseconds()}ms`);
onActionComplete();
}}
confirmButtonText={confirm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ACTION, OnActionComplete } from './types';
export const getAction = (
api: SearchSessionsMgmtAPI,
actionType: string,
{ id, name, reloadUrl }: UISession,
{ id, name, expires, reloadUrl }: UISession,
onActionComplete: OnActionComplete
): IClickActionDescriptor | null => {
switch (actionType) {
Expand All @@ -39,7 +39,16 @@ export const getAction = (
return {
iconType: extendSessionIcon,
textColor: 'default',
label: <ExtendButton api={api} id={id} name={name} onActionComplete={onActionComplete} />,
label: (
<ExtendButton
api={api}
id={id}
name={name}
expires={expires}
extendBy={api.getExtendByDuration()}
onActionComplete={onActionComplete}
/>
),
};

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import { coreMock } from 'src/core/public/mocks';
import { SessionsClient } from 'src/plugins/data/public/search';
import { SessionsMgmtConfigSchema } from '..';
import { SessionsConfigSchema } from '..';
import { SearchSessionsMgmtAPI } from '../lib/api';
import { AsyncSearchIntroDocumentation } from '../lib/documentation';
import { LocaleWrapper, mockUrls } from '../__mocks__';
import { SearchSessionsMgmtMain } from './main';

let mockCoreSetup: MockedKeys<CoreSetup>;
let mockCoreStart: MockedKeys<CoreStart>;
let mockConfig: SessionsMgmtConfigSchema;
let mockConfig: SessionsConfigSchema;
let sessionsClient: SessionsClient;
let api: SearchSessionsMgmtAPI;

Expand All @@ -29,11 +29,14 @@ describe('Background Search Session Management Main', () => {
mockCoreSetup = coreMock.createSetup();
mockCoreStart = coreMock.createStart();
mockConfig = {
expiresSoonWarning: moment.duration(1, 'days'),
maxSessions: 2000,
refreshInterval: moment.duration(1, 'seconds'),
refreshTimeout: moment.duration(10, 'minutes'),
};
defaultExpiration: moment.duration('7d'),
management: {
expiresSoonWarning: moment.duration(1, 'days'),
maxSessions: 2000,
refreshInterval: moment.duration(1, 'seconds'),
refreshTimeout: moment.duration(10, 'minutes'),
},
} as any;

sessionsClient = new SessionsClient({ http: mockCoreSetup.http });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { FormattedMessage } from '@kbn/i18n/react';
import type { CoreStart, HttpStart } from 'kibana/public';
import React from 'react';
import type { SessionsMgmtConfigSchema } from '../';
import type { SessionsConfigSchema } from '../';
import type { SearchSessionsMgmtAPI } from '../lib/api';
import type { AsyncSearchIntroDocumentation } from '../lib/documentation';
import { TableText } from './';
Expand All @@ -29,7 +29,7 @@ interface Props {
api: SearchSessionsMgmtAPI;
http: HttpStart;
timezone: string;
config: SessionsMgmtConfigSchema;
config: SessionsConfigSchema;
}

export function SearchSessionsMgmtMain({ documentation, ...tableProps }: Props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import React from 'react';
import { coreMock } from 'src/core/public/mocks';
import { SessionsClient } from 'src/plugins/data/public/search';
import { SearchSessionStatus } from '../../../../../common/search';
import { SessionsMgmtConfigSchema } from '../../';
import { SessionsConfigSchema } from '../../';
import { SearchSessionsMgmtAPI } from '../../lib/api';
import { LocaleWrapper, mockUrls } from '../../__mocks__';
import { SearchSessionsMgmtTable } from './table';

let mockCoreSetup: MockedKeys<CoreSetup>;
let mockCoreStart: CoreStart;
let mockConfig: SessionsMgmtConfigSchema;
let mockConfig: SessionsConfigSchema;
let sessionsClient: SessionsClient;
let api: SearchSessionsMgmtAPI;

Expand All @@ -29,11 +29,14 @@ describe('Background Search Session Management Table', () => {
mockCoreSetup = coreMock.createSetup();
mockCoreStart = coreMock.createStart();
mockConfig = {
expiresSoonWarning: moment.duration(1, 'days'),
maxSessions: 2000,
refreshInterval: moment.duration(1, 'seconds'),
refreshTimeout: moment.duration(10, 'minutes'),
};
defaultExpiration: moment.duration('7d'),
management: {
expiresSoonWarning: moment.duration(1, 'days'),
maxSessions: 2000,
refreshInterval: moment.duration(1, 'seconds'),
refreshTimeout: moment.duration(10, 'minutes'),
},
} as any;

sessionsClient = new SessionsClient({ http: mockCoreSetup.http });
api = new SearchSessionsMgmtAPI(sessionsClient, mockConfig, {
Expand Down Expand Up @@ -134,7 +137,10 @@ describe('Background Search Session Management Table', () => {
sessionsClient.find = jest.fn();
mockConfig = {
...mockConfig,
refreshInterval: moment.duration(10, 'seconds'),
management: {
...mockConfig.management,
refreshInterval: moment.duration(10, 'seconds'),
},
};

await act(async () => {
Expand Down Expand Up @@ -162,8 +168,11 @@ describe('Background Search Session Management Table', () => {

mockConfig = {
...mockConfig,
refreshInterval: moment.duration(1, 'day'),
refreshTimeout: moment.duration(2, 'days'),
management: {
...mockConfig.management,
refreshInterval: moment.duration(1, 'day'),
refreshTimeout: moment.duration(2, 'days'),
},
};

await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React, { useCallback, useMemo, useRef, useEffect, useState } from 'react'
import useDebounce from 'react-use/lib/useDebounce';
import useInterval from 'react-use/lib/useInterval';
import { TableText } from '../';
import { SessionsMgmtConfigSchema } from '../..';
import { SessionsConfigSchema } from '../..';
import { SearchSessionsMgmtAPI } from '../../lib/api';
import { getColumns } from '../../lib/get_columns';
import { UISession } from '../../types';
Expand All @@ -26,7 +26,7 @@ interface Props {
core: CoreStart;
api: SearchSessionsMgmtAPI;
timezone: string;
config: SessionsMgmtConfigSchema;
config: SessionsConfigSchema;
}

export function SearchSessionsMgmtTable({ core, api, timezone, config, ...props }: Props) {
Expand All @@ -35,9 +35,10 @@ export function SearchSessionsMgmtTable({ core, api, timezone, config, ...props
const [debouncedIsLoading, setDebouncedIsLoading] = useState(false);
const [pagination, setPagination] = useState({ pageIndex: 0 });
const showLatestResultsHandler = useRef<Function>();
const refreshInterval = useMemo(() => moment.duration(config.refreshInterval).asMilliseconds(), [
config.refreshInterval,
]);
const refreshInterval = useMemo(
() => moment.duration(config.management.refreshInterval).asMilliseconds(),
[config.management.refreshInterval]
);

// Debounce rendering the state of the Refresh button
useDebounce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface AppDependencies {
api: SearchSessionsMgmtAPI;
http: HttpStart;
i18n: I18nStart;
config: SessionsMgmtConfigSchema;
config: SessionsConfigSchema;
}

export const APP = {
Expand All @@ -44,11 +44,11 @@ export const APP = {
}),
};

export type SessionsMgmtConfigSchema = ConfigSchema['search']['sessions']['management'];
export type SessionsConfigSchema = ConfigSchema['search']['sessions'];

export function registerSearchSessionsMgmt(
coreSetup: CoreSetup<DataEnhancedStartDependencies>,
config: SessionsMgmtConfigSchema,
config: SessionsConfigSchema,
services: IManagementSectionsPluginsSetup
) {
services.management.sections.section.kibana.registerApp({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@ import { coreMock } from 'src/core/public/mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import type { SavedObjectsFindResponse } from 'src/core/server';
import { SessionsClient } from 'src/plugins/data/public/search';
import type { SessionsMgmtConfigSchema } from '../';
import type { SessionsConfigSchema } from '../';
import { SearchSessionStatus } from '../../../../common/search';
import { mockUrls } from '../__mocks__';
import { SearchSessionsMgmtAPI } from './api';

let mockCoreSetup: MockedKeys<CoreSetup>;
let mockCoreStart: MockedKeys<CoreStart>;
let mockConfig: SessionsMgmtConfigSchema;
let mockConfig: SessionsConfigSchema;
let sessionsClient: SessionsClient;

describe('Search Sessions Management API', () => {
beforeEach(() => {
mockCoreSetup = coreMock.createSetup();
mockCoreStart = coreMock.createStart();
mockConfig = {
expiresSoonWarning: moment.duration('1d'),
maxSessions: 2000,
refreshInterval: moment.duration('1s'),
refreshTimeout: moment.duration('10m'),
};
defaultExpiration: moment.duration('7d'),
management: {
expiresSoonWarning: moment.duration(1, 'days'),
maxSessions: 2000,
refreshInterval: moment.duration(1, 'seconds'),
refreshTimeout: moment.duration(10, 'minutes'),
},
} as any;

sessionsClient = new SessionsClient({ http: mockCoreSetup.http });
});
Expand Down Expand Up @@ -93,8 +96,11 @@ describe('Search Sessions Management API', () => {
test('handle timeout error', async () => {
mockConfig = {
...mockConfig,
refreshInterval: moment.duration(1, 'hours'),
refreshTimeout: moment.duration(1, 'seconds'),
management: {
...mockConfig.management,
refreshInterval: moment.duration(1, 'hours'),
refreshTimeout: moment.duration(1, 'seconds'),
},
};

sessionsClient.find = jest.fn().mockImplementation(async () => {
Expand Down
Loading

0 comments on commit 40d4af8

Please sign in to comment.