Skip to content

Commit 199c27a

Browse files
authored
Ensure oximeter schemas do not change (#9341)
Closes: #8862
1 parent 92669b0 commit 199c27a

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

oximeter/db/schema/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ transactions, we actually require that there are no writes of any kind. In
2121
practice, this means `oximeter` **must not** be running when this is called.
2222
Similarly, there must be only a single instance of this program at a time.
2323

24+
_NB: Schema changes for the `oximeter` database are currently disabled due to
25+
ongoing self-service update work. More information about this restriction can
26+
be found in [#8862](https://github.com/oxidecomputer/omicron/issues/8862)_
27+
2428
To run this program:
2529

2630
- Ensure the ClickHouse server is running, and grab its IP address;

oximeter/db/tests/integration_test.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use anyhow::Context;
66
use clickward::{BasePorts, Deployment, DeploymentConfig, KeeperId};
77
use dropshot::test_util::log_prefix_for_test;
8+
use omicron_test_utils::dev::file_checksum;
89
use omicron_test_utils::dev::poll;
910
use omicron_test_utils::dev::test_setup_log;
1011
use oximeter_db::oxql::query::QueryAuthzScope;
@@ -13,6 +14,7 @@ use oximeter_test_utils::wait_for_keepers;
1314
use slog::{Logger, info};
1415
use std::collections::BTreeSet;
1516
use std::default::Default;
17+
use std::path::PathBuf;
1618
use std::time::Duration;
1719

1820
pub struct TestInput {
@@ -38,6 +40,42 @@ impl TestInput {
3840
}
3941
}
4042

43+
/// Ensure the oximeter database schemas for both single node and replicated
44+
/// cluster are not modified.
45+
///
46+
/// Schema changes for the `oximeter` database are currently disabled due to
47+
/// ongoing self-service update work. More information about this restriction
48+
/// can be found in https://github.com/oxidecomputer/omicron/issues/8862
49+
#[tokio::test]
50+
async fn test_schemas_are_not_modified() -> anyhow::Result<()> {
51+
let cur_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
52+
let single_node_schema_checksum =
53+
file_checksum(cur_dir.as_path().join("schema/single-node/db-init.sql"))
54+
.unwrap();
55+
let replicated_schema_1_checksum = file_checksum(
56+
cur_dir.as_path().join("schema/replicated/db-init-1.sql"),
57+
)
58+
.unwrap();
59+
let replicated_schema_2_checksum = file_checksum(
60+
cur_dir.as_path().join("schema/replicated/db-init-2.sql"),
61+
)
62+
.unwrap();
63+
64+
assert_eq!(
65+
"1422131e72b3410b7f4520bf72a213f0c3288ce8cd738a0010b1bf44edea480a",
66+
single_node_schema_checksum
67+
);
68+
assert_eq!(
69+
"038ca7fc66006d6c06243a6fa122cf2f0bfee6edf55227e13166a9b854169abb",
70+
replicated_schema_1_checksum
71+
);
72+
assert_eq!(
73+
"d78c49e5662a2bd211eba63cc71a33bffacca7c6a80d9090532329650c6baae0",
74+
replicated_schema_2_checksum
75+
);
76+
Ok(())
77+
}
78+
4179
/// Ensure `db-init-1.sql` and `db-init-2.sql` contain disjoint sets of tables.
4280
#[tokio::test]
4381
async fn test_schemas_disjoint() -> anyhow::Result<()> {

test-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ tokio-postgres.workspace = true
3636
usdt.workspace = true
3737
rcgen.workspace = true
3838
reqwest.workspace = true
39+
sha2.workspace = true
3940
walkdir.workspace = true
4041
omicron-workspace-hack.workspace = true
4142
uuid.workspace = true

test-utils/src/dev/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ use dropshot::ConfigLoggingIfExists;
2222
use dropshot::ConfigLoggingLevel;
2323
pub use dropshot::test_util::LogContext;
2424
use omicron_common::disk::DiskIdentity;
25+
use sha2::Digest;
26+
use sha2::Sha256;
2527
use slog::Logger;
2628
use std::io::BufReader;
29+
use std::io::Read;
30+
use std::path::PathBuf;
2731

2832
/// The environment variable via which the path to the seed tarball is passed.
2933
pub static CRDB_SEED_TAR_ENV: &str = "CRDB_SEED_TAR";
@@ -160,3 +164,20 @@ pub fn mock_disk_identity() -> DiskIdentity {
160164
model: "MOCKMODEL".to_string(),
161165
}
162166
}
167+
168+
/// Returns the sha2 checksum of a file at `path`.
169+
pub fn file_checksum(path: PathBuf) -> Result<String> {
170+
let mut digest = Sha256::new();
171+
let mut buf = vec![0; 1024];
172+
let mut file = std::fs::File::open(path)?;
173+
174+
loop {
175+
let n = file.read(&mut buf)?;
176+
if n == 0 {
177+
break;
178+
}
179+
digest.update(&buf[..n]);
180+
}
181+
182+
Ok(format!("{:x}", digest.finalize()))
183+
}

0 commit comments

Comments
 (0)