Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop the service table #5287

Merged
merged 31 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8411343
wip: rack init reads from blueprint instead of services
jgallagher Mar 13, 2024
175344a
fix remaining datastore rack tests using services
jgallagher Mar 14, 2024
bfb2c08
Remove `services` from `RackInitRequest`; remove `ServicePutRequest`
jgallagher Mar 14, 2024
a89e5fd
remove `service` table references from omdb
jgallagher Mar 14, 2024
59cf61a
fix omdb tests
jgallagher Mar 15, 2024
aa8a47e
update internal nexus openapi
jgallagher Mar 15, 2024
c56504e
appease clippy
jgallagher Mar 15, 2024
c8719c6
Merge branch 'main' into john/remove-service-table
jgallagher Mar 18, 2024
90439c8
remove service table from dbinit
jgallagher Mar 18, 2024
cb3ef62
remove unused sled_resource_kind variants
jgallagher Mar 18, 2024
1f70b6c
replace last comment referencing `service` table
jgallagher Mar 18, 2024
c74a47e
Merge remote-tracking branch 'origin/main' into john/remove-service-t…
jgallagher Mar 18, 2024
39c9eb0
remove unused sled_resource_kind variants
jgallagher Mar 19, 2024
04e02e7
Merge remote-tracking branch 'origin/main' into john/remove-service-t…
jgallagher Mar 19, 2024
36121a2
remove unused omdb subcommands from expectorate test
jgallagher Mar 19, 2024
27e054f
Merge branch 'main' into john/remove-service-table
jgallagher Mar 22, 2024
dc18f57
swap up1 and up2 - check before drop
jgallagher Mar 22, 2024
7de458e
add assert_service_sled_ids() helper
jgallagher Mar 22, 2024
34835f2
Merge branch 'main' into john/remove-service-table
jgallagher Mar 28, 2024
88aaf03
migration: avoid rewriting table twice
jgallagher Mar 28, 2024
78f9429
move 'no target blueprint' error to loading blueprint from db
jgallagher Mar 29, 2024
d041cf6
Merge branch 'main' into john/remove-service-table
jgallagher Mar 29, 2024
faa9ddb
fixes from merging main
jgallagher Mar 29, 2024
0bbc9b9
omdb expectorate
jgallagher Mar 29, 2024
fcf547a
add omdb success test for showing a blueprint
jgallagher Mar 29, 2024
3fd0288
omdb nexus blueprint show: use blueprint.display()
jgallagher Mar 29, 2024
168e346
Merge branch 'main' into john/remove-service-table
jgallagher Apr 11, 2024
4f57661
test fixups after merging main
jgallagher Apr 11, 2024
ea7bd17
Merge branch 'main' into john/remove-service-table
jgallagher Apr 11, 2024
e440f70
clippy appeasement
jgallagher Apr 11, 2024
bb7b1eb
Merge branch 'main' into john/remove-service-table
jgallagher Apr 15, 2024
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
190 changes: 5 additions & 185 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ enum DbCommands {
Inventory(InventoryArgs),
/// Save the current Reconfigurator inputs to a file
ReconfiguratorSave(ReconfiguratorSaveArgs),
/// Print information about control plane services
Services(ServicesArgs),
/// Print information about sleds
Sleds,
/// Print information about customer instances
Expand Down Expand Up @@ -398,20 +396,6 @@ struct ReconfiguratorSaveArgs {
output_file: Utf8PathBuf,
}

#[derive(Debug, Args)]
struct ServicesArgs {
#[command(subcommand)]
command: ServicesCommands,
}

#[derive(Debug, Subcommand)]
enum ServicesCommands {
/// List service instances
ListInstances,
/// List service instances, grouped by sled
ListBySled,
}

#[derive(Debug, Args)]
struct NetworkArgs {
#[command(subcommand)]
Expand Down Expand Up @@ -520,26 +504,6 @@ impl DbArgs {
)
.await
}
DbCommands::Services(ServicesArgs {
command: ServicesCommands::ListInstances,
}) => {
cmd_db_services_list_instances(
&opctx,
&datastore,
&self.fetch_opts,
)
.await
}
DbCommands::Services(ServicesArgs {
command: ServicesCommands::ListBySled,
}) => {
cmd_db_services_list_by_sled(
&opctx,
&datastore,
&self.fetch_opts,
)
.await
}
DbCommands::Sleds => {
cmd_db_sleds(&opctx, &datastore, &self.fetch_opts).await
}
Expand Down Expand Up @@ -697,41 +661,11 @@ struct ServiceInfo {

/// Helper function to look up the service with the given ID.
///
/// Requires the caller to first have fetched the current target blueprint, so
/// we can find services that have been added by Reconfigurator.
/// Requires the caller to first have fetched the current target blueprint.
async fn lookup_service_info(
datastore: &DataStore,
service_id: Uuid,
current_target_blueprint: Option<&Blueprint>,
blueprint: &Blueprint,
) -> anyhow::Result<Option<ServiceInfo>> {
let conn = datastore.pool_connection_for_tests().await?;

// We need to check the `service` table (populated during rack setup)...
{
use db::schema::service::dsl;
if let Some(kind) = dsl::service
.filter(dsl::id.eq(service_id))
.limit(1)
.select(dsl::kind)
.get_result_async(&*conn)
.await
.optional()
.with_context(|| format!("loading service {service_id}"))?
{
// XXX: the services table is going to go away soon!
return Ok(Some(ServiceInfo {
service_kind: kind,
disposition: BlueprintZoneDisposition::InService,
}));
}
}

// ...and if we don't find the service, check the latest blueprint, because
// the service might have been added by Reconfigurator after RSS ran.
let Some(blueprint) = current_target_blueprint else {
return Ok(None);
};

let Some(zone_config) = blueprint
.all_blueprint_zones(BlueprintZoneFilter::All)
.find_map(|(_sled_id, zone_config)| {
Expand Down Expand Up @@ -1466,61 +1400,6 @@ async fn cmd_db_snapshot_info(
Ok(())
}

/// Run `omdb db services list-instances`.
async fn cmd_db_services_list_instances(
opctx: &OpContext,
datastore: &DataStore,
fetch_opts: &DbFetchOptions,
) -> Result<(), anyhow::Error> {
let limit = fetch_opts.fetch_limit;
let sled_list = datastore
.sled_list(&opctx, &first_page(limit))
.await
.context("listing sleds")?;
check_limit(&sled_list, limit, || String::from("listing sleds"));

let sleds: BTreeMap<Uuid, Sled> =
sled_list.into_iter().map(|s| (s.id(), s)).collect();

let mut rows = vec![];

for service_kind in ServiceKind::iter() {
let context =
|| format!("listing instances of kind {:?}", service_kind);
let instances = datastore
.services_list_kind(&opctx, service_kind, &first_page(limit))
.await
.with_context(&context)?;
check_limit(&instances, limit, &context);

rows.extend(instances.into_iter().map(|instance| {
let addr =
std::net::SocketAddrV6::new(*instance.ip, *instance.port, 0, 0)
.to_string();

ServiceInstanceRow {
kind: format!("{:?}", service_kind),
instance_id: instance.id(),
addr,
sled_serial: sleds
.get(&instance.sled_id)
.map(|s| s.serial_number())
.unwrap_or("unknown")
.to_string(),
}
}));
}

let table = tabled::Table::new(rows)
.with(tabled::settings::Style::empty())
.with(tabled::settings::Padding::new(0, 1, 0, 0))
.to_string();

println!("{}", table);

Ok(())
}

// SLEDS

#[derive(Tabled)]
Expand All @@ -1532,63 +1411,6 @@ struct ServiceInstanceSledRow {
addr: String,
}

/// Run `omdb db services list-by-sled`.
async fn cmd_db_services_list_by_sled(
opctx: &OpContext,
datastore: &DataStore,
fetch_opts: &DbFetchOptions,
) -> Result<(), anyhow::Error> {
let limit = fetch_opts.fetch_limit;
let sled_list = datastore
.sled_list(&opctx, &first_page(limit))
.await
.context("listing sleds")?;
check_limit(&sled_list, limit, || String::from("listing sleds"));

let sleds: BTreeMap<Uuid, Sled> =
sled_list.into_iter().map(|s| (s.id(), s)).collect();
let mut services_by_sled: BTreeMap<Uuid, Vec<ServiceInstanceSledRow>> =
BTreeMap::new();

for service_kind in ServiceKind::iter() {
let context =
|| format!("listing instances of kind {:?}", service_kind);
let instances = datastore
.services_list_kind(&opctx, service_kind, &first_page(limit))
.await
.with_context(&context)?;
check_limit(&instances, limit, &context);

for i in instances {
let addr =
std::net::SocketAddrV6::new(*i.ip, *i.port, 0, 0).to_string();
let sled_instances =
services_by_sled.entry(i.sled_id).or_insert_with(Vec::new);
sled_instances.push(ServiceInstanceSledRow {
kind: format!("{:?}", service_kind),
instance_id: i.id(),
addr,
})
}
}

for (sled_id, instances) in services_by_sled {
println!(
"sled: {} (id {})\n",
sleds.get(&sled_id).map(|s| s.serial_number()).unwrap_or("unknown"),
sled_id,
);
let table = tabled::Table::new(instances)
.with(tabled::settings::Style::empty())
.with(tabled::settings::Padding::new(0, 1, 0, 0))
.to_string();
println!("{}", textwrap::indent(&table.to_string(), " "));
println!("");
}

Ok(())
}

#[derive(Tabled)]
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
struct SledRow {
Expand Down Expand Up @@ -2052,19 +1874,17 @@ async fn cmd_db_eips(

let mut rows = Vec::new();

let current_target_blueprint = datastore
let (_, current_target_blueprint) = datastore
.blueprint_target_get_current_full(opctx)
.await
.context("loading current target blueprint")?
.map(|(_, blueprint)| blueprint);
.context("loading current target blueprint")?;

for ip in &ips {
let owner = if let Some(owner_id) = ip.parent_id {
if ip.is_service {
let (kind, disposition) = match lookup_service_info(
datastore,
owner_id,
current_target_blueprint.as_ref(),
&current_target_blueprint,
)
.await?
{
Expand Down
41 changes: 1 addition & 40 deletions dev-tools/omdb/tests/successes.out
Original file line number Diff line number Diff line change
Expand Up @@ -69,45 +69,6 @@ note: database schema version matches expected (<redacted database version>)
assembling reconfigurator state ... done
wrote <TMP_PATH_REDACTED>
=============================================
EXECUTING COMMAND: omdb ["db", "services", "list-instances"]
jgallagher marked this conversation as resolved.
Show resolved Hide resolved
termination: Exited(0)
---------------------------------------------
stdout:
SERVICE INSTANCE_ID ADDR SLED_SERIAL
CruciblePantry ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT sim-b6d65341
ExternalDns ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT sim-b6d65341
InternalDns ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT sim-b6d65341
Nexus ..........<REDACTED_UUID>........... [::ffff:127.0.0.1]:REDACTED_PORT sim-b6d65341
Mgd ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT sim-039be560
Mgd ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT sim-b6d65341
---------------------------------------------
stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
=============================================
EXECUTING COMMAND: omdb ["db", "services", "list-by-sled"]
termination: Exited(0)
---------------------------------------------
stdout:
sled: sim-039be560 (id ..........<REDACTED_UUID>...........)

SERVICE INSTANCE_ID ADDR
Mgd ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT

sled: sim-b6d65341 (id ..........<REDACTED_UUID>...........)

SERVICE INSTANCE_ID ADDR
CruciblePantry ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT
ExternalDns ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT
InternalDns ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT
Nexus ..........<REDACTED_UUID>........... [::ffff:127.0.0.1]:REDACTED_PORT
Mgd ..........<REDACTED_UUID>........... [::1]:REDACTED_PORT

---------------------------------------------
stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
=============================================
EXECUTING COMMAND: omdb ["db", "sleds"]
termination: Exited(0)
---------------------------------------------
Expand Down Expand Up @@ -385,7 +346,7 @@ task: "blueprint_loader"
currently executing: no
last completed activation: iter 2, triggered by an explicit signal
started at <REDACTED TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
warning: unknown background task: "blueprint_loader" (don't know how to interpret details: Object {"status": String("no target blueprint")})
last completion reported error: failed to read target blueprint: Internal Error: no target blueprint set

task: "blueprint_executor"
configured period: every 10m
Expand Down
3 changes: 0 additions & 3 deletions dev-tools/omdb/tests/test_all_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ async fn test_omdb_usage_errors() {
&["db", "dns"],
&["db", "dns", "diff"],
&["db", "dns", "names"],
&["db", "services"],
&["db", "snapshots"],
&["db", "network"],
&["mgs"],
Expand Down Expand Up @@ -90,8 +89,6 @@ async fn test_omdb_success_cases(cptestctx: &ControlPlaneTestContext) {
&["db", "dns", "names", "external", "2"],
&["db", "instances"],
&["db", "reconfigurator-save", tmppath.as_str()],
&["db", "services", "list-instances"],
&["db", "services", "list-by-sled"],
&["db", "sleds"],
&["mgs", "inventory"],
&["nexus", "background-tasks", "doc"],
Expand Down
20 changes: 0 additions & 20 deletions dev-tools/omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ Commands:
dns Print information about internal and external DNS
inventory Print information about collected hardware/software inventory
reconfigurator-save Save the current Reconfigurator inputs to a file
services Print information about control plane services
sleds Print information about sleds
instances Print information about customer instances
network Print information about the network
Expand Down Expand Up @@ -129,7 +128,6 @@ Commands:
dns Print information about internal and external DNS
inventory Print information about collected hardware/software inventory
reconfigurator-save Save the current Reconfigurator inputs to a file
services Print information about control plane services
sleds Print information about sleds
instances Print information about customer instances
network Print information about the network
Expand Down Expand Up @@ -213,24 +211,6 @@ Usage: omdb db dns names <GROUP> <VERSION>

For more information, try '--help'.
=============================================
EXECUTING COMMAND: omdb ["db", "services"]
termination: Exited(2)
---------------------------------------------
stdout:
---------------------------------------------
stderr:
Print information about control plane services

Usage: omdb db services <COMMAND>

Commands:
list-instances List service instances
list-by-sled List service instances, grouped by sled
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help
=============================================
EXECUTING COMMAND: omdb ["db", "snapshots"]
termination: Exited(2)
---------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ mod role_builtin;
pub mod saga_types;
pub mod schema;
mod schema_versions;
mod service;
mod service_kind;
mod silo;
mod silo_group;
Expand Down Expand Up @@ -165,7 +164,6 @@ pub use role_assignment::*;
pub use role_builtin::*;
pub use schema_versions::*;
pub use semver_version::*;
pub use service::*;
pub use service_kind::*;
pub use silo::*;
pub use silo_group::*;
Expand Down
Loading
Loading