-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [Logs UI] HTTP API for log entries (#53798) * Scaffold `log_entries/entries` route * Scaffold a log entry response * Add `after` pagination * Add `before` pagination * Process `query` parameter * Use pre-existing structure for the columns * Change type of date ranges We will move the responsibility to parse the dates to the client. The API will only take timestamps * Add `center` parameter Allows consumers of the API to get log items around a certain cursor * Change default page size * Test the defaults of the API * Add optional `size` parameter This makes easier to test the pagination. By default it returns a 200 size page. * Test the pagination * Test centering around a point * Handle `0` sizes Co-Authored-By: Zacqary Adam Xeper <Zacqary@users.noreply.github.com> * Add highlights endpoint * Refactor `processCursor` * Tweak cursor handling in the routes * Refine `LogEntry` type * Add tests for highlights endpoint * Tweak the types for the LogEntry Co-authored-by: Zacqary Adam Xeper <Zacqary@users.noreply.github.com> * Skip failing test (#54100) ES behaves differently in master and in 7.x, causing the test to fail in the latter. Co-authored-by: Zacqary Adam Xeper <Zacqary@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
1,011 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
x-pack/legacy/plugins/infra/common/http_api/log_entries/entries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { logEntriesCursorRT } from './common'; | ||
|
||
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, | ||
}), | ||
rt.partial({ | ||
query: rt.string, | ||
size: rt.number, | ||
}), | ||
]); | ||
|
||
export const logEntriesBeforeRequestRT = rt.intersection([ | ||
logEntriesBaseRequestRT, | ||
rt.type({ before: rt.union([logEntriesCursorRT, rt.literal('last')]) }), | ||
]); | ||
|
||
export const logEntriesAfterRequestRT = rt.intersection([ | ||
logEntriesBaseRequestRT, | ||
rt.type({ after: rt.union([logEntriesCursorRT, rt.literal('first')]) }), | ||
]); | ||
|
||
export const logEntriesCenteredRT = rt.intersection([ | ||
logEntriesBaseRequestRT, | ||
rt.type({ center: logEntriesCursorRT }), | ||
]); | ||
|
||
export const logEntriesRequestRT = rt.union([ | ||
logEntriesBaseRequestRT, | ||
logEntriesBeforeRequestRT, | ||
logEntriesAfterRequestRT, | ||
logEntriesCenteredRT, | ||
]); | ||
|
||
export type LogEntriesRequest = rt.TypeOf<typeof logEntriesRequestRT>; | ||
|
||
// JSON value | ||
const valueRT = rt.union([rt.string, rt.number, rt.boolean, rt.object, rt.null, rt.undefined]); | ||
|
||
export const logMessagePartRT = rt.union([ | ||
rt.type({ | ||
constant: rt.string, | ||
}), | ||
rt.type({ | ||
field: rt.string, | ||
value: valueRT, | ||
highlights: rt.array(rt.string), | ||
}), | ||
]); | ||
|
||
export const logColumnRT = rt.union([ | ||
rt.type({ columnId: rt.string, timestamp: rt.number }), | ||
rt.type({ | ||
columnId: rt.string, | ||
field: rt.string, | ||
value: rt.union([rt.string, rt.undefined]), | ||
highlights: rt.array(rt.string), | ||
}), | ||
rt.type({ | ||
columnId: rt.string, | ||
message: rt.array(logMessagePartRT), | ||
}), | ||
]); | ||
|
||
export const logEntryRT = rt.type({ | ||
id: rt.string, | ||
cursor: logEntriesCursorRT, | ||
columns: rt.array(logColumnRT), | ||
}); | ||
|
||
export type LogMessagepart = rt.TypeOf<typeof logMessagePartRT>; | ||
export type LogColumn = rt.TypeOf<typeof logColumnRT>; | ||
export type LogEntry = rt.TypeOf<typeof logEntryRT>; | ||
|
||
export const logEntriesResponseRT = rt.type({ | ||
data: rt.type({ | ||
entries: rt.array(logEntryRT), | ||
topCursor: logEntriesCursorRT, | ||
bottomCursor: logEntriesCursorRT, | ||
}), | ||
}); | ||
|
||
export type LogEntriesResponse = rt.TypeOf<typeof logEntriesResponseRT>; |
62 changes: 62 additions & 0 deletions
62
x-pack/legacy/plugins/infra/common/http_api/log_entries/highlights.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { | ||
logEntriesBaseRequestRT, | ||
logEntriesBeforeRequestRT, | ||
logEntriesAfterRequestRT, | ||
logEntriesCenteredRT, | ||
logEntryRT, | ||
} from './entries'; | ||
import { logEntriesCursorRT } from './common'; | ||
|
||
export const LOG_ENTRIES_HIGHLIGHTS_PATH = '/api/log_entries/highlights'; | ||
|
||
const highlightsRT = rt.type({ | ||
highlightTerms: rt.array(rt.string), | ||
}); | ||
|
||
export const logEntriesHighlightsBaseRequestRT = rt.intersection([ | ||
logEntriesBaseRequestRT, | ||
highlightsRT, | ||
]); | ||
|
||
export const logEntriesHighlightsBeforeRequestRT = rt.intersection([ | ||
logEntriesBeforeRequestRT, | ||
highlightsRT, | ||
]); | ||
|
||
export const logEntriesHighlightsAfterRequestRT = rt.intersection([ | ||
logEntriesAfterRequestRT, | ||
highlightsRT, | ||
]); | ||
|
||
export const logEntriesHighlightsCenteredRequestRT = rt.intersection([ | ||
logEntriesCenteredRT, | ||
highlightsRT, | ||
]); | ||
|
||
export const logEntriesHighlightsRequestRT = rt.union([ | ||
logEntriesHighlightsBaseRequestRT, | ||
logEntriesHighlightsBeforeRequestRT, | ||
logEntriesHighlightsAfterRequestRT, | ||
logEntriesHighlightsCenteredRequestRT, | ||
]); | ||
|
||
export type LogEntriesHighlightsRequest = rt.TypeOf<typeof logEntriesHighlightsRequestRT>; | ||
|
||
export const logEntriesHighlightsResponseRT = rt.type({ | ||
data: rt.array( | ||
rt.type({ | ||
topCursor: logEntriesCursorRT, | ||
bottomCursor: logEntriesCursorRT, | ||
entries: rt.array(logEntryRT), | ||
}) | ||
), | ||
}); | ||
|
||
export type LogEntriesHighlightsResponse = rt.TypeOf<typeof logEntriesHighlightsResponseRT>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.