|
| 1 | +--- |
| 2 | +title: Logging |
| 3 | +weight: 4 |
| 4 | +--- |
| 5 | + |
| 6 | +## Logging Configuration |
| 7 | + |
| 8 | +Pipelines-as-Code uses a ConfigMap named `pac-config-logging` in its namespace (by default, `pipelines-as-code`) to configure the logging behavior of its controllers. |
| 9 | + |
| 10 | +To view the ConfigMap, use the following command: |
| 11 | + |
| 12 | +```bash |
| 13 | +kubectl get configmap pac-config-logging -n pipelines-as-code |
| 14 | +``` |
| 15 | + |
| 16 | +To see the full content of the ConfigMap, run: |
| 17 | + |
| 18 | +```bash |
| 19 | +kubectl get configmap pac-config-logging -n pipelines-as-code -o yaml |
| 20 | +``` |
| 21 | + |
| 22 | +The `data` section of the ConfigMap contains the following keys: |
| 23 | + |
| 24 | +* `loglevel.pipelinesascode`: The log level for the `pipelines-as-code-controller` component. |
| 25 | +* `loglevel.pipelines-as-code-webhook`: The log level for the `pipelines-as-code-webhook` component. |
| 26 | +* `loglevel.pac-watcher`: The log level for the `pipelines-as-code-watcher` component. |
| 27 | + |
| 28 | +You can change the log level from `info` to `debug` or any other supported value. For example, to set the log level for the `pipelines-as-code-watcher` to `debug`, run: |
| 29 | + |
| 30 | +```bash |
| 31 | +kubectl patch configmap pac-config-logging -n pipelines-as-code --type json -p '[{"op": "replace", "path": "/data/loglevel.pac-watcher", "value":"debug"}]' |
| 32 | +``` |
| 33 | + |
| 34 | +The watcher will automatically pick up the new log level. |
| 35 | + |
| 36 | +If you want to use the same log level for all Pipelines-as-Code components, you can remove the individual `loglevel.*` keys. In this case, all components will use the log level defined in the `level` field of the `zap-logger-config`. |
| 37 | + |
| 38 | +```bash |
| 39 | +kubectl patch configmap pac-config-logging -n pipelines-as-code --type json -p '[{"op": "remove", "path": "/data/loglevel.pac-watcher"}, {"op": "remove", "path": "/data/loglevel.pipelines-as-code-webhook"}, {"op": "remove", "path": "/data/loglevel.pipelinesascode"}]' |
| 40 | +``` |
| 41 | + |
| 42 | +The `zap-logger-config` supports the following log levels: |
| 43 | + |
| 44 | +* `debug`: Fine-grained debugging information. |
| 45 | +* `info`: Normal operational logging. |
| 46 | +* `warn`: Unexpected but non-critical errors. |
| 47 | +* `error`: Critical errors that are unexpected during normal operation. |
| 48 | +* `dpanic`: Triggers a panic (crash) in development mode. |
| 49 | +* `panic`: Triggers a panic (crash). |
| 50 | +* `fatal`: Immediately exits with a status of 1. |
| 51 | + |
| 52 | +For more details, see the [Knative logging documentation](https://knative.dev/docs/serving/observability/logging/config-logging). |
| 53 | + |
| 54 | +## Debugging API Interactions |
| 55 | + |
| 56 | +If you need to troubleshoot interactions with the Git provider API (e.g., GitHub), you can enable detailed API request logging. This is useful for debugging permission issues or unexpected API responses. |
| 57 | + |
| 58 | +To enable this feature, set the log level for the `pipelines-as-code-controller` to `debug`. This will cause the controller to log the duration, URL, and remaining rate-limit for each API call it makes. |
| 59 | + |
| 60 | +You can enable this for the main controller with the following `kubectl` command: |
| 61 | + |
| 62 | +```bash |
| 63 | +kubectl patch configmap pac-config-logging -n pipelines-as-code --type json -p '[{"op": "replace", "path": "/data/loglevel.pipelinesascode", "value":"debug"}]' |
| 64 | +``` |
| 65 | + |
| 66 | +### Rate Limit Monitoring |
| 67 | + |
| 68 | +When debug logging is enabled, Pipelines-as-Code automatically monitors GitHub API rate limits and provides intelligent warnings when limits are running low. This helps prevent API quota exhaustion and provides early warning for potential service disruptions. |
| 69 | + |
| 70 | +The rate limit monitoring includes: |
| 71 | + |
| 72 | +* **Debug level**: All API calls log their duration, URL, and remaining rate limit count |
| 73 | +* **Info level**: When remaining calls drop below 500, logs include additional context like total limit and reset time |
| 74 | +* **Warning level**: When remaining calls drop below 100, warnings are logged to alert administrators |
| 75 | +* **Error level**: When remaining calls drop below 50, critical alerts are logged indicating immediate attention is needed |
| 76 | + |
| 77 | +#### Example Log Messages |
| 78 | + |
| 79 | +```console |
| 80 | +# Debug level - normal API call logging |
| 81 | +{"level":"debug","ts":"...","caller":"...","msg":"GitHub API call completed","operation":"get_pull_request","duration_ms":23,"provider":"github","repo":"myorg/myrepo","url_path":"/repos/myorg/myrepo/pulls/1","rate_limit_remaining":"4850","status_code":200} |
| 82 | +# Info level - moderate rate limit usage |
| 83 | +{"level":"info","ts":"...","caller":"...","msg":"GitHub API rate limit moderate","repo":"myorg/myrepo","remaining":350,"limit":"5000","reset":"1672531200 (15:30:00 UTC)"} |
| 84 | +# Warning level - low rate limit |
| 85 | +{"level":"warn","ts":"...","caller":"...","msg":"GitHub API rate limit running low","repo":"myorg/myrepo","remaining":75,"limit":"5000","reset":"1672531200 (15:30:00 UTC)"} |
| 86 | +# Error level - critically low rate limit |
| 87 | +{"level":"error","ts":"...","caller":"...","msg":"GitHub API rate limit critically low","repo":"myorg/myrepo","remaining":25,"limit":"5000","reset":"1672531200 (15:30:00 UTC)"} |
| 88 | +``` |
| 89 | + |
| 90 | +The rate limit information includes: |
| 91 | + |
| 92 | +* **Remaining calls**: Number of API calls left in the current rate limit window |
| 93 | +* **Total limit**: The maximum number of calls allowed (typically 5000 for authenticated requests) |
| 94 | +* **Reset time**: When the rate limit window resets (shown as Unix timestamp and human-readable time) |
| 95 | +* **Repository context**: Which repository triggered the API call (when available) |
| 96 | + |
| 97 | +This monitoring helps administrators: |
| 98 | + |
| 99 | +* **Prevent service disruptions**: Early warnings allow proactive measures before hitting rate limits |
| 100 | +* **Optimize API usage**: Identify repositories or operations that consume excessive API calls |
| 101 | +* **Plan maintenance windows**: Schedule intensive operations around rate limit reset times |
| 102 | +* **Debug authentication issues**: Rate limit headers can indicate token validity and permissions |
0 commit comments