mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 19:59:46 -05:00
add build / repo / procedure state stuff to summary
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
use std::{collections::{HashMap, HashSet}, str::FromStr, sync::OnceLock};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
str::FromStr,
|
||||
sync::OnceLock,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use async_timing_util::unix_timestamp_ms;
|
||||
@@ -7,7 +11,7 @@ use futures::TryStreamExt;
|
||||
use monitor_client::{
|
||||
api::read::*,
|
||||
entities::{
|
||||
build::{Build, BuildActionState, BuildListItem},
|
||||
build::{Build, BuildActionState, BuildListItem, BuildState},
|
||||
permission::PermissionLevel,
|
||||
update::{ResourceTargetVariant, UpdateStatus},
|
||||
user::User,
|
||||
@@ -27,7 +31,7 @@ use crate::{
|
||||
config::core_config,
|
||||
helpers::query::get_resource_ids_for_non_admin,
|
||||
resource,
|
||||
state::{action_states, db_client, State},
|
||||
state::{action_states, build_state_cache, db_client, State},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
@@ -103,15 +107,38 @@ impl Resolve<GetBuildsSummary, User> for State {
|
||||
};
|
||||
Some(query)
|
||||
};
|
||||
let total = db_client()
|
||||
|
||||
let builds = find_collect(&db_client().await.builds, query, None)
|
||||
.await
|
||||
.builds
|
||||
.count_documents(query, None)
|
||||
.await
|
||||
.context("failed to count all build documents")?;
|
||||
let res = GetBuildsSummaryResponse {
|
||||
total: total as u32,
|
||||
};
|
||||
.context("failed to find all build documents")?;
|
||||
let mut res = GetBuildsSummaryResponse::default();
|
||||
|
||||
let cache = build_state_cache();
|
||||
let action_states = action_states();
|
||||
|
||||
for build in builds {
|
||||
res.total += 1;
|
||||
|
||||
match (
|
||||
cache.get(&build.id).await.unwrap_or_default(),
|
||||
action_states
|
||||
.build
|
||||
.get(&build.id)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.get()?,
|
||||
) {
|
||||
(_, action_states) if action_states.building => {
|
||||
res.building += 1;
|
||||
}
|
||||
(BuildState::Ok, _) => res.ok += 1,
|
||||
(BuildState::Failed, _) => res.failed += 1,
|
||||
(BuildState::Unknown, _) => res.unknown += 1,
|
||||
// will never come off the cache in the building state, since that comes from action states
|
||||
(BuildState::Building, _) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
@@ -267,10 +294,9 @@ impl Resolve<ListCommonBuildExtraArgs, User> for State {
|
||||
ListCommonBuildExtraArgs { query }: ListCommonBuildExtraArgs,
|
||||
user: User,
|
||||
) -> anyhow::Result<ListCommonBuildExtraArgsResponse> {
|
||||
let builds =
|
||||
resource::list_full_for_user::<Build>(query, &user)
|
||||
.await
|
||||
.context("failed to get resources matching query")?;
|
||||
let builds = resource::list_full_for_user::<Build>(query, &user)
|
||||
.await
|
||||
.context("failed to get resources matching query")?;
|
||||
|
||||
// first collect with guaranteed uniqueness
|
||||
let mut res = HashSet::<String>::new();
|
||||
@@ -283,4 +309,4 @@ impl Resolve<ListCommonBuildExtraArgs, User> for State {
|
||||
|
||||
Ok(res.into_iter().collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ impl Resolve<GetDeploymentsSummary, User> for State {
|
||||
let deployments =
|
||||
find_collect(&db_client().await.deployments, query, None)
|
||||
.await
|
||||
.context("failed to count all deployment documents")?;
|
||||
.context("failed to find all deployment documents")?;
|
||||
let mut res = GetDeploymentsSummaryResponse::default();
|
||||
let status_cache = deployment_status_cache();
|
||||
for deployment in deployments {
|
||||
|
||||
@@ -10,17 +10,22 @@ use monitor_client::{
|
||||
ListProcedures, ListProceduresResponse,
|
||||
},
|
||||
entities::{
|
||||
permission::PermissionLevel, procedure::Procedure,
|
||||
update::ResourceTargetVariant, user::User,
|
||||
permission::PermissionLevel,
|
||||
procedure::{Procedure, ProcedureState},
|
||||
update::ResourceTargetVariant,
|
||||
user::User,
|
||||
},
|
||||
};
|
||||
use mungos::mongodb::bson::{doc, oid::ObjectId};
|
||||
use mungos::{
|
||||
find::find_collect,
|
||||
mongodb::bson::{doc, oid::ObjectId},
|
||||
};
|
||||
use resolver_api::Resolve;
|
||||
|
||||
use crate::{
|
||||
helpers::query::get_resource_ids_for_non_admin,
|
||||
resource,
|
||||
state::{action_states, db_client, State},
|
||||
state::{action_states, db_client, procedure_state_cache, State},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
@@ -73,15 +78,40 @@ impl Resolve<GetProceduresSummary, User> for State {
|
||||
};
|
||||
Some(query)
|
||||
};
|
||||
let total = db_client()
|
||||
.await
|
||||
.procedures
|
||||
.count_documents(query, None)
|
||||
.await
|
||||
.context("failed to count all procedure documents")?;
|
||||
let res = GetProceduresSummaryResponse {
|
||||
total: total as u32,
|
||||
};
|
||||
|
||||
let procedures =
|
||||
find_collect(&db_client().await.procedures, query, None)
|
||||
.await
|
||||
.context("failed to find all procedure documents")?;
|
||||
|
||||
let mut res = GetProceduresSummaryResponse::default();
|
||||
|
||||
let cache = procedure_state_cache();
|
||||
let action_states = action_states();
|
||||
|
||||
for procedure in procedures {
|
||||
res.total += 1;
|
||||
|
||||
match (
|
||||
cache.get(&procedure.id).await.unwrap_or_default(),
|
||||
action_states
|
||||
.procedure
|
||||
.get(&procedure.id)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.get()?,
|
||||
) {
|
||||
(_, action_states) if action_states.running => {
|
||||
res.running += 1;
|
||||
}
|
||||
(ProcedureState::Ok, _) => res.ok += 1,
|
||||
(ProcedureState::Failed, _) => res.failed += 1,
|
||||
(ProcedureState::Unknown, _) => res.unknown += 1,
|
||||
// will never come off the cache in the running state, since that comes from action states
|
||||
(ProcedureState::Running, _) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,21 @@ use monitor_client::{
|
||||
api::read::*,
|
||||
entities::{
|
||||
permission::PermissionLevel,
|
||||
repo::{Repo, RepoActionState, RepoListItem},
|
||||
repo::{Repo, RepoActionState, RepoListItem, RepoState},
|
||||
update::ResourceTargetVariant,
|
||||
user::User,
|
||||
},
|
||||
};
|
||||
use mungos::mongodb::bson::{doc, oid::ObjectId};
|
||||
use mungos::{
|
||||
find::find_collect,
|
||||
mongodb::bson::{doc, oid::ObjectId},
|
||||
};
|
||||
use resolver_api::Resolve;
|
||||
|
||||
use crate::{
|
||||
helpers::query::get_resource_ids_for_non_admin,
|
||||
resource,
|
||||
state::{action_states, db_client, State},
|
||||
state::{action_states, db_client, repo_state_cache, State},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
@@ -93,15 +96,43 @@ impl Resolve<GetReposSummary, User> for State {
|
||||
};
|
||||
Some(query)
|
||||
};
|
||||
let total = db_client()
|
||||
|
||||
let repos = find_collect(&db_client().await.repos, query, None)
|
||||
.await
|
||||
.repos
|
||||
.count_documents(query, None)
|
||||
.await
|
||||
.context("failed to count all build documents")?;
|
||||
let res = GetReposSummaryResponse {
|
||||
total: total as u32,
|
||||
};
|
||||
.context("failed to find all repo documents")?;
|
||||
let mut res = GetReposSummaryResponse::default();
|
||||
|
||||
let cache = repo_state_cache();
|
||||
let action_states = action_states();
|
||||
|
||||
for repo in repos {
|
||||
res.total += 1;
|
||||
|
||||
match (
|
||||
cache.get(&repo.id).await.unwrap_or_default(),
|
||||
action_states
|
||||
.repo
|
||||
.get(&repo.id)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.get()?,
|
||||
) {
|
||||
(_, action_states) if action_states.cloning => {
|
||||
res.cloning += 1;
|
||||
}
|
||||
(_, action_states) if action_states.pulling => {
|
||||
res.pulling += 1;
|
||||
}
|
||||
(RepoState::Ok, _) => res.ok += 1,
|
||||
(RepoState::Failed, _) => res.failed += 1,
|
||||
(RepoState::Unknown, _) => res.unknown += 1,
|
||||
// will never come off the cache in the building state, since that comes from action states
|
||||
(RepoState::Cloning, _) | (RepoState::Pulling, _) => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,10 +80,18 @@ pub struct GetBuildsSummary {}
|
||||
|
||||
/// Response for [GetBuildsSummary].
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
|
||||
pub struct GetBuildsSummaryResponse {
|
||||
/// The total number of builds in monitor.
|
||||
pub total: u32,
|
||||
/// The number of builds with Ok state.
|
||||
pub ok: u32,
|
||||
/// The number of builds with Failed state.
|
||||
pub failed: u32,
|
||||
/// The number of builds currently building.
|
||||
pub building: u32,
|
||||
/// The number of builds with unknown state.
|
||||
pub unknown: u32,
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -77,9 +77,18 @@ pub struct GetProceduresSummary {}
|
||||
|
||||
/// Response for [GetProceduresSummary].
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct GetProceduresSummaryResponse {
|
||||
/// The total number of procedures.
|
||||
pub total: u32,
|
||||
/// The number of procedures with Ok state.
|
||||
pub ok: u32,
|
||||
/// The number of procedures currently running.
|
||||
pub running: u32,
|
||||
/// The number of procedures with failed state.
|
||||
pub failed: u32,
|
||||
/// The number of procedures with unknown state.
|
||||
pub unknown: u32,
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -77,7 +77,18 @@ pub struct GetReposSummary {}
|
||||
|
||||
/// Response for [GetReposSummary]
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct GetReposSummaryResponse {
|
||||
/// The total number of repos
|
||||
pub total: u32,
|
||||
/// The number of repos with Ok state.
|
||||
pub ok: u32,
|
||||
/// The number of repos currently cloning.
|
||||
pub cloning: u32,
|
||||
/// The number of repos currently pulling.
|
||||
pub pulling: u32,
|
||||
/// The number of repos with failed state.
|
||||
pub failed: u32,
|
||||
/// The number of repos with unknown state.
|
||||
pub unknown: u32,
|
||||
}
|
||||
|
||||
@@ -1714,6 +1714,14 @@ export interface GetBuildsSummary {
|
||||
export interface GetBuildsSummaryResponse {
|
||||
/** The total number of builds in monitor. */
|
||||
total: number;
|
||||
/** The number of builds with Ok state. */
|
||||
ok: number;
|
||||
/** The number of builds with Failed state. */
|
||||
failed: number;
|
||||
/** The number of builds currently building. */
|
||||
building: number;
|
||||
/** The number of builds with unknown state. */
|
||||
unknown: number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2025,7 +2033,16 @@ export interface GetProceduresSummary {
|
||||
|
||||
/** Response for [GetProceduresSummary]. */
|
||||
export interface GetProceduresSummaryResponse {
|
||||
/** The total number of procedures. */
|
||||
total: number;
|
||||
/** The number of procedures with Ok state. */
|
||||
ok: number;
|
||||
/** The number of procedures currently running. */
|
||||
running: number;
|
||||
/** The number of procedures with failed state. */
|
||||
failed: number;
|
||||
/** The number of procedures with unknown state. */
|
||||
unknown: number;
|
||||
}
|
||||
|
||||
/** Get a specific repo. Response: [Repo]. */
|
||||
@@ -2055,7 +2072,18 @@ export interface GetReposSummary {
|
||||
|
||||
/** Response for [GetReposSummary] */
|
||||
export interface GetReposSummaryResponse {
|
||||
/** The total number of repos */
|
||||
total: number;
|
||||
/** The number of repos with Ok state. */
|
||||
ok: number;
|
||||
/** The number of repos currently cloning. */
|
||||
cloning: number;
|
||||
/** The number of repos currently pulling. */
|
||||
pulling: number;
|
||||
/** The number of repos with failed state. */
|
||||
failed: number;
|
||||
/** The number of repos with unknown state. */
|
||||
unknown: number;
|
||||
}
|
||||
|
||||
/** Find resources matching a common query. Response: [FindResourcesResponse]. */
|
||||
|
||||
Reference in New Issue
Block a user