Skip to content

Commit b77a826

Browse files
committed
fix: add create ts to server list
1 parent afbbfe3 commit b77a826

File tree

10 files changed

+65
-13
lines changed

10 files changed

+65
-13
lines changed

docker/dev-full/grafana/dashboards/rivet-sqlite.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@
430430
},
431431
"id": 17,
432432
"interval": "15s",
433-
"maxDataPoints": 50,
434433
"options": {
435434
"legend": {
436435
"calcs": [
@@ -531,7 +530,6 @@
531530
},
532531
"id": 18,
533532
"interval": "15s",
534-
"maxDataPoints": 50,
535533
"options": {
536534
"legend": {
537535
"calcs": [],
@@ -630,7 +628,6 @@
630628
},
631629
"id": 19,
632630
"interval": "15s",
633-
"maxDataPoints": 50,
634631
"options": {
635632
"legend": {
636633
"calcs": [],
@@ -743,7 +740,6 @@
743740
},
744741
"id": 23,
745742
"interval": "15s",
746-
"maxDataPoints": 50,
747743
"options": {
748744
"legend": {
749745
"calcs": [
@@ -845,7 +841,6 @@
845841
},
846842
"id": 24,
847843
"interval": "15s",
848-
"maxDataPoints": 50,
849844
"options": {
850845
"legend": {
851846
"calcs": [

docker/dev-full/grafana/dashboards/traces.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
"y": 1
108108
},
109109
"id": 2,
110-
"maxDataPoints": 50,
111110
"options": {
112111
"legend": {
113112
"calcs": [],
@@ -252,7 +251,6 @@
252251
"y": 10
253252
},
254253
"id": 7,
255-
"maxDataPoints": 50,
256254
"options": {
257255
"legend": {
258256
"calcs": [],
@@ -396,7 +394,6 @@
396394
"y": 19
397395
},
398396
"id": 8,
399-
"maxDataPoints": 50,
400397
"options": {
401398
"legend": {
402399
"calcs": [],

packages/common/util/core/src/format.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,43 @@ pub fn gen_name_id(s: impl AsRef<str>, default: &str) -> String {
143143
.chain(hash)
144144
.collect::<String>()
145145
}
146+
147+
pub fn duration(ms: i64, relative: bool) -> String {
148+
let neg = ms < 0;
149+
let ms = ms.abs();
150+
let mut parts = Vec::with_capacity(5);
151+
152+
if relative && neg {
153+
parts.push("in".to_string());
154+
}
155+
156+
if ms == 0 {
157+
parts.push("0ms".to_string());
158+
} else if ms < 1000 {
159+
parts.push(format!("{ms}ms"));
160+
} else {
161+
let days = ms / 86_400_000;
162+
let hours = (ms % 86_400_000) / 3_600_000;
163+
let minutes = (ms % 3_600_000) / 60_000;
164+
let seconds = (ms % 60_000) / 1_000;
165+
166+
if days > 0 {
167+
parts.push(format!("{days}d"));
168+
}
169+
if hours > 0 {
170+
parts.push(format!("{hours}h"));
171+
}
172+
if minutes > 0 {
173+
parts.push(format!("{minutes}m"));
174+
}
175+
if ms < 60_000 && seconds > 0 {
176+
parts.push(format!("{seconds}s"));
177+
}
178+
}
179+
180+
if relative && !neg {
181+
parts.push("ago".to_string());
182+
}
183+
184+
parts.join(" ")
185+
}

packages/core/services/cluster/src/ops/server/get.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(crate) struct ServerRow {
2525
provider_server_id: Option<String>,
2626
vlan_ip: Option<IpAddr>,
2727
public_ip: Option<IpAddr>,
28+
create_ts: i64,
2829
cloud_destroy_ts: Option<i64>,
2930
state: i64,
3031
}
@@ -40,6 +41,7 @@ impl TryFrom<ServerRow> for Server {
4041
provider_server_id: value.provider_server_id,
4142
lan_ip: value.vlan_ip,
4243
wan_ip: value.public_ip,
44+
create_ts: value.create_ts,
4345
cloud_destroy_ts: value.cloud_destroy_ts,
4446
state: unwrap!(ServerState::from_repr(value.state.try_into()?)),
4547
})
@@ -58,6 +60,7 @@ pub async fn cluster_server_get(ctx: &OperationCtx, input: &Input) -> GlobalResu
5860
provider_server_id,
5961
vlan_ip,
6062
public_ip,
63+
create_ts,
6164
cloud_destroy_ts,
6265
CASE
6366
WHEN cloud_destroy_ts IS NOT NULL THEN 6 -- Destroyed

packages/core/services/cluster/src/ops/server/list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub async fn cluster_server_list(ctx: &OperationCtx, input: &Input) -> GlobalRes
3030
s.provider_server_id,
3131
s.vlan_ip,
3232
s.public_ip,
33+
s.create_ts,
3334
s.cloud_destroy_ts,
3435
CASE
3536
WHEN s.cloud_destroy_ts IS NOT NULL THEN 6 -- Destroyed

packages/core/services/cluster/src/ops/server/lost_list.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,17 @@ async fn run_for_linode_account(
143143
s.provider_server_id,
144144
s.vlan_ip,
145145
s.public_ip,
146-
s.cloud_destroy_ts
146+
s.create_ts,
147+
s.cloud_destroy_ts,
148+
CASE
149+
WHEN s.cloud_destroy_ts IS NOT NULL THEN 6 -- Destroyed
150+
WHEN s.taint_ts IS NOT NULL AND s.drain_ts IS NOT NULL THEN 5 -- TaintedDraining
151+
WHEN s.drain_ts IS NOT NULL THEN 4 -- Draining
152+
WHEN s.taint_ts IS NOT NULL THEN 3 -- Tainted
153+
WHEN s.install_complete_ts IS NOT NULL THEN 2 -- Running
154+
WHEN s.provision_complete_ts IS NOT NULL THEN 1 -- Installing
155+
ELSE 0 -- Provisioning
156+
END AS state
147157
FROM db_cluster.servers AS s
148158
JOIN db_cluster.datacenters AS d
149159
ON s.datacenter_id = d.datacenter_id

packages/core/services/cluster/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub struct Server {
148148
pub provider_server_id: Option<String>,
149149
pub lan_ip: Option<IpAddr>,
150150
pub wan_ip: Option<IpAddr>,
151+
pub create_ts: i64,
151152
pub cloud_destroy_ts: Option<i64>,
152153
pub state: ServerState,
153154
}

packages/edge/services/pegboard/src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ lazy_static::lazy_static! {
4040

4141
pub static ref ENV_CPU_USAGE: IntGaugeVec = register_int_gauge_vec_with_registry!(
4242
"pegboard_env_cpu_usage",
43-
"Total percent of CPU (per core) used by an environment.",
43+
"Total millicores used by an environment.",
4444
&["env_id", "flavor"],
4545
*REGISTRY,
4646
).unwrap();

packages/edge/services/pegboard/src/ops/actor/get.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub async fn pegboard_actor_get(ctx: &OperationCtx, input: &Input) -> GlobalResu
133133
let pool = &pool;
134134

135135
let (actor_row, port_ingress_rows, port_host_rows, port_proxied_rows) = tokio::try_join!(
136-
sql_fetch_one!(
136+
sql_fetch_optional!(
137137
[ctx, ActorRow, pool]
138138
"
139139
SELECT
@@ -184,6 +184,11 @@ pub async fn pegboard_actor_get(ctx: &OperationCtx, input: &Input) -> GlobalResu
184184
),
185185
)?;
186186

187+
let Some(actor_row) = actor_row else {
188+
tracing::error!(?actor_id, ?workflow_id, "actor has no state row");
189+
return Ok(None);
190+
};
191+
187192
GlobalResult::Ok(Some(ActorData {
188193
actor_id,
189194
row: actor_row,

packages/edge/services/pegboard/standalone/usage-metrics-publish/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use futures_util::{StreamExt, TryStreamExt};
88
use pegboard::{keys, protocol};
99

1010
struct Usage {
11-
// Percent of core.
11+
// Millicores.
1212
pub cpu: u64,
1313
/// MiB.
1414
pub memory: u64,
@@ -115,7 +115,7 @@ pub async fn run_from_env(
115115
.entry((actor.env_id, client_flavor))
116116
.or_insert(Usage { cpu: 0, memory: 0 });
117117

118-
env_usage.cpu += (actor.resources.cpu_millicores / 10) as u64;
118+
env_usage.cpu += actor.resources.cpu_millicores as u64;
119119
env_usage.memory += actor.resources.memory_mib as u64;
120120
}
121121

0 commit comments

Comments
 (0)