fix(log-drain): replace server name whitespace with hyphens (#12239)

This commit is contained in:
Andras Bacsai
2026-10-20 11:29:11 +02:00
committed by GitHub
parent 57faba1b96
commit 5925c8403a
2 changed files with 31 additions and 3 deletions
+3 -2
View File
@@ -221,11 +221,12 @@ Files:
}
/**
* Fluent Bit reads its config line by line, so a value with a line break could add sections.
* Fluent Bit reads its config line by line, so a value with a line break could add sections,
* and the modify filter splits `Set` on spaces, so the value must be a single token.
*/
private function fluentBitValue(string $value): string
{
return trim(preg_replace('/\s*[\x00-\x1F\x7F]+\s*/', ' ', $value));
return preg_replace('/[\s\x00-\x1F\x7F]+/', '-', trim($value));
}
private function logDrainNetworkConnectCommands(Server $server): array
@@ -41,10 +41,37 @@ test('a server name with a line break cannot add a section to the fluent-bit con
preg_match("/echo '([A-Za-z0-9+\\/=]+)' \\| base64 -d \\| tee \\S+\\/fluent-bit\\.conf/", $commands->implode("\n"), $matches);
$config = base64_decode($matches[1]);
expect($config)->toContain("Set coolify.server_name prod [OUTPUT] Name stdout Match *\n")
expect($config)->toContain("Set coolify.server_name prod-[OUTPUT]-Name-stdout-Match-*\n")
->and(preg_match_all('/^\[OUTPUT\]/m', $config))->toBe(1)
->and($config)->not->toMatch('/^\s*Name stdout/m');
})->with([
'new relic' => [['is_logdrain_newrelic_enabled' => true, 'logdrain_newrelic_license_key' => 'key', 'logdrain_newrelic_base_uri' => 'https://log-api.newrelic.com/log/v1']],
'axiom' => [['is_logdrain_axiom_enabled' => true, 'logdrain_axiom_dataset_name' => 'dataset', 'logdrain_axiom_api_key' => 'key']],
]);
test('a server name with spaces is written as a single fluent-bit value', function (array $settings) {
$team = Team::factory()->create();
$server = Server::factory()->create([
'team_id' => $team->id,
'name' => 'Test Server #1',
'private_key_id' => PrivateKey::factory()->create(['team_id' => $team->id])->id,
]);
$server->settings()->update($settings);
$commands = new Collection;
Process::fake(function ($process) use ($commands) {
$commands->push($process->command);
return Process::result();
});
StartLogDrain::run($server->fresh());
preg_match("/echo '([A-Za-z0-9+\\/=]+)' \\| base64 -d \\| tee \\S+\\/fluent-bit\\.conf/", $commands->implode("\n"), $matches);
$config = base64_decode($matches[1]);
expect($config)->toContain("Set coolify.server_name Test-Server-#1\n");
})->with([
'new relic' => [['is_logdrain_newrelic_enabled' => true, 'logdrain_newrelic_license_key' => 'key', 'logdrain_newrelic_base_uri' => 'https://log-api.newrelic.com/log/v1']],
'axiom' => [['is_logdrain_axiom_enabled' => true, 'logdrain_axiom_dataset_name' => 'dataset', 'logdrain_axiom_api_key' => 'key']],
]);