You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.8 KiB
PHP
90 lines
3.8 KiB
PHP
<?php
|
|
|
|
// The clean-break Agent build owns a fresh log schema; no Python schema or
|
|
// upgrade DDL is consulted by the panel.
|
|
$sql = file_get_contents(dirname(__DIR__) . '/sql/cloud_log.sql');
|
|
if (!is_string($sql)) {
|
|
throw new RuntimeException('Cloud log schema is unreadable');
|
|
}
|
|
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
foreach ([
|
|
'cloud_vm_metric_samples' => [
|
|
'instance_id BIGINT UNSIGNED', 'user_id BIGINT UNSIGNED',
|
|
'PRIMARY KEY (instance_id, sampled_at)',
|
|
'network_rx_bytes BIGINT UNSIGNED',
|
|
'network_tx_bytes BIGINT UNSIGNED',
|
|
'vm_metric_owner (user_id, sampled_at, instance_id)',
|
|
],
|
|
'cloud_vm_metric_rollups' => [
|
|
'instance_id BIGINT UNSIGNED', 'interval_seconds SMALLINT UNSIGNED',
|
|
'bucket_start BIGINT UNSIGNED', 'sample_count SMALLINT UNSIGNED',
|
|
'cpu_percent_sum DOUBLE', 'cpu_percent_count SMALLINT UNSIGNED',
|
|
'vm_metric_rollup_retention', 'chk_vm_metric_rollup_bucket',
|
|
'chk_vm_metric_rollup_counts',
|
|
],
|
|
'cloud_vm_traffic_totals' => [
|
|
'host_id BIGINT UNSIGNED', 'vm_uuid BINARY(16)',
|
|
'network_signature BINARY(32)', 'network_baseline_json JSON',
|
|
'download_rx_bytes BIGINT UNSIGNED', 'upload_tx_bytes BIGINT UNSIGNED',
|
|
'PRIMARY KEY (host_id, vm_uuid)',
|
|
'vm_traffic_uuid (vm_uuid, host_id)',
|
|
'vm_traffic_owner (user_id, host_id)',
|
|
],
|
|
'cloud_vm_traffic_checkpoints' => [
|
|
'host_id BIGINT UNSIGNED', 'vm_uuid BINARY(16)',
|
|
'checkpoint_hour BIGINT UNSIGNED', 'first_observed_at BIGINT UNSIGNED',
|
|
'PRIMARY KEY (host_id, vm_uuid, checkpoint_hour)',
|
|
'vm_traffic_checkpoint_owner (user_id, host_id, first_observed_at)',
|
|
],
|
|
'cloud_vm_daily_traffic_cursors' => [
|
|
'instance_id BIGINT UNSIGNED', 'user_id BIGINT UNSIGNED',
|
|
'last_observed_at BIGINT UNSIGNED',
|
|
'download_total_bytes BIGINT UNSIGNED',
|
|
'upload_total_bytes BIGINT UNSIGNED',
|
|
'cloud_daily_traffic_cursor_owner (user_id, updated_at)',
|
|
],
|
|
'cloud_vm_daily_traffic' => [
|
|
'instance_id BIGINT UNSIGNED', 'user_id BIGINT UNSIGNED',
|
|
'day_start BIGINT UNSIGNED', 'download_bytes BIGINT UNSIGNED',
|
|
'upload_bytes BIGINT UNSIGNED', 'sample_count INT UNSIGNED',
|
|
'cloud_daily_traffic_retention (day_start)',
|
|
'cloud_daily_traffic_owner (user_id, day_start)',
|
|
],
|
|
] as $table => $required) {
|
|
$assert(preg_match('/CREATE TABLE ' . preg_quote($table, '/')
|
|
. '\s*\((.*?)\) ENGINE=/s', $sql, $match) === 1,
|
|
'Missing fresh log table: ' . $table);
|
|
foreach ($required as $fragment) {
|
|
$assert(str_contains($match[1], $fragment),
|
|
$table . ' is missing: ' . $fragment);
|
|
}
|
|
}
|
|
|
|
foreach (['cloud_vm_metric_samples', 'cloud_vm_metric_rollups'] as $table) {
|
|
preg_match('/CREATE TABLE ' . preg_quote($table, '/')
|
|
. '\s*\((.*?)\) ENGINE=/s', $sql, $match);
|
|
$assert(!str_contains($match[1], 'host_scope')
|
|
&& !str_contains($match[1], 'vm_uuid')
|
|
&& !str_contains($match[1], 'host_id'),
|
|
$table . ' retained per-row placement text in logical history.');
|
|
}
|
|
$assert(!str_contains($sql, 'vm_metric_instance')
|
|
&& !str_contains($sql, 'vm_metric_rollup_identity')
|
|
&& !str_contains($sql, 'vm_traffic_host')
|
|
&& !str_contains($sql, 'cloud_network_observation_placement')
|
|
&& !str_contains($sql, 'cloud_network_observation_host'),
|
|
'Fresh log schema retained redundant high-frequency indexes.');
|
|
|
|
$assert(preg_match('/\b(?:ALTER|DROP)\s+TABLE\b/i', $sql) !== 1,
|
|
'Fresh cloud log schema contains migration/destructive DDL.');
|
|
$assert(!str_contains($sql, 'engine_vm_'),
|
|
'Fresh cloud log schema retained an engine-prefixed table.');
|
|
|
|
echo "Fresh-install Agent metric and traffic DDL contract passed.\n";
|