Skip to content

Commit

Permalink
[Fleet] Use unmapped_type: long when sorting datasets that don't in…
Browse files Browse the repository at this point in the history
…clude `event.ingested` (#136114)

* Add ignore_unmapped: true to fix data streams API in e2e tests

* Fix sort setup

* Skip failing cypress suite for now

* Filter out non-integration data streams from Fleet data streams API

* Try using timestamp instead of event.ingested

* Use unmapped type setting

* Provide explicit missing value for event.ingested

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
kpollich and kibanamachine authored Jul 14, 2022
1 parent 33b743c commit 8a5bf42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/cypress/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"baseUrl": "http://localhost:5620",
"defaultCommandTimeout": 60000,
"requestTimeout": 60000,
"responseTimetout": 60000,
"responseTimeout": 60000,
"execTimeout": 120000,
"pageLoadTimeout": 120000,
"nodeVersion": "system",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,22 @@ export async function getDataStreamsQueryMetadata({
esClient.search({
size: 1,
index: dataStreamName,
sort: 'event.ingested:desc',
_source: false,
fields: ['event.ingested'],
// We need to use `body` to control the `sort` value here, because otherwise
// it's just appended as a query string to the search operation and we can't
// set `unmapped_type` for cases where `event.ingested` is not defiend, e.g.
// in custom logs or custom HTTPJSON integrations
body: {
sort: {
'event.ingested': {
order: 'desc',
// Necessary because of https://github.com/elastic/elasticsearch/issues/81960
missing: 0,
unmapped_type: 'long',
},
},
},
}),
esClient.termsEnum({
index: dataStreamName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const getListHandler: RequestHandler = async (context, request, response)
});

// Return final data streams objects sorted by last activity, descending
// After filtering out data streams that are missing dataset/namespace/type fields
// After filtering out data streams that are missing dataset/namespace/type/package fields
body.data_streams = (await Promise.all(dataStreamPromises))
.filter(({ dataset, namespace, type }) => dataset && namespace && type)
.sort((a, b) => b.last_activity_ms - a.last_activity_ms);
Expand Down

0 comments on commit 8a5bf42

Please sign in to comment.