Skip to content
Merged
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.5.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 @@ -113,12 +113,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 @@ -7,6 +7,7 @@
//! DPD endpoint definitions.

pub mod v1;
pub mod v11;
pub mod v2;
pub mod v7;

Expand Down Expand Up @@ -63,6 +64,7 @@ api_versions!([
// | example for the next person.
// v
// (next_int, IDENT),
(11, WALLCLOCK_HISTORY),
(10, ASIC_DETAILS),
(9, SNAPSHOT),
(8, MCAST_STRICT_UNDERLAY),
Expand Down Expand Up @@ -1173,6 +1175,24 @@ pub trait DpdApi {
#[endpoint {
method = GET,
path = "/ports/{port_id}/links/{link_id}/history",
versions = ..VERSION_WALLCLOCK_HISTORY
}]
async fn link_history_get_v11(
rqctx: RequestContext<Self::Context>,
path: Path<LinkPath>,
) -> Result<HttpResponseOk<v11::LinkHistory>, HttpError> {
let history = Self::link_history_get(rqctx, path).await?.0;
Ok(HttpResponseOk(v11::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/v11.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
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timestamp field represents the pre-v7 history collection time (returned as history.relative in link_history_get_v3), i.e. a daemon-uptime-relative millisecond value, not wallclock time. Update this field’s doc comment to avoid implying it is wallclock/absolute time.

Suggested change
/// The timestamp in milliseconds at which this history was collected
/// The pre-v7 history collection time for this record, in milliseconds,
/// measured relative to the daemon's uptime (as returned in
/// `history.relative` by `link_history_get_v3`), not wallclock/absolute time.

Copilot uses AI. Check for mistakes.
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 @@ -995,7 +995,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
1 change: 1 addition & 0 deletions openapi/dpd/dpd-10.0.0-57485f.json.gitstub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
78fa4e7c745169e48c7a1d4a0aaa5e9ac47d8057:openapi/dpd/dpd-10.0.0-57485f.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://oxide.computer",
"email": "api@oxide.computer"
},
"version": "10.0.0"
"version": "11.0.0"
},
"paths": {
"/all-settings": {
Expand Down Expand Up @@ -7758,14 +7758,20 @@
"$ref": "#/components/schemas/LinkEvent"
}
},
"relative": {
"description": "The timestamp in milliseconds at which this history was collected, relative to the time the switch management daemon started.",
"type": "integer",
"format": "int64"
},
"timestamp": {
"description": "The timestamp in milliseconds at which this history was collected.",
"description": "The wallclock time in milliseconds at which this history was collected.",
"type": "integer",
"format": "int64"
}
},
"required": [
"events",
"relative",
"timestamp"
]
},
Expand Down
2 changes: 1 addition & 1 deletion openapi/dpd/dpd-latest.json
4 changes: 3 additions & 1 deletion swadm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ colored.workspace = true
common.workspace = true
dpd-client.workspace = true
futures.workspace = true
reqwest.workspace = true
humantime.workspace = true
oxide-tokio-rt.workspace = true
oxnet.workspace = true
regex.workspace = true
reqwest.workspace = true
slog.workspace = true
tabwriter.workspace = true
tokio.workspace = true
1 change: 1 addition & 0 deletions swadm/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use dpd_client::types;
/// non-development debugging, you probably want "swadm link counters".
pub enum P4Counters {
/// list all available counters
#[clap(visible_alias = "ls")]
List,
/// get data from the given counter
Get {
Expand Down
Loading