Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search Sessions] Use sync config #90138

Merged
merged 56 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
03f413a
Search Sessions: Unskip Flaky Functional Test
tsullivan Jan 26, 2021
2e09f56
Merge branch 'master' into flaky/search-sessions
tsullivan Jan 28, 2021
cb1de74
Save all search sessions and then manage them based on their persiste…
Jan 28, 2021
2b3b90e
Get default search session expiration from config
Jan 28, 2021
cd23cef
randomize sleep time
Jan 28, 2021
5f21181
fix test
Jan 28, 2021
cdcf562
fix test
Jan 28, 2021
bdbc748
Merge branch 'master' into sessions/save-all-sessions
kibanamachine Jan 28, 2021
667c9d3
Make sure we poll, and dont persist, searches not in the context of a…
Jan 28, 2021
867f1f4
Merge branch 'sessions/save-all-sessions' of github.com:lizozom/kiban…
Jan 28, 2021
51545ae
Merge branch 'master' of github.com:elastic/kibana into sessions/save…
Jan 28, 2021
763746b
Added keepalive unit tests
Jan 28, 2021
bbf85c5
Merge branch 'master' into sessions/save-all-sessions
kibanamachine Jan 29, 2021
01f292d
fix ts
Dosant Jan 29, 2021
7a85729
Merge branch 'master' into flaky/search-sessions
kibanamachine Jan 29, 2021
46cdf7f
Merge branch 'master' of github.com:elastic/kibana into sessions/save…
Jan 31, 2021
393d800
Merge branch 'sessions/save-all-sessions' of github.com:lizozom/kiban…
Jan 31, 2021
2d75b96
code review @lukasolson
Jan 31, 2021
13691e6
Merge branch 'master' of github.com:elastic/kibana into sessions/save…
Jan 31, 2021
1cd21fd
ts
Jan 31, 2021
a9cc263
More tests, rename onScreenTimeout to completedTimeout
Jan 31, 2021
bfcbdb2
lint
Jan 31, 2021
9b914f6
lint
Jan 31, 2021
ddb86a7
Merge branch 'master' into flaky/search-sessions
kibanamachine Jan 31, 2021
7ab767d
Delete async seaches
Jan 31, 2021
d924604
Support saved object pagination
Feb 1, 2021
11f429e
Merge branch 'master' of github.com:elastic/kibana into sessions/save…
Feb 1, 2021
48a90fb
better PersistedSearchSessionSavedObjectAttributes ts
Feb 1, 2021
de99c73
test titles
Feb 1, 2021
1bad580
Merge branch 'master' of github.com:elastic/kibana into sessions/save…
Feb 1, 2021
53a820e
Merge branch 'master' into sessions/save-all-sessions
kibanamachine Feb 1, 2021
ab0ce8f
Merge branch 'master' into sessions/save-all-sessions
kibanamachine Feb 1, 2021
89d0887
Merge branch 'master' into sessions/save-all-sessions
kibanamachine Feb 2, 2021
eb735ef
Merge branch 'master' of github.com:elastic/kibana into sessions/save…
Feb 2, 2021
f305245
Remove runAt from monitoring task
Feb 2, 2021
68c163d
Merge branch 'sessions/save-all-sessions' of github.com:lizozom/kiban…
Feb 2, 2021
d92996e
support workload histograms that take into account overdue tasks
gmmorris Feb 2, 2021
0587c27
Merge branch 'sessions/save-all-sessions' of https://github.com/lizoz…
gmmorris Feb 2, 2021
353f722
Update touched when changing session status to complete \ error
Feb 2, 2021
899d547
Merge branch 'sessions/save-all-sessions' of github.com:lizozom/kiban…
Feb 2, 2021
6bd93ac
removed test
Feb 2, 2021
a6491dd
Updated management test data
Feb 2, 2021
fc29c7f
Rename configs
Feb 2, 2021
d61fa45
Merge branch 'sessions/save-all-sessions' into pr/89370
Feb 2, 2021
2bd7e2b
delete tap first
Feb 3, 2021
cf45bb3
Merge branch 'master' of github.com:elastic/kibana into sessions/save…
Feb 3, 2021
19fa7e1
Merge branch 'sessions/save-all-sessions' of github.com:lizozom/kiban…
Feb 3, 2021
f0e4281
Use sync config in data-enhanced plugin
Feb 3, 2021
8e1dcf2
Merge branch 'master' of github.com:elastic/kibana into sessions/use-…
Feb 3, 2021
dbfd580
fix merge
Feb 3, 2021
c53310a
fix merge
Feb 3, 2021
a8325f7
Merge branch 'master' into sessions/use-sync-config
kibanamachine Feb 4, 2021
7cee454
ts
Feb 4, 2021
e78f7e2
Merge branch 'sessions/use-sync-config' of github.com:lizozom/kibana …
Feb 4, 2021
336f056
code review
Feb 5, 2021
3ff4185
Merge branch 'master' of github.com:elastic/kibana into sessions/use-…
Feb 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions x-pack/plugins/data_enhanced/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { CoreSetup, CoreStart, Logger, Plugin, PluginInitializerContext } from 'kibana/server';
import { Observable } from 'rxjs';
import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server';
import {
PluginSetup as DataPluginSetup,
Expand Down Expand Up @@ -40,11 +39,11 @@ export class EnhancedDataServerPlugin
implements Plugin<void, void, SetupDependencies, StartDependencies> {
private readonly logger: Logger;
private sessionService!: SearchSessionService;
private config$: Observable<ConfigSchema>;
private config: ConfigSchema;

constructor(private initializerContext: PluginInitializerContext<ConfigSchema>) {
this.logger = initializerContext.logger.get('data_enhanced');
this.config$ = this.initializerContext.config.create();
this.config = this.initializerContext.config.get<ConfigSchema>();
}

public setup(core: CoreSetup<DataPluginStart>, deps: SetupDependencies) {
Expand All @@ -56,7 +55,7 @@ export class EnhancedDataServerPlugin
deps.data.search.registerSearchStrategy(
ENHANCED_ES_SEARCH_STRATEGY,
enhancedEsSearchStrategyProvider(
this.config$,
this.config,
this.initializerContext.config.legacy.globalConfig$,
this.logger,
usage
Expand All @@ -68,10 +67,7 @@ export class EnhancedDataServerPlugin
eqlSearchStrategyProvider(this.logger)
);

this.sessionService = new SearchSessionService(
this.logger,
this.initializerContext.config.create()
);
this.sessionService = new SearchSessionService(this.logger, this.config);

deps.data.__enhance({
search: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ describe('ES search strategy', () => {
},
});

const mockConfig$ = new BehaviorSubject<any>({
const mockConfig: any = {
search: {
sessions: {
defaultExpiration: moment.duration('1', 'm'),
},
},
});
};

beforeEach(() => {
mockApiCaller.mockClear();
Expand All @@ -89,7 +89,7 @@ describe('ES search strategy', () => {

it('returns a strategy with `search and `cancel`', async () => {
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -104,7 +104,7 @@ describe('ES search strategy', () => {

const params = { index: 'logstash-*', body: { query: {} } };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -123,7 +123,7 @@ describe('ES search strategy', () => {

const params = { index: 'logstash-*', body: { query: {} } };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -142,7 +142,7 @@ describe('ES search strategy', () => {

const params = { index: 'foo-*', body: {} };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -160,7 +160,7 @@ describe('ES search strategy', () => {

const params = { index: 'foo-程', body: {} };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('ES search strategy', () => {

const params = { index: 'logstash-*', body: { query: {} } };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -209,7 +209,7 @@ describe('ES search strategy', () => {

const params = { index: 'logstash-*', body: { query: {} } };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('ES search strategy', () => {

const params = { index: 'logstash-*', body: { query: {} } };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -262,7 +262,7 @@ describe('ES search strategy', () => {

const params = { index: 'logstash-*', body: { query: {} } };
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -287,7 +287,7 @@ describe('ES search strategy', () => {

const id = 'some_id';
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -311,7 +311,7 @@ describe('ES search strategy', () => {

const id = 'some_id';
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -338,7 +338,7 @@ describe('ES search strategy', () => {
const id = 'some_other_id';
const keepAlive = '1d';
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand All @@ -357,7 +357,7 @@ describe('ES search strategy', () => {
const id = 'some_other_id';
const keepAlive = '1d';
const esSearch = await enhancedEsSearchStrategyProvider(
mockConfig$,
mockConfig,
mockLegacyConfig$,
mockLogger
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { ConfigSchema } from '../../config';
import { getKbnServerError, KbnServerError } from '../../../../../src/plugins/kibana_utils/server';

export const enhancedEsSearchStrategyProvider = (
config$: Observable<ConfigSchema>,
config: ConfigSchema,
legacyConfig$: Observable<SharedGlobalConfig>,
logger: Logger,
usage?: SearchUsage
Expand All @@ -60,7 +60,6 @@ export const enhancedEsSearchStrategyProvider = (
const client = esClient.asCurrentUser.asyncSearch;

const search = async () => {
const config = await config$.pipe(first()).toPromise();
const params = id
? getDefaultAsyncGetParams(options)
: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { Duration } from 'moment';
import {
TaskManagerSetupContract,
Expand All @@ -24,14 +22,13 @@ export const SEARCH_SESSIONS_TASK_ID = `data_enhanced_${SEARCH_SESSIONS_TASK_TYP
interface SearchSessionTaskDeps {
taskManager: TaskManagerSetupContract;
logger: Logger;
config$: Observable<ConfigSchema>;
config: ConfigSchema;
}

function searchSessionRunner(core: CoreSetup, { logger, config$ }: SearchSessionTaskDeps) {
function searchSessionRunner(core: CoreSetup, { logger, config }: SearchSessionTaskDeps) {
return ({ taskInstance }: RunContext) => {
return {
async run() {
const config = await config$.pipe(first()).toPromise();
const sessionConfig = config.search.sessions;
const [coreStart] = await core.getStartServices();
const internalRepo = coreStart.savedObjects.createInternalRepository([SEARCH_SESSION_TYPE]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { BehaviorSubject } from 'rxjs';
import {
SavedObject,
SavedObjectsClientContract,
Expand Down Expand Up @@ -46,7 +45,7 @@ describe('SearchSessionService', () => {

beforeEach(async () => {
savedObjectsClient = savedObjectsClientMock.create();
const config$ = new BehaviorSubject<ConfigSchema>({
const config: ConfigSchema = {
search: {
sessions: {
enabled: true,
Expand All @@ -59,13 +58,13 @@ describe('SearchSessionService', () => {
management: {} as any,
},
},
});
};
const mockLogger: any = {
debug: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};
service = new SearchSessionService(mockLogger, config$);
service = new SearchSessionService(mockLogger, config);
const coreStart = coreMock.createStart();
const mockTaskManager = taskManagerMock.createStart();
await flushPromises();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import {
CoreSetup,
CoreStart,
Expand Down Expand Up @@ -50,32 +48,33 @@ function sleep(ms: number) {
}
export class SearchSessionService
implements ISearchSessionService<SearchSessionSavedObjectAttributes> {
private config!: SearchSessionsConfig;
private sessionConfig!: SearchSessionsConfig;
lizozom marked this conversation as resolved.
Show resolved Hide resolved

constructor(
private readonly logger: Logger,
private readonly config$: Observable<ConfigSchema>
) {}
constructor(private readonly logger: Logger, private readonly config: ConfigSchema) {
this.sessionConfig = this.config.search.sessions;
}

public setup(core: CoreSetup, deps: SetupDependencies) {
registerSearchSessionsTask(core, {
config$: this.config$,
config: this.config,
taskManager: deps.taskManager,
logger: this.logger,
});
}

public async start(core: CoreStart, deps: StartDependencies) {
const configPromise = await this.config$.pipe(first()).toPromise();
this.config = (await configPromise).search.sessions;
return this.setupMonitoring(core, deps);
}

public stop() {}

private setupMonitoring = async (core: CoreStart, deps: StartDependencies) => {
if (this.config.enabled) {
scheduleSearchSessionsTasks(deps.taskManager, this.logger, this.config.trackingInterval);
if (this.sessionConfig.enabled) {
scheduleSearchSessionsTasks(
deps.taskManager,
this.logger,
this.sessionConfig.trackingInterval
);
}
};

Expand Down Expand Up @@ -107,7 +106,7 @@ export class SearchSessionService
} catch (createError) {
if (
SavedObjectsErrorHelpers.isConflictError(createError) &&
retry < this.config.maxUpdateRetries
retry < this.sessionConfig.maxUpdateRetries
) {
return await retryOnConflict(createError);
} else {
Expand All @@ -116,7 +115,7 @@ export class SearchSessionService
}
} else if (
SavedObjectsErrorHelpers.isConflictError(e) &&
retry < this.config.maxUpdateRetries
retry < this.sessionConfig.maxUpdateRetries
) {
return await retryOnConflict(e);
} else {
Expand Down Expand Up @@ -164,7 +163,7 @@ export class SearchSessionService
sessionId,
status: SearchSessionStatus.IN_PROGRESS,
expires: new Date(
Date.now() + this.config.defaultExpiration.asMilliseconds()
Date.now() + this.sessionConfig.defaultExpiration.asMilliseconds()
).toISOString(),
created: new Date().toISOString(),
touched: new Date().toISOString(),
Expand Down