|
| 1 | +<!-- Dev guide --> |
| 2 | + |
| 3 | + |
| 4 | +## Logging |
| 5 | + |
| 6 | +### Change log verbosity |
| 7 | +We use the `k8s.io/klog/v2` package to manage logging. |
| 8 | + |
| 9 | +We generally follow the [k8s instrumentation logging guidelines](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md), which states "the practical default level is V(2). Developers and QE environments may wish to run at V(3) or V(4)". |
| 10 | + |
| 11 | +To configure logging verbosity, specify the `v` flag such as `--v=2`. |
| 12 | + |
| 13 | +### Add logs |
| 14 | +We adapt the [k8s instrumentation logging guidelines](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md) based on our code base. |
| 15 | + |
| 16 | +1. The server startup process. Logging at the default verbosity level is generally welcome here as this is only logged once at startup, and provides useful info for debugging. |
| 17 | + * `klog.V(0).InfoS` = `klog.InfoS` Default, log things such as startup flags |
| 18 | + |
| 19 | +2. Reconciler loops. The reconciler loops watches for CR changes such as the `InferenceModel` CR. And given changes in these CRs significantly affect the behavior of the extension, we recommend using v=1 verbosity level as default, and sparsely use higher verbosity levels. |
| 20 | + |
| 21 | + * `klog.V(1).InfoS` |
| 22 | + * Default log level in the reconcilers. |
| 23 | + * Information about config (listening on X, watching Y) |
| 24 | + * Errors that repeat frequently that relate to conditions that can be corrected (e.g., inference model not initialized yet) |
| 25 | + * `klog.V(2).InfoS` |
| 26 | + * System state changing (adding/removing objects in the data store) |
| 27 | + * `V(3)` and above: Use your best judgement. |
| 28 | + |
| 29 | +3. Inference request handling. These requests are expected to be much higher volume than the control flow in the reconcilers and therefore we should be mindful of log spamming. We recommend using v=2 to log important info about a request, such as the HTTP response code, and higher verbosity levels for less important info. |
| 30 | + |
| 31 | + * `klog.V(2).InfoS` |
| 32 | + * Logging HTTP requests and their exit code |
| 33 | + * Important decision making such as picking the target model, target pod |
| 34 | + * `klog.V(3).InfoS` |
| 35 | + * Detailed request scheduling algorithm operations, such as running the filtering logic |
| 36 | + * `V(4)` and above: Use your best judgement. |
| 37 | + |
| 38 | +4. Metric scraping loops. These loops run at a very high frequency, and logs can be very spammy if not handled properly. |
| 39 | + * `klog.V(4).InfoS` |
| 40 | + * Transient errors/warnings, such as failure to get response from a pod. |
| 41 | + * `klog.V(5).InfoS` - Default |
| 42 | + |
| 43 | +5. Misc |
| 44 | + * `klog.V(3).InfoS` |
| 45 | + * A periodically (every 5s) printed debug message with the current pods and metrics. This is very important to debug the request scheduling algorithm, and yet not spammy compared to the metric scraping loop logs. |
0 commit comments