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.
83 lines
3.1 KiB
PHP
83 lines
3.1 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\Cloud\CloudTrafficCheckpointRetention;
|
|
use App\Services\Cloud\CloudTrafficSettlementRetention;
|
|
use App\Services\Cloud\CloudTrafficStorageHealthService;
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
$capsule = new Capsule();
|
|
$capsule->addConnection([
|
|
'driver' => 'sqlite', 'database' => ':memory:',
|
|
], 'default');
|
|
$capsule->addConnection([
|
|
'driver' => 'sqlite', 'database' => ':memory:',
|
|
], 'log');
|
|
$capsule->setAsGlobal();
|
|
$capsule->bootEloquent();
|
|
|
|
$main = $capsule->schema('default');
|
|
$main->create('cloud_traffic_usage_settlement_buckets',
|
|
static function (Blueprint $table): void {
|
|
$table->increments('id');
|
|
$table->string('state');
|
|
$table->integer('updated_at');
|
|
});
|
|
$main->create('cloud_traffic_instance_cursors',
|
|
static function (Blueprint $table): void {
|
|
$table->integer('instance_id')->primary();
|
|
$table->string('state');
|
|
});
|
|
$capsule->schema('log')->create('cloud_vm_traffic_checkpoints',
|
|
static function (Blueprint $table): void {
|
|
$table->integer('instance_id');
|
|
$table->integer('first_observed_at');
|
|
});
|
|
|
|
$now = 20 * 86400;
|
|
$healthy = CloudTrafficStorageHealthService::snapshot($now);
|
|
$assert($healthy['status'] === 'ok'
|
|
&& $healthy['metrics']['settlement_buckets_due'] === 0
|
|
&& $healthy['metrics']['hourly_checkpoints_due'] === 0
|
|
&& $healthy['metrics']['cursor_attention_instances'] === 0,
|
|
'Empty compaction queues did not report a healthy bounded state.');
|
|
|
|
$settlementCutoff = $now
|
|
- CloudTrafficSettlementRetention::RETENTION_SECONDS;
|
|
$checkpointCutoff = $now
|
|
- CloudTrafficCheckpointRetention::RETENTION_SECONDS;
|
|
$capsule->connection('default')
|
|
->table('cloud_traffic_usage_settlement_buckets')->insert([
|
|
['state' => 'sealed', 'updated_at' => $settlementCutoff - 7200],
|
|
['state' => 'open', 'updated_at' => $settlementCutoff - 86400],
|
|
]);
|
|
$capsule->connection('log')->table('cloud_vm_traffic_checkpoints')->insert([
|
|
['instance_id' => 3, 'first_observed_at' => $checkpointCutoff - 7200],
|
|
['instance_id' => 4, 'first_observed_at' => $checkpointCutoff + 60],
|
|
]);
|
|
$capsule->connection('default')->table(
|
|
'cloud_traffic_instance_cursors'
|
|
)->insert([
|
|
'instance_id' => 3,
|
|
'state' => 'attention',
|
|
]);
|
|
$warning = CloudTrafficStorageHealthService::snapshot($now);
|
|
$assert($warning['status'] === 'warning'
|
|
&& $warning['metrics']['settlement_buckets_due'] === 1
|
|
&& $warning['metrics']['hourly_checkpoints_due'] === 1
|
|
&& $warning['metrics']['hourly_checkpoint_instances_due'] === 1
|
|
&& $warning['metrics']['cursor_attention_instances'] === 1
|
|
&& $warning['metrics']['oldest_due_lag_seconds'] === 7200
|
|
&& str_contains($warning['message'], '结算桶 1 个')
|
|
&& str_contains($warning['message'], '小时检查点 1 行'),
|
|
'Compaction backlog or attention state was hidden from operator health.');
|
|
|
|
echo "Traffic storage health summary contracts passed.\n";
|