mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 21:18:11 -04:00
perf(metrics): ask Sentinel to bucket metric history rows
Send bucket_ms on the Sentinel metric history reads so Sentinel averages the rows and sends far fewer of them over SSH. Older Sentinels ignore the param and return raw rows, which Coolify still buckets and downsamples. Also quote the history URL in the single-fetch curl command, because the URL now has an & in it.
This commit is contained in:
committed by
Andras Bacsai
parent
1d286427ad
commit
5312ea4dbc
@@ -13,10 +13,17 @@ class MetricsMappingDouble
|
||||
/** @var array<string, ?array> type => rows */
|
||||
public array $rowsByType = [];
|
||||
|
||||
public string $uuid = 'app-uuid';
|
||||
|
||||
protected function fetchMetricRows(string $type, int $mins): ?array
|
||||
{
|
||||
return $this->rowsByType[$type] ?? null;
|
||||
}
|
||||
|
||||
public function endpoint(string $type, int $mins): string
|
||||
{
|
||||
return $this->getMetricsEndpoint($type, '2026-01-01T00:00:00Z', $mins);
|
||||
}
|
||||
}
|
||||
|
||||
it('keeps only the root mount for disk metrics', function () {
|
||||
@@ -73,3 +80,12 @@ it('supports older disk rows without a mount field', function () {
|
||||
|
||||
expect($double->getDiskMetrics(5))->toBe([[1000, 40.0]]);
|
||||
});
|
||||
|
||||
it('asks sentinel to bucket ranges over an hour into at most 1000 whole-minute rows', function () {
|
||||
$double = new MetricsMappingDouble;
|
||||
|
||||
expect($double->endpoint('cpu', 60))->not->toContain('bucket_ms')
|
||||
->and($double->endpoint('cpu', 720))->toBe('http://localhost:8888/api/container/app-uuid/cpu/history?from=2026-01-01T00:00:00Z&bucket_ms=60000')
|
||||
->and($double->endpoint('cpu', 10080))->toEndWith('&bucket_ms=660000')
|
||||
->and($double->endpoint('cpu', 43200))->toEndWith('&bucket_ms=2640000');
|
||||
});
|
||||
|
||||
@@ -12,8 +12,12 @@ class FakeMetricsClient extends SentinelMetricsClient
|
||||
/** @var array<int, string> */
|
||||
public array $failing = [];
|
||||
|
||||
/** @var array<int, string> */
|
||||
public array $urls = [];
|
||||
|
||||
protected function raw(string $url): string
|
||||
{
|
||||
$this->urls[] = $url;
|
||||
foreach ($this->failing as $needle) {
|
||||
if (str_contains($url, $needle)) {
|
||||
throw new RuntimeException('boom');
|
||||
@@ -247,3 +251,16 @@ it('prefers the root mount over the host mount of the Coolify data directory', f
|
||||
|
||||
expect($client->history('disk', '24h'))->toBe([[1699999800000, 60.0]]);
|
||||
});
|
||||
|
||||
it('asks sentinel to bucket history rows by range', function (string $range, int $bucketMs) {
|
||||
$client = fakeMetricsClient();
|
||||
|
||||
$client->history('memory', $range);
|
||||
$client->networkHistory($range);
|
||||
|
||||
expect($client->urls)->each->toContain("bucket_ms={$bucketMs}");
|
||||
})->with([
|
||||
['24h', 300_000],
|
||||
['7d', 1_800_000],
|
||||
['30d', 7_200_000],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user