Skip to content

Conversation

MasterPtato
Copy link
Contributor

Changes

@MasterPtato MasterPtato requested a review from NathanFlurry June 16, 2025 21:57
This was referenced Jun 16, 2025
Copy link
Contributor Author

MasterPtato commented Jun 16, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Implements caching layer for server list queries across multiple services to improve performance and reduce database load.

  • Added new server_discovery module in packages/core/services/cluster/src/ops/datacenter/server_discovery.rs with 5-second TTL cache
  • Migrated from custom types to standard rivet_api::models types in packages/common/service-discovery/src/lib.rs
  • Modified packages/edge/infra/guard/server/src/routing/api.rs to use service discovery instead of direct server queries
  • Re-enabled prewarm request error handling in packages/core/api/actor/src/route/builds.rs for build completion safety
  • Added exclude_installing flag across server list operations for better control of server lifecycle management

18 files reviewed, 6 comments
Edit PR Review Bot Settings | Greptile

"worker" => Ok(PoolType::Worker),
"nats" => Ok(PoolType::Nats),
"guard" => Ok(PoolType::Guard),
_ => bail!("Invalid PoolType string: {}", s),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Include variant name in error message for better debugging: Invalid PoolType string '{}' (expected: job, gg, ats, etc)

Comment on lines 21 to 27
.op(crate::ops::server::list::Input {
filter: input.filter.clone(),
include_destroyed: false,
exclude_installing: false,
exclude_draining: false,
exclude_no_vlan: false,
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: All filter flags are set to false, but there's no comment explaining why we want to include all server states. Consider adding a comment explaining this design decision.

Comment on lines 59 to 68
let servers_res = ctx
.op(cluster::ops::server::list::Input {
filter: cluster::types::Filter {
datacenter_ids: Some(vec![datacenter_id]),
pool_types: (!query.pools.is_empty())
.then(|| query.pools.into_iter().map(ApiInto::api_into).collect()),
..Default::default()
},
include_destroyed: false,
exclude_draining: true,
exclude_no_vlan: true,
.op(cluster::ops::datacenter::server_discovery::Input {
datacenter_id,
pool_types: query
.pools
.into_iter()
.map(ApiInto::api_into)
.collect(),
})
.await?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Replacing server::list with server_discovery removes several critical filters (exclude_draining, exclude_no_vlan). Verify these are handled in server_discovery operation or document why they're no longer needed

Comment on lines 71 to 75
servers: servers_res
.servers
.into_iter()
// Filter out installing servers
.filter(|server| server.install_complete_ts.is_some())
.map(ApiInto::api_into)
.collect(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Removal of .filter(|server| server.install_complete_ts.is_some()) could expose incomplete/installing servers to clients. Verify this is handled in server_discovery or restore the filter

Comment on lines 73 to 74
let client = Client::new();
Ok(self.fetch_inner(&client).await?.servers)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Creating new Client for each fetch is inefficient - consider reusing the client from fetch_inner's parameter

Comment on lines +21 to +29
let cache_keys = if input.pool_types.is_empty() {
vec![(input.datacenter_id, "all".to_string())]
} else {
input
.pool_types
.iter()
.map(|pool| (input.datacenter_id, pool.to_string()))
.collect()
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a const for 'all' string to avoid magic strings

@MasterPtato MasterPtato changed the base branch from 06-16-fix_toolchain_attach_tags_to_function_workers to graphite-base/2620 June 18, 2025 23:46
@MasterPtato MasterPtato changed the base branch from graphite-base/2620 to 06-16-fix_toolchain_attach_tags_to_function_workers June 18, 2025 23:48
@MasterPtato MasterPtato changed the base branch from 06-16-fix_toolchain_attach_tags_to_function_workers to graphite-base/2620 June 20, 2025 00:58
@MasterPtato MasterPtato force-pushed the 06-16-fix_add_cache_to_server_list_queries branch from 5d622b5 to 0e85267 Compare June 20, 2025 19:09
@MasterPtato MasterPtato changed the base branch from graphite-base/2620 to 06-16-fix_toolchain_attach_tags_to_function_workers June 20, 2025 19:10
@NathanFlurry NathanFlurry changed the base branch from 06-16-fix_toolchain_attach_tags_to_function_workers to graphite-base/2620 June 20, 2025 19:18
Copy link
Contributor

graphite-app bot commented Jun 20, 2025

Merge activity

  • Jun 20, 7:19 PM UTC: MasterPtato added this pull request to the Graphite merge queue.
  • Jun 20, 7:21 PM UTC: CI is running for this pull request on a draft pull request (#2630) due to your merge queue CI optimization settings.
  • Jun 20, 7:22 PM UTC: Merged by the Graphite merge queue via draft PR: #2630.

graphite-app bot pushed a commit that referenced this pull request Jun 20, 2025
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
@graphite-app graphite-app bot closed this Jun 20, 2025
@graphite-app graphite-app bot deleted the 06-16-fix_add_cache_to_server_list_queries branch June 20, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant