|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
|
|
$python = file_get_contents(dirname($root) . '/engine/virsh_panel/database.py');
|
|
|
|
|
if (preg_match('/_METRIC_SCHEMA\s*=\s*"""(.*?)"""/s', $python, $match) !== 1) {
|
|
|
|
|
throw new RuntimeException('Engine metric schema missing');
|
|
|
|
|
}
|
|
|
|
|
if (preg_match('/_TRAFFIC_SCHEMA\s*=\s*"""(.*?)"""/s', $python, $trafficMatch) !== 1) {
|
|
|
|
|
throw new RuntimeException('Engine traffic schema missing');
|
|
|
|
|
}
|
|
|
|
|
if (preg_match('/_TRAFFIC_CHECKPOINT_SCHEMA\s*=\s*"""(.*?)"""/s', $python, $checkpointMatch) !== 1) {
|
|
|
|
|
throw new RuntimeException('Engine traffic checkpoint schema missing');
|
|
|
|
|
}
|
|
|
|
|
$sql = file_get_contents($root . '/sql/cloud_log.sql');
|
|
|
|
|
$normalize = static function ($value): string {
|
|
|
|
|
$value = preg_replace('/^\s*--[^\n]*$/m', '', $value);
|
|
|
|
|
return rtrim(trim(preg_replace('/\s+/', ' ', $value)), ';');
|
|
|
|
|
};
|
|
|
|
|
$metric = $normalize(str_replace('vm_metric_samples', 'engine_vm_metric_samples', $match[1]));
|
|
|
|
|
$traffic = $normalize(str_replace('vm_traffic_totals', 'engine_vm_traffic_totals', $trafficMatch[1]));
|
|
|
|
|
$checkpoint = $normalize(str_replace('vm_traffic_checkpoints', 'engine_vm_traffic_checkpoints', $checkpointMatch[1]));
|
|
|
|
|
$actual = $normalize($sql);
|
|
|
|
|
if (!str_contains($actual, $metric) || !str_contains($actual, $traffic)
|
|
|
|
|
|| !str_contains($actual, $checkpoint)) {
|
|
|
|
|
throw new RuntimeException('Fresh-install metric/traffic/checkpoint SQL differs from engine-owned schemas');
|
|
|
|
|
}
|
|
|
|
|
foreach ([
|
|
|
|
|
'host_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NULL AFTER vm_uuid',
|
|
|
|
|
'user_id BIGINT UNSIGNED NULL AFTER host_id',
|
|
|
|
|
'network_rx_bytes BIGINT UNSIGNED NULL AFTER network_tx_bps',
|
|
|
|
|
'network_tx_bytes BIGINT UNSIGNED NULL AFTER network_rx_bytes',
|
|
|
|
|
'vm_metric_owner (user_id, host_id, sampled_at)',
|
|
|
|
|
] as $migration) {
|
|
|
|
|
if (!str_contains($actual, $migration)) {
|
|
|
|
|
throw new RuntimeException('Log schema is missing an idempotent metric migration');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!str_contains($sql, 'CREATE TABLE IF NOT EXISTS engine_vm_metric_samples')) {
|
|
|
|
|
throw new RuntimeException('Metric initializer must execute DDL, not an empty/comment-only query');
|
|
|
|
|
}
|
|
|
|
|
echo "Fresh-install metric and traffic DDL matches the Python engine schemas.\n";
|