Skip to content

Commit dc7a3fc

Browse files
[cross-repo from server#288] Conformance finding: replay workflow remains waiting on current artifacts (#610)
1 parent 6a4202e commit dc7a3fc

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/V2/Support/StandaloneWorkerVisibility.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,25 @@ private static function processMetrics(mixed $value): ?array
224224
return null;
225225
}
226226

227-
$allowed = ['cpu_percent', 'memory_bytes', 'process_uptime_seconds', 'process_id', 'host'];
227+
$allowed = [
228+
'cpu_percent',
229+
'memory_bytes',
230+
'process_uptime_seconds',
231+
'process_id',
232+
'host',
233+
'process_started_at',
234+
];
228235
$clean = [];
229236

230237
foreach ($allowed as $key) {
231238
if (! array_key_exists($key, $value) || $value[$key] === null) {
232239
continue;
233240
}
234241

235-
if ($key === 'host' && is_string($value[$key]) && trim($value[$key]) !== '') {
242+
if (($key === 'host' || $key === 'process_started_at')
243+
&& is_string($value[$key])
244+
&& trim($value[$key]) !== ''
245+
) {
236246
$clean[$key] = mb_substr(trim($value[$key]), 0, 255);
237247

238248
continue;

src/V2/Support/WorkerHeartbeatTelemetry.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ public static function taskSlots(
6666
* runtime APIs that PHP exposes everywhere (no extension required).
6767
*
6868
* The optional `$startedAt` argument is a Unix timestamp captured at
69-
* worker boot; it is used to derive `process_uptime_seconds` and to
70-
* anchor the wall-clock denominator for `cpu_percent` so long-running
71-
* workers see the lifetime average rather than a value inflated by
72-
* the first telemetry call. When `$startedAt` is null the uptime
73-
* entry is omitted and `cpu_percent` falls back to a denominator
69+
* worker boot; it is used to derive `process_uptime_seconds`, report
70+
* the stable `process_started_at` identity field, and anchor the
71+
* wall-clock denominator for `cpu_percent` so long-running workers see
72+
* the lifetime average rather than a value inflated by the first
73+
* telemetry call. When `$startedAt` is null the uptime and process-start
74+
* entries are omitted and `cpu_percent` falls back to a denominator
7475
* cached on the first call.
7576
*
7677
* @return array<string, float|int|string>
@@ -89,6 +90,7 @@ public static function processMetrics(?int $startedAt = null): array
8990

9091
if ($startedAt !== null) {
9192
$metrics['process_uptime_seconds'] = max(0, time() - $startedAt);
93+
$metrics['process_started_at'] = gmdate('Y-m-d\TH:i:s\Z', $startedAt);
9294
}
9395

9496
$host = self::host();

tests/Unit/V2/WorkerHeartbeatTelemetryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ public function test_task_slots_omits_keys_when_inputs_are_unknown(): void
4747

4848
public function test_process_metrics_include_memory_pid_and_optional_uptime(): void
4949
{
50-
$metrics = WorkerHeartbeatTelemetry::processMetrics(startedAt: time() - 30);
50+
$startedAt = time() - 30;
51+
$metrics = WorkerHeartbeatTelemetry::processMetrics(startedAt: $startedAt);
5152

5253
self::assertArrayHasKey('memory_bytes', $metrics);
5354
self::assertArrayHasKey('process_id', $metrics);
5455
self::assertGreaterThan(0, $metrics['memory_bytes']);
5556
self::assertGreaterThan(0, $metrics['process_id']);
5657

5758
self::assertArrayHasKey('process_uptime_seconds', $metrics);
59+
self::assertSame(gmdate('Y-m-d\TH:i:s\Z', $startedAt), $metrics['process_started_at']);
5860
self::assertGreaterThanOrEqual(0, $metrics['process_uptime_seconds']);
5961
self::assertLessThan(120, $metrics['process_uptime_seconds']);
6062
}
@@ -64,6 +66,7 @@ public function test_process_metrics_omit_uptime_when_started_at_is_null(): void
6466
$metrics = WorkerHeartbeatTelemetry::processMetrics();
6567

6668
self::assertArrayNotHasKey('process_uptime_seconds', $metrics);
69+
self::assertArrayNotHasKey('process_started_at', $metrics);
6770
}
6871

6972
public function test_process_metrics_cpu_percent_uses_started_at_for_long_running_workers(): void

0 commit comments

Comments
 (0)