Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ dropshot-api-manager-types = "0.2.2"
expectorate = "1"
futures = "0.3"
http = "1.2.0"
humantime = "2.3"
kstat-rs = "0.2.4"
lazy_static = "1.5"
libc = "0.2"
Expand Down
10 changes: 8 additions & 2 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ fn timestamp() -> Duration {
Instant::now().duration_since(START_OF_DAY.unwrap())
}
}
/// Return a timestamp in nanoseconds
/// Return a START_OF_DAY-relative timestamp in nanoseconds
pub fn timestamp_ns() -> i64 {
i64::try_from(timestamp().as_nanos()).unwrap()
}

/// Return a timestamp in milliseconds
/// Return a START_OF_DAY-relative timestamp in milliseconds
pub fn timestamp_ms() -> i64 {
i64::try_from(timestamp().as_millis()).unwrap()
}

/// Return a time-of-day timestamp in milliseconds
pub fn wallclock_ms() -> i64 {
let now = chrono::Utc::now();
now.timestamp_millis()
}
20 changes: 20 additions & 0 deletions dpd-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use transceiver_controller::{

mod v1;
mod v2;
mod v3;

api_versions!([
// WHEN CHANGING THE API (part 1 of 2):
Expand All @@ -60,6 +61,7 @@ api_versions!([
// | example for the next person.
// v
// (next_int, IDENT),
(7, WALLCLOCK_HISTORY),
(6, CONSOLIDATED_V4_ROUTES),
(5, UPLINK_PORTS),
(4, V4_OVER_V6_ROUTES),
Expand Down Expand Up @@ -1145,6 +1147,24 @@ pub trait DpdApi {
#[endpoint {
method = GET,
path = "/ports/{port_id}/links/{link_id}/history",
versions = ..VERSION_WALLCLOCK_HISTORY
}]
async fn link_history_get_v3(
rqctx: RequestContext<Self::Context>,
path: Path<LinkPath>,
) -> Result<HttpResponseOk<v3::LinkHistory>, HttpError> {
let history = Self::link_history_get(rqctx, path).await?.0;
Ok(HttpResponseOk(v3::LinkHistory {
timestamp: history.relative,
events: history.events,
}))
}

/// Get the event history for the given link.
#[endpoint {
method = GET,
path = "/ports/{port_id}/links/{link_id}/history",
versions = VERSION_WALLCLOCK_HISTORY..
}]
async fn link_history_get(
rqctx: RequestContext<Self::Context>,
Expand Down
16 changes: 16 additions & 0 deletions dpd-api/src/v3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/
//
// Copyright 2026 Oxide Computer Company

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
pub struct LinkHistory {
/// The timestamp in milliseconds at which this history was collected
pub timestamp: i64,
/// The set of historical events recorded
pub events: Vec<dpd_types::views::LinkEvent>,
}
5 changes: 4 additions & 1 deletion dpd-types/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ pub struct LinkEvent {

#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
pub struct LinkHistory {
/// The timestamp in milliseconds at which this history was collected.
/// The wallclock time in milliseconds at which this history was collected.
pub timestamp: i64,
/// The timestamp in milliseconds at which this history was collected,
/// relative to the time the switch management daemon started.
pub relative: i64,
/// The set of historical events recorded
pub events: Vec<LinkEvent>,
}
Expand Down
3 changes: 2 additions & 1 deletion dpd/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ impl Switch {
let mut events = self.fetch_history(asic_ids);
events.sort_by_key(|a| a.timestamp);
Ok(views::LinkHistory {
timestamp: common::timestamp_ms(),
timestamp: common::wallclock_ms(),
relative: common::timestamp_ms(),
events: events.iter().map(|er| er.into()).collect(),
})
}
Expand Down
Loading