Skip to content

Commit

Permalink
Merge branch 'sessions/retry-logic' of github.com:lizozom/kibana into…
Browse files Browse the repository at this point in the history
… sessions/retry-logic
  • Loading branch information
Liza K committed Dec 8, 2020
2 parents 6c9e345 + 0858b98 commit e85da48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { BACKGROUND_SESSION_TYPE } from '../../saved_objects';
import { createRequestHash } from './utils';
import { ConfigSchema } from '../../../config';

const INMEM_MAX_SESSIONS = 10000;
const DEFAULT_EXPIRATION = 7 * 24 * 60 * 60 * 1000;
export const INMEM_TRACKING_INTERVAL = 10 * 1000;
export const INMEM_TRACKING_TIMEOUT_SEC = 60;
Expand Down Expand Up @@ -93,6 +94,7 @@ export class BackgroundSessionService implements ISessionService {
.map((sessionId) => `"${sessionId}"`)
.join(' | ');
const res = await this.internalSavedObjectsClient.find<BackgroundSessionSavedObjectAttributes>({
perPage: INMEM_MAX_SESSIONS, // If there are more sessions in memory, they will be synced when some items are cleared out.
type: BACKGROUND_SESSION_TYPE,
search: activeMappingIds,
searchFields: ['sessionId'],
Expand All @@ -104,6 +106,7 @@ export class BackgroundSessionService implements ISessionService {

private clearSessions = () => {
const curTime = moment();

this.sessionSearchMap.forEach((sessionInfo, sessionId) => {
if (
moment.duration(curTime.diff(sessionInfo.insertTime)).asSeconds() >
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/data_enhanced/server/search/session/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { createHash } from 'crypto';
import stringify from 'json-stable-stringify';

/**
* Generate the hash for this request so that, in the future, this hash can be used to look up
Expand All @@ -13,5 +14,5 @@ import { createHash } from 'crypto';
*/
export function createRequestHash(keys: Record<any, any>) {
const { preference, ...params } = keys;
return createHash(`sha256`).update(JSON.stringify(params)).digest('hex');
return createHash(`sha256`).update(stringify(params)).digest('hex');
}

0 comments on commit e85da48

Please sign in to comment.