Skip to content

Commit e09858f

Browse files
davidv1992rnijveld
authored andcommitted
[Management] Refined log display to display more relevant info.
Currently extracts the status for the 3 probe operations.
1 parent 719805a commit e09858f

3 files changed

Lines changed: 99 additions & 45 deletions

File tree

nts-pool-management/assets/components.css

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,20 @@ table {
301301
}
302302
}
303303

304+
table.birowed {
305+
tbody {
306+
tr:nth-child(4n + 1),
307+
tr:nth-child(4n + 4) {
308+
background-color: var(--white);
309+
}
310+
311+
tr:nth-child(4n + 2),
312+
tr:nth-child(4n + 3) {
313+
background-color: transparent;
314+
}
315+
}
316+
}
317+
304318
table.autowidth {
305319
width: auto;
306320

@@ -319,34 +333,6 @@ table.autowidth {
319333
background-color: var(--white);
320334
}
321335

322-
.grid-table {
323-
display: grid;
324-
grid-template-columns: 1fr 3fr 1fr 1fr;
325-
justify-content: space-around;
326-
327-
.sample {
328-
grid-column-start: 1;
329-
grid-column-end: 5;
330-
331-
white-space: pre;
332-
white-space: nowrap;
333-
overflow-x: auto;
334-
margin-bottom: var(--space-sm);
335-
padding: var(--space-sm);
336-
font-family: monospace;
337-
}
338-
339-
.grid-table-header {
340-
font-weight: var(--bold);
341-
342-
margin-bottom: var(--space-sm);
343-
}
344-
345-
div:not(.grid-table-header) {
346-
background-color: var(--white);
347-
}
348-
}
349-
350336
.nowrap {
351337
white-space: nowrap;
352338
}

nts-pool-management/src/routes/management.rs

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use axum::{
66
extract::{Path, Query, State},
77
response::{IntoResponse, Redirect},
88
};
9+
use chrono::{DateTime, Utc};
910
use nts_pool_shared::IpVersion;
1011
use serde::Deserialize;
12+
use serde_json::Value;
1113

1214
use crate::{
1315
AppState,
@@ -17,9 +19,7 @@ use crate::{
1719
error::AppError,
1820
models::{
1921
monitor::MonitorId,
20-
time_source::{
21-
self, LogRow, NewTimeSourceForm, TimeSource, TimeSourceId, UpdateTimeSourceForm,
22-
},
22+
time_source::{self, NewTimeSourceForm, TimeSource, TimeSourceId, UpdateTimeSourceForm},
2323
},
2424
templates::{HtmlTemplate, filters},
2525
};
@@ -49,12 +49,21 @@ struct ScoreTableData {
4949
ipv6: f64,
5050
}
5151

52+
struct DisplayLogRow {
53+
time: DateTime<Utc>,
54+
ke_status: String,
55+
ntp_from_ke_status: String,
56+
ntp_from_ntp_status: String,
57+
score: f64,
58+
raw_sample: Value,
59+
}
60+
5261
#[derive(Template)]
5362
#[template(path = "management/time_source_details.html.j2")]
5463
struct TimeSourceInfoTemplate {
5564
app: AppContext,
5665
ts: TimeSource,
57-
log: Vec<LogRow>,
66+
log: Vec<DisplayLogRow>,
5867
scores: Vec<ScoreTableData>,
5968
monitors: Vec<String>,
6069
cur_monitor: Option<MonitorId>,
@@ -67,6 +76,29 @@ pub struct LogSelection {
6776
protocol: Option<IpVersion>,
6877
}
6978

79+
fn extract_keyexchange_status(ke: &Value) -> Option<String> {
80+
ke.get("description")
81+
.and_then(|ke_status| ke_status.as_str())
82+
.and_then(|ke_status| {
83+
if !ke_status.is_empty() {
84+
Some(ke_status.to_owned())
85+
} else {
86+
None
87+
}
88+
})
89+
.or_else(|| {
90+
ke.get("status")
91+
.and_then(|ke_status| ke_status.as_str())
92+
.map(|ke_status| ke_status.to_owned())
93+
})
94+
}
95+
96+
fn extract_ntp_status(ntp: &Value) -> Option<String> {
97+
ntp.get("status")
98+
.and_then(|ntp_status| ntp_status.as_str())
99+
.map(|ntp_status| ntp_status.to_owned())
100+
}
101+
70102
pub async fn time_source_info(
71103
Path(time_source_id): Path<TimeSourceId>,
72104
app: AppContext,
@@ -85,7 +117,7 @@ pub async fn time_source_info(
85117
}
86118
}
87119
let monitors: Vec<String> = scoremap.iter().map(|v| v.0.clone()).collect();
88-
let log = if let Some(cur_monitor) = cur_monitor {
120+
let logs = if let Some(cur_monitor) = cur_monitor {
89121
time_source::logs(&state.db, time_source_id, cur_monitor, cur_protocol, 0, 200).await?
90122
} else {
91123
vec![]
@@ -102,7 +134,35 @@ pub async fn time_source_info(
102134
ipv6: v.1.1,
103135
})
104136
.collect(),
105-
log,
137+
log: logs
138+
.into_iter()
139+
.map(|v| DisplayLogRow {
140+
time: v
141+
.sample
142+
.get("keyexchange")
143+
.and_then(|ke| ke.get("exchange_start"))
144+
.and_then(|start| start.as_i64())
145+
.and_then(|start| DateTime::from_timestamp(start, 0))
146+
.unwrap_or(v.received_at),
147+
ke_status: v
148+
.sample
149+
.get("keyexchange")
150+
.and_then(extract_keyexchange_status)
151+
.unwrap_or_default(),
152+
ntp_from_ke_status: v
153+
.sample
154+
.get("ntp_with_ke_cookie")
155+
.and_then(extract_ntp_status)
156+
.unwrap_or_default(),
157+
ntp_from_ntp_status: v
158+
.sample
159+
.get("ntp_with_ntp_cookie")
160+
.and_then(extract_ntp_status)
161+
.unwrap_or_default(),
162+
score: v.score,
163+
raw_sample: v.sample,
164+
})
165+
.collect(),
106166
monitors,
107167
cur_monitor,
108168
cur_protocol,

nts-pool-management/templates/management/time_source_details.html.j2

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,27 @@
4040
</select>
4141
<button type="submit">apply</button>
4242
</form>
43-
<div class="grid-table">
44-
<div class="grid-table-header">Received at</div>
45-
<div class="grid-table-header">Monitor</div>
46-
<div class="grid-table-header">Protocol</div>
47-
<div class="grid-table-header">New score</div>
43+
<table class="birowed">
44+
<tr>
45+
<th>Time</th>
46+
<th>Key exchange</th>
47+
<th>Ntp (cookie from KE)</th>
48+
<th>Ntp (cookie from NTP)</th>
49+
<th>New score</th>
50+
</tr>
4851
{% for row in log %}
49-
<div title="{{ row.received_at }}">{{ row.received_at.format("%Y-%m-%d %H:%M") }}</div>
50-
<div>{{ row.monitor }}</div>
51-
<div>{{ row.protocol }}</div>
52-
<div title="{{ row.score }}">{{ row.score | fmt("{:.1}") }}</div>
53-
<div class="sample">{{ row.sample }}</div>
52+
<tr>
53+
<td rowspan=2>{{ row.time.format("%Y-%m-%d %H:%M") }}</td>
54+
<td>{{ row.ke_status }}</td>
55+
<td>{{ row.ntp_from_ke_status }}</td>
56+
<td>{{ row.ntp_from_ntp_status }}</td>
57+
<td>{{ row.score | fmt("{:.1}") }}</td>
58+
</tr>
59+
<tr>
60+
<td colspan=4><details name="samples"><summary>raw sample</summary><code-block>{{ row.raw_sample | fmt("{:#}") }}</code-block></details></td>
61+
</tr>
5462
{% endfor %}
55-
</div>
63+
</table>
5664
{% else %}
5765
No monitoring logs available.
5866
{% endif %}

0 commit comments

Comments
 (0)