-
Notifications
You must be signed in to change notification settings - Fork 17
feat(analyzer): entity list endpoint #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e2574eb
feat(query-engine): entity-list endpoint
johanpel be65a2b
Add some more commentary
johanpel de166c9
refactor(query-engine): relocate scope resolution and tidy entities h…
johanpel 6bc5a4b
fmt
johanpel 0c88f36
Merge remote-tracking branch 'upstream/main' into pr-entity-list
johanpel e170657
Merge remote-tracking branch 'upstream/main' into pr-entity-list
johanpel fdbc1c3
fix(query-engine): address coderabbit comments on entity list
johanpel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,6 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Requests and responses for entity-list queries. | ||
| pub mod request; | ||
| pub mod response; |
This file contains hidden or 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,137 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use std::collections::HashSet; | ||
|
|
||
| use quent_analyzer::{AnalyzerResult, Model, resource::tree::ResourceTreeNode}; | ||
| use quent_time::{TimeError, TimeSec, TimeUnixNanoSec, span::SpanUnixNanoSec, to_nanosecs}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use ts_rs::TS; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::paginate::PageParams; | ||
|
|
||
| /// Restricts returned entities to appear in a certain scope. | ||
| #[derive(TS, Debug, Clone, Serialize, Deserialize)] | ||
| pub enum EntityScope { | ||
| /// Only return entities that use this resource. | ||
| Resource { resource_id: Uuid }, | ||
| /// Only return entities that use any resource within this group. | ||
| ResourceGroup { | ||
| resource_group_id: Uuid, | ||
| resource_type_name: String, | ||
| }, | ||
| } | ||
|
|
||
| impl EntityScope { | ||
| /// Resolve the scope to the resource IDs it covers: the single resource, or | ||
| /// the leaf resources of the group that have the requested type. | ||
| pub fn resolve(&self, model: &impl Model) -> AnalyzerResult<HashSet<Uuid>> { | ||
| match self { | ||
| EntityScope::Resource { resource_id } => { | ||
| model.resource(*resource_id)?; | ||
| Ok([*resource_id].into_iter().collect()) | ||
| } | ||
| EntityScope::ResourceGroup { | ||
| resource_group_id, | ||
| resource_type_name, | ||
| } => { | ||
| let tree = ResourceTreeNode::try_new(model, *resource_group_id)?; | ||
| Ok(tree | ||
| .iter_leaf_ids() | ||
| .filter(|&id| { | ||
| model | ||
| .resource(id) | ||
| .is_ok_and(|r| r.type_name() == resource_type_name) | ||
| }) | ||
| .collect()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A time window, resolved against an epoch supplied at conversion. | ||
| #[derive(TS, Debug, Clone, Copy, Serialize, Deserialize)] | ||
| pub struct TimeWindow { | ||
| /// The start time of the window in seconds. | ||
| pub start: TimeSec, | ||
| /// The end time of the window in seconds. | ||
| pub end: TimeSec, | ||
| } | ||
|
|
||
| impl TimeWindow { | ||
| /// Resolve to an absolute span by offsetting from `epoch`. | ||
| pub fn try_into_span(self, epoch: TimeUnixNanoSec) -> Result<SpanUnixNanoSec, TimeError> { | ||
| SpanUnixNanoSec::try_new( | ||
| epoch + to_nanosecs(self.start), | ||
| epoch + to_nanosecs(self.end), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /// Entity filters. | ||
| /// | ||
| /// Every field that is set must match, `None` fields do not filter. | ||
| #[derive(TS, Debug, Clone, Default, Serialize, Deserialize)] | ||
| pub struct EntityListFilter { | ||
| /// Restrict resulting entities to be in this scope. | ||
| pub scope: Option<EntityScope>, | ||
| /// Restrict resulting entities to be of this type. | ||
| pub entity_type_name: Option<String>, | ||
| /// Keep only entities with resource usages longer than this threshold. | ||
| /// | ||
| /// N.B. only Fsm-type entities can have usages. | ||
| pub min_usage_s: Option<TimeSec>, | ||
| } | ||
|
|
||
| /// The key entities are sorted by. | ||
| #[derive(TS, Debug, Clone, Copy, Serialize, Deserialize)] | ||
| pub enum EntitySortKey { | ||
| /// The longest single resource-usage span within the window. | ||
| UsageDuration, | ||
| } | ||
|
|
||
| /// The direction to sort in. | ||
| #[derive(TS, Debug, Clone, Copy, Serialize, Deserialize)] | ||
| pub enum SortDir { | ||
| /// Sort in ascending order. | ||
| Asc, | ||
| /// Sort in descending order. | ||
| Desc, | ||
| } | ||
|
|
||
| /// Sorting parameters. | ||
| #[derive(TS, Debug, Clone, Copy, Serialize, Deserialize)] | ||
| pub struct Sort { | ||
| /// The key to sort on. | ||
| pub key: EntitySortKey, | ||
| /// The direction to sort in. | ||
| pub dir: SortDir, | ||
| } | ||
|
|
||
| /// A single entity-list query. | ||
| #[derive(TS, Debug, Clone, Serialize, Deserialize)] | ||
| pub struct EntityListEntry<EntryParams> { | ||
| /// The window of time entities must fall in. | ||
| pub window: TimeWindow, | ||
| /// Filter parameters. | ||
| pub filter: EntityListFilter, | ||
| /// Sort parameters. | ||
| pub sort: Sort, | ||
| /// Pagination parameters. | ||
| /// | ||
| /// When this is not set, return the full list. Depending on the dataset | ||
| /// size and other parameters, this may result in a large volume of data and | ||
| /// should be used with care. | ||
| pub page: Option<PageParams>, | ||
| /// Per-query application-specific parameters. | ||
| pub application: EntryParams, | ||
| } | ||
|
|
||
| /// Parameters for listing entities. | ||
| #[derive(TS, Debug, Clone, Serialize, Deserialize)] | ||
| pub struct EntityListRequest<GlobalParams, EntryParams> { | ||
| pub entry: EntityListEntry<EntryParams>, | ||
| /// Global application parameters shared by the query. | ||
| pub app_params: GlobalParams, | ||
| } | ||
This file contains hidden or 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,17 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use serde::Serialize; | ||
| use ts_rs::TS; | ||
|
|
||
| use crate::FiniteStateMachine; | ||
|
|
||
| /// A ranked, paged list of entities. | ||
| #[derive(TS, Debug, Clone, Serialize)] | ||
| pub struct EntityListResponse { | ||
| // TODO(johanpel): generalize to other entity types, but only FSMs are | ||
| // represented today. | ||
| pub items: Vec<FiniteStateMachine>, | ||
| /// The count of entities matching the filter before paging. | ||
| pub total: u32, | ||
| } |
This file contains hidden or 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 hidden or 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,16 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Pagination parameters shared across list endpoints. | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
| use ts_rs::TS; | ||
|
|
||
| /// Parameters for paginated lists. | ||
| #[derive(TS, Debug, Clone, Copy, Serialize, Deserialize)] | ||
| pub struct PageParams { | ||
| /// The maximum size of a page. | ||
| pub max: u32, | ||
| /// The zero-based index of the requested page. | ||
| pub page: u32, | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that only leaf resources should have valid usages ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this limitation is removed as a part of #191.
The resource concept will be unrelated to hierarchical trees of entities, also see:
https://github.com/rapidsai/quent/blob/main/crates/ref-tree/src/lib.rs
https://github.com/rapidsai/quent/blob/main/crates/resource/src/lib.rs