Skip to content

Commit

Permalink
Change default page size
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Fernández Gómez committed Dec 27, 2019
1 parent 3dee2d4 commit a4f3b12
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
LogEntryDocument,
LogEntryQuery,
LogSummaryBucket,
LOG_ENTRIES_PAGE_SIZE,
} from '../../domains/log_entries_domain';
import { InfraSourceConfiguration } from '../../sources';
import { SortedSearchHit } from '../framework';
Expand Down Expand Up @@ -89,7 +90,7 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter {
fields: string[],
params: LogEntriesParams
): Promise<LogEntryDocument[]> {
const { startDate, endDate, query, cursor } = params;
const { startDate, endDate, query, cursor, size } = params;

const { sortDirection, searchAfterClause } = processCursor(cursor);

Expand All @@ -103,7 +104,7 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter {
index: sourceConfiguration.logAlias,
ignoreUnavailable: true,
body: {
size: 10,
size: size ? size : LOG_ENTRIES_PAGE_SIZE,
track_total_hits: false,
query: {
bool: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ import {
export interface LogEntriesParams {
startDate: number;
endDate: number;
size?: number;
query?: JsonObject;
cursor?: { before: LogEntriesCursor | 'last' } | { after: LogEntriesCursor | 'first' };
}
export interface LogEntriesAroundParams {
startDate: number;
endDate: number;
size?: number;
center: LogEntriesCursor;
query?: JsonObject;
}

export const LOG_ENTRIES_PAGE_SIZE = 200;

export class InfraLogEntriesDomain {
constructor(
private readonly adapter: LogEntriesAdapter,
Expand All @@ -60,16 +64,28 @@ export class InfraLogEntriesDomain {
sourceId: string,
params: LogEntriesAroundParams
) {
const { startDate, endDate, center, query } = params;
const { startDate, endDate, center, query, size } = params;

/*
* For odd sizes we will round this value down for the first half, and up
* for the second. This keeps the center cursor right in the center.
*
* For even sizes the half before is one entry bigger than the half after.
* [1, 2, 3, 4, 5, *6*, 7, 8, 9, 10]
* | 5 entries | |4 entries|
*/
const halfSize = (size || LOG_ENTRIES_PAGE_SIZE) / 2;

const entriesBefore = await this.getLogEntries(requestContext, sourceId, {
startDate,
endDate,
query,
cursor: { before: center },
size: Math.floor(halfSize),
});

/* Elasticsearch's `search_after` returns documents after the specified cursor.
/*
* Elasticsearch's `search_after` returns documents after the specified cursor.
* - If we have documents before the center, we search after the last of
* those. The first document of the new group is the center.
* - If there were no documents, we search one milisecond before the
Expand All @@ -85,6 +101,7 @@ export class InfraLogEntriesDomain {
endDate,
query,
cursor: { after: cursorAfter },
size: Math.ceil(halfSize),
});

return [...entriesBefore, ...entriesAfter];
Expand Down

0 comments on commit a4f3b12

Please sign in to comment.