Skip to content

Commit b5d9596

Browse files
authored
Server error stats (#581)
* Server message hook * Report server errors * Remove server_errors from show pools * save * accerate arm builds
1 parent 983a8ec commit b5d9596

6 files changed

Lines changed: 49 additions & 1 deletion

File tree

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ WORKDIR /build
1212

1313
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
1414
RUN source ~/.cargo/env && \
15+
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then \
16+
export RUSTFLAGS="-Ctarget-feature=+lse"; \
17+
fi && \
1518
cd pgdog && \
1619
cargo build --release
1720

pgdog/src/admin/show_stats.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl Command for ShowStats {
4242
Field::numeric(&format!("{}_server_parse_count", prefix)),
4343
Field::numeric(&format!("{}_bind_count", prefix)),
4444
Field::numeric(&format!("{}_close_count", prefix)),
45+
Field::numeric(&format!("{}_errors", prefix)),
4546
]
4647
})
4748
.collect::<Vec<Field>>(),
@@ -82,7 +83,8 @@ impl Command for ShowStats {
8283
.add(stat.wait_time.as_millis() as u64)
8384
.add(stat.parse_count)
8485
.add(stat.bind_count)
85-
.add(stat.close);
86+
.add(stat.close)
87+
.add(stat.errors);
8688
}
8789

8890
messages.push(dr.message()?);

pgdog/src/backend/pool/stats.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct Counts {
2424
pub rollbacks: usize,
2525
pub healthchecks: usize,
2626
pub close: usize,
27+
pub errors: usize,
2728
}
2829

2930
impl Sub for Counts {
@@ -47,6 +48,7 @@ impl Sub for Counts {
4748
rollbacks: self.rollbacks.saturating_sub(rhs.rollbacks),
4849
healthchecks: self.healthchecks.saturating_add(rhs.healthchecks),
4950
close: self.close.saturating_add(rhs.close),
51+
errors: self.errors.saturating_add(rhs.errors),
5052
}
5153
}
5254
}
@@ -70,6 +72,7 @@ impl Div<usize> for Counts {
7072
rollbacks: self.rollbacks.saturating_div(rhs),
7173
healthchecks: self.healthchecks.saturating_div(rhs),
7274
close: self.close.saturating_div(rhs),
75+
errors: self.errors.saturating_div(rhs),
7376
}
7477
}
7578
}
@@ -93,6 +96,7 @@ impl Add<BackendCounts> for Counts {
9396
rollbacks: self.rollbacks + rhs.rollbacks,
9497
healthchecks: self.healthchecks + rhs.healthchecks,
9598
close: self.close + rhs.close,
99+
errors: self.errors + rhs.errors,
96100
}
97101
}
98102
}
@@ -129,6 +133,7 @@ impl Add for Counts {
129133
rollbacks: self.rollbacks.saturating_add(rhs.rollbacks),
130134
healthchecks: self.healthchecks.saturating_add(rhs.healthchecks),
131135
close: self.close.saturating_add(rhs.close),
136+
errors: self.errors.saturating_add(rhs.errors),
132137
}
133138
}
134139
}

pgdog/src/frontend/client/query_engine/hooks/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ impl QueryEngineHooks {
3737
) -> Result<(), Error> {
3838
Ok(())
3939
}
40+
41+
pub(super) fn on_server_message(
42+
&mut self,
43+
context: &mut QueryEngineContext<'_>,
44+
message: &Message,
45+
) -> Result<(), Error> {
46+
Ok(())
47+
}
4048
}

pgdog/src/frontend/client/query_engine/query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ impl QueryEngine {
225225
if code == 'Z' {
226226
self.pending_explain = None;
227227
}
228+
self.hooks.on_server_message(context, &message)?;
228229

229230
Ok(())
230231
}

pgdog/src/stats/pools.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ impl Pools {
6565
let mut avg_query_time = vec![];
6666
let mut total_close = vec![];
6767
let mut avg_close = vec![];
68+
let mut total_server_errors = vec![];
69+
let mut avg_server_errors = vec![];
70+
6871
for (user, cluster) in databases().all() {
6972
for (shard_num, shard) in cluster.shards().iter().enumerate() {
7073
for (role, pool) in shard.pools_with_roles() {
@@ -191,6 +194,16 @@ impl Pools {
191194
labels: labels.clone(),
192195
measurement: averages.close.into(),
193196
});
197+
198+
total_server_errors.push(Measurement {
199+
labels: labels.clone(),
200+
measurement: totals.errors.into(),
201+
});
202+
203+
avg_server_errors.push(Measurement {
204+
labels: labels.clone(),
205+
measurement: averages.errors.into(),
206+
});
194207
}
195208
}
196209
}
@@ -372,6 +385,22 @@ impl Pools {
372385
metric_type: None,
373386
}));
374387

388+
metrics.push(Metric::new(PoolMetric {
389+
name: "total_server_errors".into(),
390+
measurements: total_server_errors,
391+
help: "Total number of errors returned by server connections.".into(),
392+
unit: None,
393+
metric_type: Some("counter".into()),
394+
}));
395+
396+
metrics.push(Metric::new(PoolMetric {
397+
name: "avg_server_errors".into(),
398+
measurements: avg_server_errors,
399+
help: "Average number of errors returned by server connections.".into(),
400+
unit: None,
401+
metric_type: None,
402+
}));
403+
375404
Pools { metrics }
376405
}
377406
}

0 commit comments

Comments
 (0)