- 
        Couldn't load subscription status. 
- Fork 130
feat: add pb usage metrics, server state #2503
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -149,6 +149,18 @@ pub struct Server { | |
| pub lan_ip: Option<IpAddr>, | ||
| pub wan_ip: Option<IpAddr>, | ||
| pub cloud_destroy_ts: Option<i64>, | ||
| pub state: ServerState, | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: The Server struct doesn't derive Serialize/Deserialize traits but contains a serializable state field. This may cause issues if Server needs to be serialized | ||
| } | ||
|  | ||
| #[derive(Serialize, Deserialize, Hash, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, FromRepr)] | ||
| pub enum ServerState { | ||
| Provisioning = 0, | ||
| Installing = 1, | ||
| Running = 2, | ||
| Tainted = 3, | ||
| Draining = 4, | ||
| TaintedDraining = 5, | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: TaintedDraining combines two states - consider if this should be a separate flag instead of a combined state for better state management | ||
| Destroyed = 6, | ||
| } | ||
|  | ||
| #[derive(Debug, Default, Clone)] | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -246,6 +246,10 @@ impl ActorKey { | |
| pub fn subspace(client_id: Uuid) -> ActorSubspaceKey { | ||
| ActorSubspaceKey::new(client_id) | ||
| } | ||
|  | ||
| pub fn entire_subspace() -> ActorSubspaceKey { | ||
| ActorSubspaceKey::entire() | ||
| } | ||
| } | ||
|  | ||
| impl FormalKey for ActorKey { | ||
|  | @@ -290,12 +294,16 @@ impl<'de> TupleUnpack<'de> for ActorKey { | |
| } | ||
|  | ||
| pub struct ActorSubspaceKey { | ||
| client_id: Uuid, | ||
| client_id: Option<Uuid>, | ||
| } | ||
| 
      Comment on lines
    
      296
     to 
      298
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Missing Debug derive for ActorSubspaceKey. This could make debugging more difficult if issues arise. | ||
|  | ||
| impl ActorSubspaceKey { | ||
| fn new(client_id: Uuid) -> Self { | ||
| ActorSubspaceKey { client_id } | ||
| ActorSubspaceKey { client_id: Some(client_id) } | ||
| } | ||
|  | ||
| fn entire() -> Self { | ||
| ActorSubspaceKey { client_id: None } | ||
| } | ||
| } | ||
|  | ||
|  | @@ -305,8 +313,16 @@ impl TuplePack for ActorSubspaceKey { | |
| w: &mut W, | ||
| tuple_depth: TupleDepth, | ||
| ) -> std::io::Result<VersionstampOffset> { | ||
| let t = (CLIENT, ACTOR, self.client_id); | ||
| t.pack(w, tuple_depth) | ||
| let mut offset = VersionstampOffset::None { size: 0 }; | ||
|  | ||
| let t = (CLIENT, ACTOR); | ||
| offset += t.pack(w, tuple_depth)?; | ||
|  | ||
| if let Some(client_id) = &self.client_id { | ||
| offset += client_id.pack(w, tuple_depth)?; | ||
| } | ||
|  | ||
| Ok(offset) | ||
| } | ||
| } | ||
|  | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -37,4 +37,18 @@ lazy_static::lazy_static! { | |
| BUCKETS.to_vec(), | ||
| *REGISTRY, | ||
| ).unwrap(); | ||
|  | ||
| pub static ref ENV_CPU_USAGE: IntGaugeVec = register_int_gauge_vec_with_registry!( | ||
| "pegboard_env_cpu_usage", | ||
| "Total percent of CPU (per core) used by an environment.", | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Description could be more precise - 'Total percent of CPU' is ambiguous. Consider clarifying if this is average, peak, or instantaneous CPU usage. | ||
| &["env_id", "flavor"], | ||
| *REGISTRY, | ||
| ).unwrap(); | ||
|  | ||
| pub static ref ENV_MEMORY_USAGE: IntGaugeVec = register_int_gauge_vec_with_registry!( | ||
| "pegboard_env_memory_usage", | ||
| "Total MiB of memory used by an environment.", | ||
| &["env_id", "flavor"], | ||
| *REGISTRY, | ||
| ).unwrap(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,2 +1 @@ | ||
| pub mod update_allocation_idx; | ||
| pub mod usage_get; | 
This file was deleted.
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.
style: State values should be defined as constants in the codebase to avoid magic numbers and ensure consistency across queries