mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-04 10:42:23 +00:00
Containers without the Coolify default variables sent no project, environment, or service to the drain. The fluentd driver now also sends the Coolify container labels; the built-in configs use them as a fallback and add coolify.service_name. Closes #8415 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.2 KiB
PHP
86 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Server;
|
|
use App\Models\ServerSetting;
|
|
|
|
function serverWithLogDrainSettings(array $attributes): Server
|
|
{
|
|
$server = new Server;
|
|
$server->setRelation('settings', new ServerSetting($attributes));
|
|
|
|
return $server;
|
|
}
|
|
|
|
it('uses the fluentd driver when CloudWatch is not the active drain', function () {
|
|
$server = serverWithLogDrainSettings(['is_logdrain_axiom_enabled' => true]);
|
|
|
|
expect(generate_log_drain_configuration($server))->toBe(generate_fluentd_configuration());
|
|
});
|
|
|
|
it('uses the awslogs driver with every configured option', function () {
|
|
$server = serverWithLogDrainSettings([
|
|
'is_logdrain_cloudwatch_enabled' => true,
|
|
'logdrain_cloudwatch_region' => 'eu-west-1',
|
|
'logdrain_cloudwatch_group' => '/coolify/prod',
|
|
'logdrain_cloudwatch_stream_prefix' => 'docker/',
|
|
]);
|
|
|
|
expect(generate_log_drain_configuration($server))->toBe([
|
|
'driver' => 'awslogs',
|
|
'options' => [
|
|
'awslogs-region' => 'eu-west-1',
|
|
'awslogs-group' => '/coolify/prod',
|
|
'awslogs-create-group' => 'true',
|
|
'mode' => 'non-blocking',
|
|
'tag' => 'docker/{{.Name}}',
|
|
],
|
|
]);
|
|
});
|
|
|
|
it('names streams after the container when no prefix is set', function () {
|
|
$server = serverWithLogDrainSettings([
|
|
'is_logdrain_cloudwatch_enabled' => true,
|
|
'logdrain_cloudwatch_region' => 'us-east-1',
|
|
'logdrain_cloudwatch_group' => 'coolify',
|
|
]);
|
|
|
|
expect(generate_log_drain_configuration($server)['options']['tag'])->toBe('{{.Name}}');
|
|
});
|
|
|
|
it('does not fall back to a default region', function () {
|
|
$server = serverWithLogDrainSettings([
|
|
'is_logdrain_cloudwatch_enabled' => true,
|
|
'logdrain_cloudwatch_group' => 'coolify',
|
|
]);
|
|
|
|
expect(generate_log_drain_configuration($server)['options'])->not->toHaveKey('awslogs-region');
|
|
});
|
|
|
|
it('never sets awslogs-stream because it would override the container-name tag', function () {
|
|
$server = serverWithLogDrainSettings([
|
|
'is_logdrain_cloudwatch_enabled' => true,
|
|
'logdrain_cloudwatch_group' => 'coolify',
|
|
'logdrain_cloudwatch_stream_prefix' => 'apps/',
|
|
]);
|
|
|
|
expect(generate_log_drain_configuration($server)['options'])->not->toHaveKey('awslogs-stream');
|
|
});
|
|
|
|
it('reports CloudWatch as an enabled drain that does not use Fluent Bit', function () {
|
|
$cloudwatch = serverWithLogDrainSettings(['is_logdrain_cloudwatch_enabled' => true]);
|
|
$axiom = serverWithLogDrainSettings(['is_logdrain_axiom_enabled' => true]);
|
|
|
|
expect($cloudwatch->isLogDrainEnabled())->toBeTrue()
|
|
->and($cloudwatch->isFluentBitLogDrainEnabled())->toBeFalse()
|
|
->and($axiom->isLogDrainEnabled())->toBeTrue()
|
|
->and($axiom->isFluentBitLogDrainEnabled())->toBeTrue();
|
|
});
|
|
|
|
it('sends the Coolify labels with fluentd, so containers without the default variables are identified', function () {
|
|
$server = serverWithLogDrainSettings(['is_logdrain_custom_enabled' => true]);
|
|
|
|
expect(generate_log_drain_configuration($server)['options'])
|
|
->toHaveKey('env', 'COOLIFY_APP_NAME,COOLIFY_PROJECT_NAME,COOLIFY_SERVER_IP,COOLIFY_ENVIRONMENT_NAME')
|
|
->toHaveKey('labels', 'coolify.projectName,coolify.environmentName,coolify.resourceName,coolify.serviceName');
|
|
});
|