-
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.
Stacked on #204004 <img width="1275" alt="Screenshot 2024-12-12 at 17 19 58" src="https://github.com/user-attachments/assets/2ad14305-15c0-4522-8e70-5691c50e381b" /> Adds some bits to the stream overview page: * Number of docs for the current time range (let's stop here and don't build more of Kibana) * List of child streams for wired streams * Quick links tab (currently empty) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
2a7a53a
commit 58d1522
Showing
8 changed files
with
604 additions
and
97 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
86 changes: 86 additions & 0 deletions
86
x-pack/solutions/observability/plugins/streams/server/routes/streams/details.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,86 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { z } from '@kbn/zod'; | ||
import { notFound, internal } from '@hapi/boom'; | ||
import { SearchTotalHits } from '@elastic/elasticsearch/lib/api/types'; | ||
import { createServerRoute } from '../create_server_route'; | ||
import { DefinitionNotFound } from '../../lib/streams/errors'; | ||
import { readStream } from '../../lib/streams/stream_crud'; | ||
|
||
export interface StreamDetailsResponse { | ||
details: { | ||
count: number; | ||
}; | ||
} | ||
|
||
export const streamDetailRoute = createServerRoute({ | ||
endpoint: 'GET /api/streams/{id}/_details', | ||
options: { | ||
access: 'internal', | ||
}, | ||
security: { | ||
authz: { | ||
enabled: false, | ||
reason: | ||
'This API delegates security to the currently logged in user and their Elasticsearch permissions.', | ||
}, | ||
}, | ||
params: z.object({ | ||
path: z.object({ id: z.string() }), | ||
query: z.object({ | ||
start: z.string(), | ||
end: z.string(), | ||
}), | ||
}), | ||
handler: async ({ | ||
response, | ||
params, | ||
request, | ||
logger, | ||
getScopedClients, | ||
}): Promise<StreamDetailsResponse> => { | ||
try { | ||
const { scopedClusterClient } = await getScopedClients({ request }); | ||
const streamEntity = await readStream({ | ||
scopedClusterClient, | ||
id: params.path.id, | ||
}); | ||
|
||
// check doc count | ||
const docCountResponse = await scopedClusterClient.asCurrentUser.search({ | ||
index: streamEntity.name, | ||
body: { | ||
track_total_hits: true, | ||
query: { | ||
range: { | ||
'@timestamp': { | ||
gte: params.query.start, | ||
lte: params.query.end, | ||
}, | ||
}, | ||
}, | ||
size: 0, | ||
}, | ||
}); | ||
|
||
const count = (docCountResponse.hits.total as SearchTotalHits).value; | ||
|
||
return { | ||
details: { | ||
count, | ||
}, | ||
}; | ||
} catch (e) { | ||
if (e instanceof DefinitionNotFound) { | ||
throw notFound(e); | ||
} | ||
|
||
throw internal(e); | ||
} | ||
}, | ||
}); |
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.