Skip to content

Commit

Permalink
Normalize *Date and *Timestamp names in the APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Fernández Gómez committed Feb 5, 2020
1 parent 727bc30 commit 6ba0eaf
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const LOG_ENTRIES_PATH = '/api/log_entries/entries';
export const logEntriesBaseRequestRT = rt.intersection([
rt.type({
sourceId: rt.string,
startDate: rt.number,
endDate: rt.number,
startTimestamp: rt.number,
endTimestamp: rt.number,
}),
rt.partial({
query: rt.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const LOG_ENTRIES_SUMMARY_PATH = '/api/log_entries/summary';

export const logEntriesSummaryRequestRT = rt.type({
sourceId: rt.string,
startDate: rt.number,
endDate: rt.number,
startTimestamp: rt.number,
endTimestamp: rt.number,
bucketSize: rt.number,
query: rt.union([rt.string, rt.undefined, rt.null]),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ const useFetchEntriesEffect = (
try {
const fetchArgs: LogEntriesRequest = {
sourceId: overrides.sourceId || props.sourceId,
startDate: overrides.startTimestamp || props.startTimestamp,
endDate: overrides.endTimestamp || props.endTimestamp,
startTimestamp: overrides.startTimestamp || props.startTimestamp,
endTimestamp: overrides.endTimestamp || props.endTimestamp,
query: overrides.filterQuery || props.filterQuery || undefined, // FIXME
};

Expand Down Expand Up @@ -195,8 +195,8 @@ const useFetchEntriesEffect = (
try {
const fetchArgs: LogEntriesRequest = {
sourceId: props.sourceId,
startDate: props.startTimestamp,
endDate: props.endTimestamp,
startTimestamp: props.startTimestamp,
endTimestamp: props.endTimestamp,
query: props.filterQuery || undefined, // FIXME
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const useLogEntryHighlights = (

return await fetchLogEntriesHighlights({
sourceId,
startDate: getPreviousTimeKey(startKey).time,
endDate: getNextTimeKey(endKey).time,
startTimestamp: getPreviousTimeKey(startKey).time,
endTimestamp: getNextTimeKey(endKey).time,
query: filterQuery || undefined,
highlightTerms,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const useLogSummaryHighlights = (

return await fetchLogSummaryHighlights({
sourceId,
startDate: startTimestamp,
endDate: endTimestamp,
startTimestamp,
endTimestamp,
bucketSize,
query: filterQuery,
highlightTerms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useState, useMemo } from 'react';
import { useState } from 'react';

import { useCancellableEffect } from '../../../utils/cancellable_effect';
import { fetchLogSummary } from './api/fetch_log_summary';
Expand Down Expand Up @@ -32,8 +32,8 @@ export const useLogSummary = (

fetchLogSummary({
sourceId,
startDate: startTimestamp,
endDate: endTimestamp,
startTimestamp,
endTimestamp,
bucketSize,
query: filterQuery,
}).then(response => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter {
fields: string[],
params: LogEntriesParams
): Promise<LogEntryDocument[]> {
const { startDate, endDate, query, cursor, size, highlightTerm } = params;
const { startTimestamp, endTimestamp, query, cursor, size, highlightTerm } = params;

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

Expand Down Expand Up @@ -137,8 +137,8 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter {
{
range: {
[sourceConfiguration.fields.timestamp]: {
gte: startDate,
lte: endDate,
gte: startTimestamp,
lte: endTimestamp,
format: TIMESTAMP_FORMAT,
},
},
Expand Down Expand Up @@ -190,12 +190,16 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter {
public async getContainedLogSummaryBuckets(
requestContext: RequestHandlerContext,
sourceConfiguration: InfraSourceConfiguration,
start: number,
end: number,
startTimestamp: number,
endTimestamp: number,
bucketSize: number,
filterQuery?: LogEntryQuery
): Promise<LogSummaryBucket[]> {
const bucketIntervalStarts = timeMilliseconds(new Date(start), new Date(end), bucketSize);
const bucketIntervalStarts = timeMilliseconds(
new Date(startTimestamp),
new Date(endTimestamp),
bucketSize
);

const query = {
allowNoIndices: true,
Expand Down Expand Up @@ -233,8 +237,8 @@ export class InfraKibanaLogEntriesAdapter implements LogEntriesAdapter {
{
range: {
[sourceConfiguration.fields.timestamp]: {
gte: start,
lte: end,
gte: startTimestamp,
lte: endTimestamp,
format: TIMESTAMP_FORMAT,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ import {
} from './message';

export interface LogEntriesParams {
startDate: number;
endDate: number;
startTimestamp: number;
endTimestamp: number;
size?: number;
query?: JsonObject;
cursor?: { before: LogEntriesCursor | 'last' } | { after: LogEntriesCursor | 'first' };
highlightTerm?: string;
}
export interface LogEntriesAroundParams {
startDate: number;
endDate: number;
startTimestamp: number;
endTimestamp: number;
size?: number;
center: LogEntriesCursor;
query?: JsonObject;
Expand All @@ -67,7 +67,7 @@ export class InfraLogEntriesDomain {
sourceId: string,
params: LogEntriesAroundParams
) {
const { startDate, endDate, center, query, size, highlightTerm } = params;
const { startTimestamp, endTimestamp, center, query, size, highlightTerm } = params;

/*
* For odd sizes we will round this value down for the first half, and up
Expand All @@ -80,8 +80,8 @@ export class InfraLogEntriesDomain {
const halfSize = (size || LOG_ENTRIES_PAGE_SIZE) / 2;

const entriesBefore = await this.getLogEntries(requestContext, sourceId, {
startDate,
endDate,
startTimestamp,
endTimestamp,
query,
cursor: { before: center },
size: Math.floor(halfSize),
Expand All @@ -101,8 +101,8 @@ export class InfraLogEntriesDomain {
: { time: center.time - 1, tiebreaker: 0 };

const entriesAfter = await this.getLogEntries(requestContext, sourceId, {
startDate,
endDate,
startTimestamp,
endTimestamp,
query,
cursor: { after: cursorAfter },
size: Math.ceil(halfSize),
Expand Down Expand Up @@ -368,8 +368,8 @@ export class InfraLogEntriesDomain {
public async getLogSummaryHighlightBucketsBetween(
requestContext: RequestHandlerContext,
sourceId: string,
start: number,
end: number,
startTimestamp: number,
endTimestamp: number,
bucketSize: number,
highlightQueries: string[],
filterQuery?: LogEntryQuery
Expand All @@ -396,8 +396,8 @@ export class InfraLogEntriesDomain {
const summaryBuckets = await this.adapter.getContainedLogSummaryBuckets(
requestContext,
configuration,
start,
end,
startTimestamp,
endTimestamp,
bucketSize,
query
);
Expand Down Expand Up @@ -476,8 +476,8 @@ export interface LogEntriesAdapter {
getContainedLogSummaryBuckets(
requestContext: RequestHandlerContext,
sourceConfiguration: InfraSourceConfiguration,
start: number,
end: number,
startTimestamp: number,
endTimestamp: number,
bucketSize: number,
filterQuery?: LogEntryQuery
): Promise<LogSummaryBucket[]>;
Expand Down
16 changes: 11 additions & 5 deletions x-pack/legacy/plugins/infra/server/routes/log_entries/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ export const initLogEntriesRoute = ({ framework, logEntries }: InfraBackendLibs)
fold(throwErrors(Boom.badRequest), identity)
);

const { startDate, endDate, sourceId, query, size } = payload;
const {
startTimestamp: startTimestamp,
endTimestamp: endTimestamp,
sourceId,
query,
size,
} = payload;

let entries;
if ('center' in payload) {
entries = await logEntries.getLogEntriesAround__new(requestContext, sourceId, {
startDate,
endDate,
startTimestamp,
endTimestamp,
query: parseFilterQuery(query),
center: payload.center,
size,
Expand All @@ -58,8 +64,8 @@ export const initLogEntriesRoute = ({ framework, logEntries }: InfraBackendLibs)
}

entries = await logEntries.getLogEntries(requestContext, sourceId, {
startDate,
endDate,
startTimestamp,
endTimestamp,
query: parseFilterQuery(query),
cursor,
size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBa
fold(throwErrors(Boom.badRequest), identity)
);

const { startDate, endDate, sourceId, query, size, highlightTerms } = payload;
const { startTimestamp, endTimestamp, sourceId, query, size, highlightTerms } = payload;

let entriesPerHighlightTerm;

if ('center' in payload) {
entriesPerHighlightTerm = await Promise.all(
highlightTerms.map(highlightTerm =>
logEntries.getLogEntriesAround__new(requestContext, sourceId, {
startDate,
endDate,
startTimestamp,
endTimestamp,
query: parseFilterQuery(query),
center: payload.center,
size,
Expand All @@ -66,8 +66,8 @@ export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBa
entriesPerHighlightTerm = await Promise.all(
highlightTerms.map(highlightTerm =>
logEntries.getLogEntries(requestContext, sourceId, {
startDate,
endDate,
startTimestamp,
endTimestamp,
query: parseFilterQuery(query),
cursor,
size,
Expand Down
10 changes: 5 additions & 5 deletions x-pack/legacy/plugins/infra/server/routes/log_entries/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ export const initLogEntriesSummaryRoute = ({ framework, logEntries }: InfraBacke
logEntriesSummaryRequestRT.decode(request.body),
fold(throwErrors(Boom.badRequest), identity)
);
const { sourceId, startDate, endDate, bucketSize, query } = payload;
const { sourceId, startTimestamp, endTimestamp, bucketSize, query } = payload;

const buckets = await logEntries.getLogSummaryBucketsBetween(
requestContext,
sourceId,
startDate,
endDate,
startTimestamp,
endTimestamp,
bucketSize,
parseFilterQuery(query)
);

return response.ok({
body: logEntriesSummaryResponseRT.encode({
data: {
start: startDate,
end: endDate,
start: startTimestamp,
end: endTimestamp,
buckets,
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ export const initLogEntriesSummaryHighlightsRoute = ({
logEntriesSummaryHighlightsRequestRT.decode(request.body),
fold(throwErrors(Boom.badRequest), identity)
);
const { sourceId, startDate, endDate, bucketSize, query, highlightTerms } = payload;
const {
sourceId,
startTimestamp,
endTimestamp,
bucketSize,
query,
highlightTerms,
} = payload;

const bucketsPerHighlightTerm = await logEntries.getLogSummaryHighlightBucketsBetween(
requestContext,
sourceId,
startDate,
endDate,
startTimestamp,
endTimestamp,
bucketSize,
highlightTerms,
parseFilterQuery(query)
Expand All @@ -54,8 +61,8 @@ export const initLogEntriesSummaryHighlightsRoute = ({
return response.ok({
body: logEntriesSummaryHighlightsResponseRT.encode({
data: bucketsPerHighlightTerm.map(buckets => ({
start: startDate,
end: endDate,
start: startTimestamp,
end: endTimestamp,
buckets,
})),
}),
Expand Down
Loading

0 comments on commit 6ba0eaf

Please sign in to comment.