Skip to content

Commit

Permalink
Merge branch 'main' into dap/sled-agent-services-type
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Nov 30, 2023
2 parents 5e55c48 + 7ef3631 commit e9af61c
Show file tree
Hide file tree
Showing 64 changed files with 1,840 additions and 632 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hakari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
toolchain: stable
- name: Install cargo-hakari
uses: taiki-e/install-action@f7c663c03b51ed0d93e9cec22a575d3f02175989 # v2
uses: taiki-e/install-action@6b385b7509c65e9d1b7d6b72244f7e275a7f5cef # v2
with:
tool: cargo-hakari
- name: Check workspace-hack Cargo.toml is up-to-date
Expand Down
26 changes: 13 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl From<&omicron_common::api::internal::nexus::ProducerEndpoint>
address: s.address.to_string(),
base_route: s.base_route.clone(),
id: s.id,
kind: s.kind.map(Into::into),
kind: s.kind.into(),
interval: s.interval.into(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion clients/oximeter-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl From<&omicron_common::api::internal::nexus::ProducerEndpoint>
address: s.address.to_string(),
base_route: s.base_route.clone(),
id: s.id,
kind: s.kind.map(Into::into),
kind: s.kind.into(),
interval: s.interval.into(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct ProducerEndpoint {
/// A unique ID for this producer.
pub id: Uuid,
/// The kind of producer.
pub kind: Option<ProducerKind>,
pub kind: ProducerKind,
/// The IP address and port at which `oximeter` can collect metrics from the
/// producer.
pub address: SocketAddr,
Expand Down
7 changes: 5 additions & 2 deletions common/src/api/internal/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ pub struct PortConfigV1 {
pub uplink_port_fec: PortFec,
/// BGP peers on this port
pub bgp_peers: Vec<BgpPeerConfig>,
/// Whether or not to set autonegotiation
pub autoneg: bool,
}

impl From<UplinkConfig> for PortConfigV1 {
Expand All @@ -155,6 +157,7 @@ impl From<UplinkConfig> for PortConfigV1 {
uplink_port_speed: value.uplink_port_speed,
uplink_port_fec: value.uplink_port_fec,
bgp_peers: vec![],
autoneg: false,
}
}
}
Expand Down Expand Up @@ -260,7 +263,7 @@ pub enum ExternalPortDiscovery {
}

/// Switchport Speed options
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum PortSpeed {
#[serde(alias = "0G")]
Expand All @@ -284,7 +287,7 @@ pub enum PortSpeed {
}

/// Switchport FEC options
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum PortFec {
Firecode,
Expand Down
4 changes: 2 additions & 2 deletions nexus/db-model/src/producer_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct ProducerEndpoint {
#[diesel(embed)]
identity: ProducerEndpointIdentity,

pub kind: Option<ProducerKind>,
pub kind: ProducerKind,
pub ip: ipnetwork::IpNetwork,
pub port: SqlU16,
pub interval: f64,
Expand All @@ -69,7 +69,7 @@ impl ProducerEndpoint {
) -> Self {
Self {
identity: ProducerEndpointIdentity::new(endpoint.id),
kind: endpoint.kind.map(Into::into),
kind: endpoint.kind.into(),
ip: endpoint.address.ip().into(),
port: endpoint.address.port().into(),
base_route: endpoint.base_route.clone(),
Expand Down
5 changes: 3 additions & 2 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ table! {
mtu -> Int4,
fec -> crate::SwitchLinkFecEnum,
speed -> crate::SwitchLinkSpeedEnum,
autoneg -> Bool,
}
}

Expand Down Expand Up @@ -399,7 +400,7 @@ table! {
id -> Uuid,
time_created -> Timestamptz,
time_modified -> Timestamptz,
kind -> Nullable<crate::ProducerKindEnum>,
kind -> crate::ProducerKindEnum,
ip -> Inet,
port -> Int4,
interval -> Float8,
Expand Down Expand Up @@ -1300,7 +1301,7 @@ table! {
///
/// This should be updated whenever the schema is changed. For more details,
/// refer to: schema/crdb/README.adoc
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(15, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(17, 0, 0);

allow_tables_to_appear_in_same_query!(
system_update,
Expand Down
3 changes: 3 additions & 0 deletions nexus/db-model/src/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ pub struct SwitchPortLinkConfig {
pub mtu: SqlU16,
pub fec: SwitchLinkFec,
pub speed: SwitchLinkSpeed,
pub autoneg: bool,
}

impl SwitchPortLinkConfig {
Expand All @@ -365,13 +366,15 @@ impl SwitchPortLinkConfig {
mtu: u16,
fec: SwitchLinkFec,
speed: SwitchLinkSpeed,
autoneg: bool,
) -> Self {
Self {
port_settings_id,
lldp_service_config_id,
link_name,
fec,
speed,
autoneg,
mtu: mtu.into(),
}
}
Expand Down
112 changes: 112 additions & 0 deletions nexus/db-queries/src/db/column_walker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// 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/.

//! CTE utility for iterating over all columns in a table.
use diesel::prelude::*;
use std::marker::PhantomData;

/// Used to iterate over a tuple of columns ("T").
///
/// Diesel exposes "AllColumns" as a tuple, which is difficult to iterate over
/// -- after all, all the types are distinct. However, each of these types
/// implements "Column", so we can use a macro to provide a
/// "convertion-to-iterator" implemenation for our expected tuples.
pub(crate) struct ColumnWalker<T> {
remaining: PhantomData<T>,
}

impl<T> ColumnWalker<T> {
pub fn new() -> Self {
Self { remaining: PhantomData }
}
}

macro_rules! impl_column_walker {
( $len:literal $($column:ident)+ ) => (
impl<$($column: Column),+> IntoIterator for ColumnWalker<($($column,)+)> {
type Item = &'static str;
type IntoIter = std::array::IntoIter<Self::Item, $len>;

fn into_iter(self) -> Self::IntoIter {
[$($column::NAME,)+].into_iter()
}
}
);
}

// implementations for 1 - 32 columns
impl_column_walker! { 1 A }
impl_column_walker! { 2 A B }
impl_column_walker! { 3 A B C }
impl_column_walker! { 4 A B C D }
impl_column_walker! { 5 A B C D E }
impl_column_walker! { 6 A B C D E F }
impl_column_walker! { 7 A B C D E F G }
impl_column_walker! { 8 A B C D E F G H }
impl_column_walker! { 9 A B C D E F G H I }
impl_column_walker! { 10 A B C D E F G H I J }
impl_column_walker! { 11 A B C D E F G H I J K }
impl_column_walker! { 12 A B C D E F G H I J K L }
impl_column_walker! { 13 A B C D E F G H I J K L M }
impl_column_walker! { 14 A B C D E F G H I J K L M N }
impl_column_walker! { 15 A B C D E F G H I J K L M N O }
impl_column_walker! { 16 A B C D E F G H I J K L M N O P }
impl_column_walker! { 17 A B C D E F G H I J K L M N O P Q }
impl_column_walker! { 18 A B C D E F G H I J K L M N O P Q R }
impl_column_walker! { 19 A B C D E F G H I J K L M N O P Q R S }
impl_column_walker! { 20 A B C D E F G H I J K L M N O P Q R S T }
impl_column_walker! { 21 A B C D E F G H I J K L M N O P Q R S T U }
impl_column_walker! { 22 A B C D E F G H I J K L M N O P Q R S T U V }
impl_column_walker! { 23 A B C D E F G H I J K L M N O P Q R S T U V W }
impl_column_walker! { 24 A B C D E F G H I J K L M N O P Q R S T U V W X }
impl_column_walker! { 25 A B C D E F G H I J K L M N O P Q R S T U V W X Y }
impl_column_walker! { 26 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z }
impl_column_walker! { 27 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A1 }
impl_column_walker! { 28 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A1 B1 }
impl_column_walker! { 29 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A1 B1 C1 }
impl_column_walker! { 30 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A1 B1 C1 D1 }
impl_column_walker! { 31 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A1 B1 C1 D1 E1 }
impl_column_walker! { 32 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A1 B1 C1 D1 E1 F1 }

#[cfg(test)]
mod test {
use super::*;

table! {
test_schema.test_table (id) {
id -> Uuid,
value -> Int4,
time_deleted -> Nullable<Timestamptz>,
}
}

// We can convert all a tables columns into an iteratable format.
#[test]
fn test_walk_table() {
let all_columns =
ColumnWalker::<<test_table::table as Table>::AllColumns>::new();

let mut iter = all_columns.into_iter();
assert_eq!(iter.next(), Some("id"));
assert_eq!(iter.next(), Some("value"));
assert_eq!(iter.next(), Some("time_deleted"));
assert_eq!(iter.next(), None);
}

// We can, if we want to, also make a ColumnWalker out of an arbitrary tuple
// of columns.
#[test]
fn test_walk_columns() {
let all_columns = ColumnWalker::<(
test_table::columns::id,
test_table::columns::value,
)>::new();

let mut iter = all_columns.into_iter();
assert_eq!(iter.next(), Some("id"));
assert_eq!(iter.next(), Some("value"));
assert_eq!(iter.next(), None);
}
}
Loading

0 comments on commit e9af61c

Please sign in to comment.