docs: measure where function logs go in CockpitUnverified
The probe gains a stderr mode writing a multi-line exception and a long line, the way the runtime logs its failures. The README documents how to read the logs from Grafana and from the Loki API with a read-only token.
fd5aef9 parent: 7ee023b modified
README.md +36 -5 | @@ -21,6 +21,7 @@ Vocabulary (Invocation, Event, Warm Process...) is defined in [GLOSSARY.md](GLOS | ||
| 21 | 21 | - [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations) |
| 22 | 22 | - [Packaging](#packaging) |
| 23 | 23 | - [Deployment](#deployment) |
| 24 | +- [Logs](#logs) | |
| 24 | 25 | - [Local development with the Emulator](#local-development-with-the-emulator) |
| 25 | 26 | - [Warm Processes](#warm-processes) |
| 26 | 27 | - [Limitations and platform caveats](#limitations-and-platform-caveats) |
| @@ -155,7 +156,7 @@ Logs written to files are lost with the instance: send them to `php://stderr` in | ||
| 155 | 156 | |
| 156 | 157 | ### Errors |
| 157 | 158 | |
| 158 | -An exception escaping the Application (a Kernel failing to boot, an unsupported Front Controller...) is logged to stderr and answered with a 500. | |
| 159 | +An exception escaping the Application (a Kernel failing to boot, an unsupported Front Controller...) is logged to stderr ([Logs](#logs)) and answered with a 500. | |
| 159 | 160 | Its body is `Internal Server Error`, or the full exception when `APP_DEBUG` is true. |
| 160 | 161 | A Kernel that failed to boot is built again from scratch on the next Invocation. |
| 161 | 162 | |
| @@ -377,6 +378,39 @@ That Terraform code was written against the `scaleway/scaleway` provider v2.92 d | ||
| 377 | 378 | Redeploy by running `scaleway-package` again, then `terraform apply`. |
| 378 | 379 | Replacing a function, for instance to change its `runtime`, deletes its CRON triggers on Scaleway's side: give them a `lifecycle { replace_triggered_by = [scaleway_function.<name>.id] }`, as the example does, so the same apply recreates them. |
| 379 | 380 | |
| 381 | +## Logs | |
| 382 | + | |
| 383 | +Scaleway sends what the function writes to stdout and stderr to [Cockpit](https://www.scaleway.com/en/docs/cockpit/), in the project's `Scaleway Logs` data source, about 2 seconds after it is written. | |
| 384 | +The runtime logs its own failures to stderr, as Monolog does with a `php://stderr` handler. | |
| 385 | +Each line is one log entry: a stack trace spans one entry per line, and a line over 16 KiB is split into 16 KiB entries and cut after 64 KiB. | |
| 386 | +Every entry has the `debug` level, stderr ones included: filter on the `stream` field instead. | |
| 387 | +An entry looks like this, with the `resource_id` label holding the function's UUID: | |
| 388 | + | |
| 389 | +```json | |
| 390 | +{"message":"DEBUG - Invocation failed: RuntimeException: ... in /home/app/function/src/Kernel.php:12 source=user stream=stderr","stream":"stderr","resource_instance":"<namespace>-<function>-00001-deployment-<id>"} | |
| 391 | +``` | |
| 392 | + | |
| 393 | +In the console, open Cockpit's Grafana (`scw cockpit grafana get` prints its URL) and the `Serverless Functions Logs` dashboard, or Explore with the `Scaleway Logs` data source. | |
| 394 | + | |
| 395 | +From the command line, query Loki's HTTP API with a token that can only read logs: | |
| 396 | + | |
| 397 | +```sh | |
| 398 | +LOKI_URL=$(scw cockpit data-source list origin=scaleway types.0=logs -o json | jq -r '.[0].url') | |
| 399 | +FUNCTION_ID=$(scw function function list name=<function name> -o json | jq -r '.[0].id') | |
| 400 | +# The secret key is only shown at creation. | |
| 401 | +scw cockpit token create name=read-logs token-scopes.0=read_only_logs -o json > token.json | |
| 402 | +LOKI_TOKEN=$(jq -r .secret_key token.json) | |
| 403 | + | |
| 404 | +curl -sS -G "$LOKI_URL/loki/api/v1/query_range" -H "Authorization: Bearer $LOKI_TOKEN" \ | |
| 405 | + --data-urlencode "query={resource_id=\"$FUNCTION_ID\"} | json | stream=\"stderr\" | line_format \"{{.message}}\"" \ | |
| 406 | + --data-urlencode since=1h --data-urlencode limit=1000 \ | |
| 407 | + | jq -r '[.data.result[].values[]] | sort_by(.[0]) | .[][1]' | |
| 408 | + | |
| 409 | +scw cockpit token delete token-id=$(jq -r .id token.json) && rm token.json | |
| 410 | +``` | |
| 411 | + | |
| 412 | +Without the `stream="stderr"` filter, the query also returns stdout and the platform's own lines (`Function Triggered: /`, `Function is now ready to serve requests!`). | |
| 413 | + | |
| 380 | 414 | ## Local development with the Emulator |
| 381 | 415 | |
| 382 | 416 | ```sh |
| @@ -493,10 +527,7 @@ Without the `pcntl` extension, stopping the Emulator with `kill` may leave its P | ||
| 493 | 527 | |
| 494 | 528 | ### Not measured |
| 495 | 529 | |
| 496 | -The [probe](probe) settled every platform fact the runtime relies on ([results](docs/probe-results.md)), except: | |
| 497 | - | |
| 498 | -- where stdout, stderr and uncaught exceptions are logged (Cockpit); | |
| 499 | -- whether a deployment whose Composer install or script fails serves the new code or keeps the previous version. | |
| 530 | +The [probe](probe) settled every platform fact the runtime relies on ([results](docs/probe-results.md)), except whether a deployment whose Composer install or script fails serves the new code or keeps the previous version. | |
| 500 | 531 | |
| 501 | 532 | ## Contributing |
| 502 | 533 | |
| @@ -21,6 +21,7 @@ Vocabulary (Invocation, Event, Warm Process...) is defined in [GLOSSARY.md](GLOS | |||
| 21 | - [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations) | 21 | - [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations) |
| 22 | - [Packaging](#packaging) | 22 | - [Packaging](#packaging) |
| 23 | - [Deployment](#deployment) | 23 | - [Deployment](#deployment) |
| 24 | +- [Logs](#logs) | ||
| 24 | - [Local development with the Emulator](#local-development-with-the-emulator) | 25 | - [Local development with the Emulator](#local-development-with-the-emulator) |
| 25 | - [Warm Processes](#warm-processes) | 26 | - [Warm Processes](#warm-processes) |
| 26 | - [Limitations and platform caveats](#limitations-and-platform-caveats) | 27 | - [Limitations and platform caveats](#limitations-and-platform-caveats) |
| @@ -155,7 +156,7 @@ Logs written to files are lost with the instance: send them to `php://stderr` in | |||
| 155 | 156 | ||
| 156 | ### Errors | 157 | ### Errors |
| 157 | 158 | ||
| 158 | -An exception escaping the Application (a Kernel failing to boot, an unsupported Front Controller...) is logged to stderr and answered with a 500. | 159 | +An exception escaping the Application (a Kernel failing to boot, an unsupported Front Controller...) is logged to stderr ([Logs](#logs)) and answered with a 500. |
| 159 | Its body is `Internal Server Error`, or the full exception when `APP_DEBUG` is true. | 160 | Its body is `Internal Server Error`, or the full exception when `APP_DEBUG` is true. |
| 160 | A Kernel that failed to boot is built again from scratch on the next Invocation. | 161 | A Kernel that failed to boot is built again from scratch on the next Invocation. |
| 161 | 162 | ||
| @@ -377,6 +378,39 @@ That Terraform code was written against the `scaleway/scaleway` provider v2.92 d | |||
| 377 | Redeploy by running `scaleway-package` again, then `terraform apply`. | 378 | Redeploy by running `scaleway-package` again, then `terraform apply`. |
| 378 | Replacing a function, for instance to change its `runtime`, deletes its CRON triggers on Scaleway's side: give them a `lifecycle { replace_triggered_by = [scaleway_function.<name>.id] }`, as the example does, so the same apply recreates them. | 379 | Replacing a function, for instance to change its `runtime`, deletes its CRON triggers on Scaleway's side: give them a `lifecycle { replace_triggered_by = [scaleway_function.<name>.id] }`, as the example does, so the same apply recreates them. |
| 379 | 380 | ||
| 381 | +## Logs | ||
| 382 | + | ||
| 383 | +Scaleway sends what the function writes to stdout and stderr to [Cockpit](https://www.scaleway.com/en/docs/cockpit/), in the project's `Scaleway Logs` data source, about 2 seconds after it is written. | ||
| 384 | +The runtime logs its own failures to stderr, as Monolog does with a `php://stderr` handler. | ||
| 385 | +Each line is one log entry: a stack trace spans one entry per line, and a line over 16 KiB is split into 16 KiB entries and cut after 64 KiB. | ||
| 386 | +Every entry has the `debug` level, stderr ones included: filter on the `stream` field instead. | ||
| 387 | +An entry looks like this, with the `resource_id` label holding the function's UUID: | ||
| 388 | + | ||
| 389 | +```json | ||
| 390 | +{"message":"DEBUG - Invocation failed: RuntimeException: ... in /home/app/function/src/Kernel.php:12 source=user stream=stderr","stream":"stderr","resource_instance":"<namespace>-<function>-00001-deployment-<id>"} | ||
| 391 | +``` | ||
| 392 | + | ||
| 393 | +In the console, open Cockpit's Grafana (`scw cockpit grafana get` prints its URL) and the `Serverless Functions Logs` dashboard, or Explore with the `Scaleway Logs` data source. | ||
| 394 | + | ||
| 395 | +From the command line, query Loki's HTTP API with a token that can only read logs: | ||
| 396 | + | ||
| 397 | +```sh | ||
| 398 | +LOKI_URL=$(scw cockpit data-source list origin=scaleway types.0=logs -o json | jq -r '.[0].url') | ||
| 399 | +FUNCTION_ID=$(scw function function list name=<function name> -o json | jq -r '.[0].id') | ||
| 400 | +# The secret key is only shown at creation. | ||
| 401 | +scw cockpit token create name=read-logs token-scopes.0=read_only_logs -o json > token.json | ||
| 402 | +LOKI_TOKEN=$(jq -r .secret_key token.json) | ||
| 403 | + | ||
| 404 | +curl -sS -G "$LOKI_URL/loki/api/v1/query_range" -H "Authorization: Bearer $LOKI_TOKEN" \ | ||
| 405 | + --data-urlencode "query={resource_id=\"$FUNCTION_ID\"} | json | stream=\"stderr\" | line_format \"{{.message}}\"" \ | ||
| 406 | + --data-urlencode since=1h --data-urlencode limit=1000 \ | ||
| 407 | + | jq -r '[.data.result[].values[]] | sort_by(.[0]) | .[][1]' | ||
| 408 | + | ||
| 409 | +scw cockpit token delete token-id=$(jq -r .id token.json) && rm token.json | ||
| 410 | +``` | ||
| 411 | + | ||
| 412 | +Without the `stream="stderr"` filter, the query also returns stdout and the platform's own lines (`Function Triggered: /`, `Function is now ready to serve requests!`). | ||
| 413 | + | ||
| 380 | ## Local development with the Emulator | 414 | ## Local development with the Emulator |
| 381 | 415 | ||
| 382 | ```sh | 416 | ```sh |
| @@ -493,10 +527,7 @@ Without the `pcntl` extension, stopping the Emulator with `kill` may leave its P | |||
| 493 | 527 | ||
| 494 | ### Not measured | 528 | ### Not measured |
| 495 | 529 | ||
| 496 | -The [probe](probe) settled every platform fact the runtime relies on ([results](docs/probe-results.md)), except: | 530 | +The [probe](probe) settled every platform fact the runtime relies on ([results](docs/probe-results.md)), except whether a deployment whose Composer install or script fails serves the new code or keeps the previous version. |
| 497 | - | ||
| 498 | -- where stdout, stderr and uncaught exceptions are logged (Cockpit); | ||
| 499 | -- whether a deployment whose Composer install or script fails serves the new code or keeps the previous version. | ||
| 500 | 531 | ||
| 501 | ## Contributing | 532 | ## Contributing |
| 502 | 533 | ||
modified
docs/plan.md +2 -1 | @@ -56,4 +56,5 @@ Done on 2026-11-14: the repository is on GitHub with CI green, the package is on | ||
| 56 | 56 | |
| 57 | 57 | 1. Verify a Command Invocation end to end on Scaleway: the e2e scenarios trigger CRON Invocations only through the Emulator, and the deployed one could only be observed in the logs. |
| 58 | 58 | 2. Run the example deployment with `host` set, to check absolute URLs. |
| 59 | -3. Measure what the probe left open: where logs go (Cockpit), and what a deployment with a failing Composer script serves. | |
| 59 | +3. Measure what the probe left open: what a deployment with a failing Composer script serves. | |
| 60 | + Where logs go was measured on 2026-11-14 ([probe results](probe-results.md#logs)): the runtime's stderr lines reach Cockpit unchanged, one entry per line. | |
| @@ -56,4 +56,5 @@ Done on 2026-11-14: the repository is on GitHub with CI green, the package is on | |||
| 56 | 56 | ||
| 57 | 1. Verify a Command Invocation end to end on Scaleway: the e2e scenarios trigger CRON Invocations only through the Emulator, and the deployed one could only be observed in the logs. | 57 | 1. Verify a Command Invocation end to end on Scaleway: the e2e scenarios trigger CRON Invocations only through the Emulator, and the deployed one could only be observed in the logs. |
| 58 | 2. Run the example deployment with `host` set, to check absolute URLs. | 58 | 2. Run the example deployment with `host` set, to check absolute URLs. |
| 59 | -3. Measure what the probe left open: where logs go (Cockpit), and what a deployment with a failing Composer script serves. | 59 | +3. Measure what the probe left open: what a deployment with a failing Composer script serves. |
| 60 | + Where logs go was measured on 2026-11-14 ([probe results](probe-results.md#logs)): the runtime's stderr lines reach Cockpit unchanged, one entry per line. | ||
modified
docs/probe-results.md +20 -1 | @@ -94,11 +94,30 @@ An `array`: `{"memoryLimitInMb": 256, "functionName": "probe-php85", "functionVe | ||
| 94 | 94 | - `HEAD` responses carry `Content-Length` and no body. |
| 95 | 95 | - The platform adds `Access-Control-Allow-Origin: *` and `Access-Control-Allow-Headers: Content-Type` to every response. |
| 96 | 96 | |
| 97 | +## Logs | |
| 98 | + | |
| 99 | +Measured with the Loki HTTP API of the project's `Scaleway Logs` data source (`scw cockpit data-source list origin=scaleway types.0=logs`), with a `read_only_logs` Cockpit token sent as `Authorization: Bearer`; requests without it get `401`. | |
| 100 | + | |
| 101 | +- stdout and stderr written by the handler both reach Cockpit, `echo` and `error_log()` alike, as does a `php://stderr` stream opened with `fopen()` like the runtime's. | |
| 102 | +- An entry is visible through the API 1.5 to 1.9 seconds after the Invocation (4 samples, polling every 0.5 to 1 second). | |
| 103 | +- Labels: `resource_type="serverless_function"`, `service_name="serverless_function"`, `resource_id` (the function's UUID), `resource_name` (`<namespace name and suffix>-<function name>`, e.g. `scalewayruntimeprobekzb5ehst-probe-php85`), `project_id`, `project_name`, `region`, and `detected_level`. | |
| 104 | +- Each entry is a JSON line; `stream` tells stdout from stderr, `resource_instance` the instance: | |
| 105 | + | |
| 106 | +```json | |
| 107 | +{"message":"DEBUG - probe: written to stdout by the handler source=user stream=stdout","stream":"stdout","resource_instance":"scalewayruntimeprobekzb5ehst-probe-php85-00001-deployment-h4658"} | |
| 108 | +{"message":"DEBUG - probe: exception escaping the handler source=user stream=stderr","stream":"stderr","resource_instance":"scalewayruntimeprobekzb5ehst-probe-php85-00001-deployment-h4658"} | |
| 109 | +``` | |
| 110 | + | |
| 111 | +- Everything the function writes is at the `DEBUG` level (`detected_level="debug"`), stderr included. | |
| 112 | +- The platform logs its own lines with `source=core`: `Function is not ready to serve requests yet...` every second while an instance starts, `Function is now ready to serve requests!`, `Function Triggered: /` before each Invocation, and `INFO - Forked function has terminated` when an instance stops. | |
| 113 | +- Each line is a separate entry: a stack trace written in one `fwrite()` gave 29 entries, one per line, with consecutive timestamps. | |
| 114 | +- A line over 16 KiB is split into entries of 16384 characters (counting the `DEBUG - ` prefix), and cut after 64 KiB: lines of 65536 and 300000 bytes both ended in 4 entries, the last one ending with `... (truncated, line too long)`; a 20000 byte line arrived complete, in 2 entries. | |
| 115 | +- An uncaught exception logs its message only, on stderr (`probe: exception escaping the handler` above), without its class, file, line or trace; the Warm Process survives it (same pid, the counter went on). | |
| 116 | + | |
| 97 | 117 | ## Terraform |
| 98 | 118 | |
| 99 | 119 | - Replacing a function (for example changing `runtime`) deletes its CRON triggers server side; Terraform recreates them only on the next apply. |
| 100 | 120 | |
| 101 | 121 | ## Not measured |
| 102 | 122 | |
| 103 | -- Cockpit logs (where stdout and uncaught exceptions are logged). | |
| 104 | 123 | - Whether a deployment with a failing Composer script serves the new code or keeps the previous version. |
| @@ -94,11 +94,30 @@ An `array`: `{"memoryLimitInMb": 256, "functionName": "probe-php85", "functionVe | |||
| 94 | - `HEAD` responses carry `Content-Length` and no body. | 94 | - `HEAD` responses carry `Content-Length` and no body. |
| 95 | - The platform adds `Access-Control-Allow-Origin: *` and `Access-Control-Allow-Headers: Content-Type` to every response. | 95 | - The platform adds `Access-Control-Allow-Origin: *` and `Access-Control-Allow-Headers: Content-Type` to every response. |
| 96 | 96 | ||
| 97 | +## Logs | ||
| 98 | + | ||
| 99 | +Measured with the Loki HTTP API of the project's `Scaleway Logs` data source (`scw cockpit data-source list origin=scaleway types.0=logs`), with a `read_only_logs` Cockpit token sent as `Authorization: Bearer`; requests without it get `401`. | ||
| 100 | + | ||
| 101 | +- stdout and stderr written by the handler both reach Cockpit, `echo` and `error_log()` alike, as does a `php://stderr` stream opened with `fopen()` like the runtime's. | ||
| 102 | +- An entry is visible through the API 1.5 to 1.9 seconds after the Invocation (4 samples, polling every 0.5 to 1 second). | ||
| 103 | +- Labels: `resource_type="serverless_function"`, `service_name="serverless_function"`, `resource_id` (the function's UUID), `resource_name` (`<namespace name and suffix>-<function name>`, e.g. `scalewayruntimeprobekzb5ehst-probe-php85`), `project_id`, `project_name`, `region`, and `detected_level`. | ||
| 104 | +- Each entry is a JSON line; `stream` tells stdout from stderr, `resource_instance` the instance: | ||
| 105 | + | ||
| 106 | +```json | ||
| 107 | +{"message":"DEBUG - probe: written to stdout by the handler source=user stream=stdout","stream":"stdout","resource_instance":"scalewayruntimeprobekzb5ehst-probe-php85-00001-deployment-h4658"} | ||
| 108 | +{"message":"DEBUG - probe: exception escaping the handler source=user stream=stderr","stream":"stderr","resource_instance":"scalewayruntimeprobekzb5ehst-probe-php85-00001-deployment-h4658"} | ||
| 109 | +``` | ||
| 110 | + | ||
| 111 | +- Everything the function writes is at the `DEBUG` level (`detected_level="debug"`), stderr included. | ||
| 112 | +- The platform logs its own lines with `source=core`: `Function is not ready to serve requests yet...` every second while an instance starts, `Function is now ready to serve requests!`, `Function Triggered: /` before each Invocation, and `INFO - Forked function has terminated` when an instance stops. | ||
| 113 | +- Each line is a separate entry: a stack trace written in one `fwrite()` gave 29 entries, one per line, with consecutive timestamps. | ||
| 114 | +- A line over 16 KiB is split into entries of 16384 characters (counting the `DEBUG - ` prefix), and cut after 64 KiB: lines of 65536 and 300000 bytes both ended in 4 entries, the last one ending with `... (truncated, line too long)`; a 20000 byte line arrived complete, in 2 entries. | ||
| 115 | +- An uncaught exception logs its message only, on stderr (`probe: exception escaping the handler` above), without its class, file, line or trace; the Warm Process survives it (same pid, the counter went on). | ||
| 116 | + | ||
| 97 | ## Terraform | 117 | ## Terraform |
| 98 | 118 | ||
| 99 | - Replacing a function (for example changing `runtime`) deletes its CRON triggers server side; Terraform recreates them only on the next apply. | 119 | - Replacing a function (for example changing `runtime`) deletes its CRON triggers server side; Terraform recreates them only on the next apply. |
| 100 | 120 | ||
| 101 | ## Not measured | 121 | ## Not measured |
| 102 | 122 | ||
| 103 | -- Cockpit logs (where stdout and uncaught exceptions are logged). | ||
| 104 | - Whether a deployment with a failing Composer script serves the new code or keeps the previous version. | 123 | - Whether a deployment with a failing Composer script serves the new code or keeps the previous version. |
modified
probe/README.md +3 -1 | @@ -60,6 +60,8 @@ done > 06-body-sizes.txt | ||
| 60 | 60 | # 7. Output and failures: where does stdout go, what does an exception produce? |
| 61 | 61 | curl -sS -i "$PROBE_URL/?mode=stdout" > 07-stdout.txt |
| 62 | 62 | curl -sS -i "$PROBE_URL/?mode=exception" > 07-exception.txt |
| 63 | +# A multi-line exception and a long line (bytes, 65536 by default) written to stderr: how are they split in the logs? | |
| 64 | +curl -sS -i "$PROBE_URL/?mode=stderr&bytes=65536" > 07-stderr.txt | |
| 63 | 65 | |
| 64 | 66 | # 8. Other methods and HEAD. |
| 65 | 67 | curl -sS -X PUT "$PROBE_URL/" --data 'put body' > 08-put.json |
| @@ -70,7 +72,7 @@ curl -sS -I "$PROBE_URL/" > 08-head.txt | ||
| 70 | 72 | sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson |
| 71 | 73 | ``` |
| 72 | 74 | |
| 73 | -10. In the Scaleway console, open the function's logs (Cockpit) and export the lines starting with `probe:` for the last hour, including the CRON ones, plus the `probe: written to stdout` and exception lines. | |
| 75 | +10. Export the function's logs of the last hour, CRON lines included, from Cockpit's Grafana or with the Loki query of the [README](../README.md#logs). | |
| 74 | 76 | |
| 75 | 77 | 11. Compare a CRON Event (step 9 or 10) with the HTTP one of `01-facts.json`, `event` and `context` alike, and list what only the CRON one has or lacks: headers (a trigger name or id, a token, `User-Agent`, `X-Forwarded-For`), method, path, context fields. |
| 76 | 78 | Then send each such header from a plain HTTP call, and check whether it reaches the Event as sent, is overwritten, or is removed: only a marker the platform sets itself can tell CRON Invocations from HTTP ones. |
| @@ -60,6 +60,8 @@ done > 06-body-sizes.txt | |||
| 60 | # 7. Output and failures: where does stdout go, what does an exception produce? | 60 | # 7. Output and failures: where does stdout go, what does an exception produce? |
| 61 | curl -sS -i "$PROBE_URL/?mode=stdout" > 07-stdout.txt | 61 | curl -sS -i "$PROBE_URL/?mode=stdout" > 07-stdout.txt |
| 62 | curl -sS -i "$PROBE_URL/?mode=exception" > 07-exception.txt | 62 | curl -sS -i "$PROBE_URL/?mode=exception" > 07-exception.txt |
| 63 | +# A multi-line exception and a long line (bytes, 65536 by default) written to stderr: how are they split in the logs? | ||
| 64 | +curl -sS -i "$PROBE_URL/?mode=stderr&bytes=65536" > 07-stderr.txt | ||
| 63 | 65 | ||
| 64 | # 8. Other methods and HEAD. | 66 | # 8. Other methods and HEAD. |
| 65 | curl -sS -X PUT "$PROBE_URL/" --data 'put body' > 08-put.json | 67 | curl -sS -X PUT "$PROBE_URL/" --data 'put body' > 08-put.json |
| @@ -70,7 +72,7 @@ curl -sS -I "$PROBE_URL/" > 08-head.txt | |||
| 70 | sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson | 72 | sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson |
| 71 | ``` | 73 | ``` |
| 72 | 74 | ||
| 73 | -10. In the Scaleway console, open the function's logs (Cockpit) and export the lines starting with `probe:` for the last hour, including the CRON ones, plus the `probe: written to stdout` and exception lines. | 75 | +10. Export the function's logs of the last hour, CRON lines included, from Cockpit's Grafana or with the Loki query of the [README](../README.md#logs). |
| 74 | 76 | ||
| 75 | 11. Compare a CRON Event (step 9 or 10) with the HTTP one of `01-facts.json`, `event` and `context` alike, and list what only the CRON one has or lacks: headers (a trigger name or id, a token, `User-Agent`, `X-Forwarded-For`), method, path, context fields. | 77 | 11. Compare a CRON Event (step 9 or 10) with the HTTP one of `01-facts.json`, `event` and `context` alike, and list what only the CRON one has or lacks: headers (a trigger name or id, a token, `User-Agent`, `X-Forwarded-For`), method, path, context fields. |
| 76 | Then send each such header from a plain HTTP call, and check whether it reaches the Event as sent, is overwritten, or is removed: only a marker the platform sets itself can tell CRON Invocations from HTTP ones. | 78 | Then send each such header from a plain HTTP call, and check whether it reaches the Event as sent, is overwritten, or is removed: only a marker the platform sets itself can tell CRON Invocations from HTTP ones. |
modified
probe/function/handler.php +9 -0 | @@ -69,6 +69,15 @@ function handle($event, $context) | ||
| 69 | 69 | |
| 70 | 70 | return ['statusCode' => 200, 'headers' => ['Content-Type' => 'text/plain'], 'body' => "Is the stdout line in the logs or in this body?\n"]; |
| 71 | 71 | |
| 72 | + case 'stderr': | |
| 73 | + // Written like the runtime logs its failures: does a multi-line exception stay one log entry? | |
| 74 | + $stderr = fopen('php://stderr', 'w'); | |
| 75 | + fwrite($stderr, 'probe: written to stderr: '.new RuntimeException('probe: multi-line').PHP_EOL); | |
| 76 | + // Is a long line, like a whole stack trace on one line, kept or cut? | |
| 77 | + fwrite($stderr, 'probe: long line '.str_repeat('a', (int) ($query['bytes'] ?? 65536)).' end of the long line'.PHP_EOL); | |
| 78 | + | |
| 79 | + return ['statusCode' => 200, 'headers' => ['Content-Type' => 'text/plain'], 'body' => "Check the stderr lines in the logs.\n"]; | |
| 80 | + | |
| 72 | 81 | case 'exception': |
| 73 | 82 | throw new RuntimeException('probe: exception escaping the handler'); |
| 74 | 83 | |
| @@ -69,6 +69,15 @@ function handle($event, $context) | |||
| 69 | 69 | ||
| 70 | return ['statusCode' => 200, 'headers' => ['Content-Type' => 'text/plain'], 'body' => "Is the stdout line in the logs or in this body?\n"]; | 70 | return ['statusCode' => 200, 'headers' => ['Content-Type' => 'text/plain'], 'body' => "Is the stdout line in the logs or in this body?\n"]; |
| 71 | 71 | ||
| 72 | + case 'stderr': | ||
| 73 | + // Written like the runtime logs its failures: does a multi-line exception stay one log entry? | ||
| 74 | + $stderr = fopen('php://stderr', 'w'); | ||
| 75 | + fwrite($stderr, 'probe: written to stderr: '.new RuntimeException('probe: multi-line').PHP_EOL); | ||
| 76 | + // Is a long line, like a whole stack trace on one line, kept or cut? | ||
| 77 | + fwrite($stderr, 'probe: long line '.str_repeat('a', (int) ($query['bytes'] ?? 65536)).' end of the long line'.PHP_EOL); | ||
| 78 | + | ||
| 79 | + return ['statusCode' => 200, 'headers' => ['Content-Type' => 'text/plain'], 'body' => "Check the stderr lines in the logs.\n"]; | ||
| 80 | + | ||
| 72 | case 'exception': | 81 | case 'exception': |
| 73 | throw new RuntimeException('probe: exception escaping the handler'); | 82 | throw new RuntimeException('probe: exception escaping the handler'); |
| 74 | 83 | ||