- Dịch vụ custom: bảng custom_products + services.custom_product_id; createService nhận
custom{} thay product_id, giá = đơn giá tháng x số tháng chu kỳ (1/3/6/12/24/36),
gia hạn tính theo cùng đơn giá, ServiceClientDetailResource trả custom_product và specs.
- Giám sát VM: GET v1/system/vm-metrics/history gom lịch sử về tối đa 240 điểm;
lỗi lấy dung lượng đĩa không còn làm hỏng cả thẻ metrics.
- SealResponse: AES-256-GCM theo khoá phiên do proxy Next cấp qua header x-seal-key
(HMAC của session id). Client opt-in bằng x-seal; chi tiết dịch vụ, mật khẩu VM và
console ticket luôn được mã hoá. Body gửi lên dạng {enc} được giải mã trước validate;
khoá lệch trả 428 để client lấy khoá mới. Đây là che mắt DevTools, không phải bảo mật
chống chính chủ tài khoản.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Services\VmMetricsService;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class VmMetricsHistoryTest extends TestCase
|
|
{
|
|
public function test_history_is_bucketed_and_averaged(): void
|
|
{
|
|
config(['portal-monitor.url' => 'http://monitor', 'portal-monitor.api_key' => 'k']);
|
|
Http::fake(['monitor/*' => Http::response(['data' => [
|
|
['timestamp' => '2026-10-27T00:00:10Z', 'cpu_usage_percent' => 10, 'guest_memory_usage_percent' => 40],
|
|
['timestamp' => '2026-10-27T00:00:20Z', 'cpu_usage_percent' => 30, 'guest_memory_usage_percent' => null],
|
|
['timestamp' => '2026-10-27T00:30:00Z', 'cpu_usage_percent' => 50],
|
|
]])]);
|
|
|
|
$points = app(VmMetricsService::class)->history(
|
|
'vm-1',
|
|
new \DateTimeImmutable('2026-10-27T00:00:00Z'),
|
|
new \DateTimeImmutable('2026-10-27T01:00:00Z'),
|
|
maxPoints: 4,
|
|
);
|
|
|
|
$this->assertCount(2, $points);
|
|
$this->assertSame(20.0, $points[0]['cpu']);
|
|
$this->assertSame(40.0, $points[0]['mem']);
|
|
$this->assertNull($points[1]['mem']);
|
|
}
|
|
}
|