mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
add data retention to the metrics
This commit is contained in:
@ -35,6 +35,29 @@ public function test_cannot_visit_metrics(): void
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->get(route('servers.metrics', ['server' => $this->server]))
|
||||
->assertRedirect(route('servers.services', ['server' => $this->server]));
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_update_data_retention(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Service::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'name' => 'vito-agent',
|
||||
'type' => 'monitoring',
|
||||
'version' => 'latest',
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
$this->post(route('servers.metrics.settings', ['server' => $this->server]), [
|
||||
'data_retention' => 30,
|
||||
])->assertSessionHas('toast.type', 'success');
|
||||
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => $this->server->id,
|
||||
'type' => 'monitoring',
|
||||
'type_data->data_retention' => 30,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
49
tests/Unit/Commands/DeleteOlderMetricsCommandTest.php
Normal file
49
tests/Unit/Commands/DeleteOlderMetricsCommandTest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Commands;
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Models\Metric;
|
||||
use App\Models\Service;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteOlderMetricsCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_delete_older_metrics(): void
|
||||
{
|
||||
$monitoring = Service::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'name' => 'vito-agent',
|
||||
'type' => 'monitoring',
|
||||
'type_data' => [
|
||||
'data_retention' => 1,
|
||||
],
|
||||
'version' => 'latest',
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
$range = CarbonPeriod::create(Carbon::now()->subDays(10), '1 hour', Carbon::now()->subDays(8));
|
||||
foreach ($range as $date) {
|
||||
Metric::factory()->create([
|
||||
'server_id' => $monitoring->server_id,
|
||||
'created_at' => $date,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->assertDatabaseHas('metrics', [
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
$this->artisan('metrics:delete-older-metrics')
|
||||
->expectsOutput('Metrics deleted');
|
||||
|
||||
$this->assertDatabaseMissing('metrics', [
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user