-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs UI] HTTP endpoint for Log Summary (#51903)
* Scaffold `/logs/summary` endpoint * Use HTTP API for the log summary * Handle queries in log summary * Simplify `useLogSummary` implementation * Scaffold `/logs/summary/highlights` API * Use HTTP endpoint for log summary highlights * Tweak `highlightTerms` * Deduplicate ES queries for summary endpoints * Clean GraphQL implementation * Make tests pass * Handle server errors * Pass source to the API * Cleanup tests * Future-proof response types Wrap the existing response into a `{ data: ... }` object to allow adding metadata in the future. * Refactor tests with `@testing-library/react-hooks` * Adapt endpoint to NP * Tweak types in the test * Split API methods into separate files * Flatten highlights API * Restructure `common/http_api/logs` folder We will group relevant codecs and types into `log_entries`, splitting summary and summary_highlights as two individual concepts. * Reorganize route files * Resurrect changes in `server/lib/{adapter,domain}` Replace some of the exported types from GraphQL with io-ts codecs * Wire the route with the domain library * Remove dead types * Clean up test file * Fix merge mishap Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
254b18c
commit 0a1ffd9
Showing
24 changed files
with
517 additions
and
1,493 deletions.
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
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
37 changes: 37 additions & 0 deletions
37
x-pack/legacy/plugins/infra/common/http_api/log_entries/summary.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,37 @@ | ||
/* | ||
* 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'; | ||
|
||
export const LOG_ENTRIES_SUMMARY_PATH = '/api/log_entries/summary'; | ||
|
||
export const logEntriesSummaryRequestRT = rt.type({ | ||
sourceId: rt.string, | ||
startDate: rt.number, | ||
endDate: rt.number, | ||
bucketSize: rt.number, | ||
query: rt.union([rt.string, rt.undefined, rt.null]), | ||
}); | ||
|
||
export type LogEntriesSummaryRequest = rt.TypeOf<typeof logEntriesSummaryRequestRT>; | ||
|
||
export const logEntriesSummaryBucketRT = rt.type({ | ||
start: rt.number, | ||
end: rt.number, | ||
entriesCount: rt.number, | ||
}); | ||
|
||
export type LogEntriesSummaryBucket = rt.TypeOf<typeof logEntriesSummaryBucketRT>; | ||
|
||
export const logEntriesSummaryResponseRT = rt.type({ | ||
data: rt.type({ | ||
start: rt.number, | ||
end: rt.number, | ||
buckets: rt.array(logEntriesSummaryBucketRT), | ||
}), | ||
}); | ||
|
||
export type LogEntriesSummaryResponse = rt.TypeOf<typeof logEntriesSummaryResponseRT>; |
48 changes: 48 additions & 0 deletions
48
x-pack/legacy/plugins/infra/common/http_api/log_entries/summary_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,48 @@ | ||
/* | ||
* 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 { logEntriesSummaryRequestRT, logEntriesSummaryBucketRT } from './summary'; | ||
|
||
export const LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH = '/api/log_entries/summary_highlights'; | ||
|
||
export const logEntriesSummaryHighlightsRequestRT = rt.intersection([ | ||
logEntriesSummaryRequestRT, | ||
rt.type({ | ||
highlightTerms: rt.array(rt.string), | ||
}), | ||
]); | ||
|
||
export type LogEntriesSummaryHighlightsRequest = rt.TypeOf< | ||
typeof logEntriesSummaryHighlightsRequestRT | ||
>; | ||
|
||
export const logEntriesSummaryHighlightsBucketRT = rt.intersection([ | ||
logEntriesSummaryBucketRT, | ||
rt.type({ | ||
representativeKey: rt.type({ | ||
time: rt.number, | ||
tiebreaker: rt.number, | ||
}), | ||
}), | ||
]); | ||
|
||
export type LogEntriesSummaryHighlightsBucket = rt.TypeOf< | ||
typeof logEntriesSummaryHighlightsBucketRT | ||
>; | ||
|
||
export const logEntriesSummaryHighlightsResponseRT = rt.type({ | ||
data: rt.array( | ||
rt.type({ | ||
start: rt.number, | ||
end: rt.number, | ||
buckets: rt.array(logEntriesSummaryHighlightsBucketRT), | ||
}) | ||
), | ||
}); | ||
export type LogEntriesSummaryHighlightsResponse = rt.TypeOf< | ||
typeof logEntriesSummaryHighlightsResponseRT | ||
>; |
33 changes: 33 additions & 0 deletions
33
...y/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_summary_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,33 @@ | ||
/* | ||
* 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 { fold } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import { identity } from 'fp-ts/lib/function'; | ||
import { kfetch } from 'ui/kfetch'; | ||
|
||
import { throwErrors, createPlainError } from '../../../../../common/runtime_types'; | ||
|
||
import { | ||
LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH, | ||
LogEntriesSummaryHighlightsRequest, | ||
logEntriesSummaryHighlightsRequestRT, | ||
logEntriesSummaryHighlightsResponseRT, | ||
} from '../../../../../common/http_api'; | ||
|
||
export const fetchLogSummaryHighlights = async ( | ||
requestArgs: LogEntriesSummaryHighlightsRequest | ||
) => { | ||
const response = await kfetch({ | ||
method: 'POST', | ||
pathname: LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH, | ||
body: JSON.stringify(logEntriesSummaryHighlightsRequestRT.encode(requestArgs)), | ||
}); | ||
|
||
return pipe( | ||
logEntriesSummaryHighlightsResponseRT.decode(response), | ||
fold(throwErrors(createPlainError), identity) | ||
); | ||
}; |
44 changes: 0 additions & 44 deletions
44
...y/plugins/infra/public/containers/logs/log_highlights/log_summary_highlights.gql_query.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.