The benchmark depends on k8s.io/api (for v1.Container). Such a dependency is not desirable for k8s.io/component-base/logs, even if it's just for testing. The solution is to create a separate directory where such a dependency isn't a problem. The alternative, a separate package with its own go.mod file under k8s.io/component-base/logs wouldd have been more complicated to maintain (yet another go.mod file and different whitelisted dependencies).
44 lines
1.4 KiB
Markdown
44 lines
1.4 KiB
Markdown
# Benchmarking logging
|
|
|
|
Any major changes to the logging code, whether it is in Kubernetes or in klog,
|
|
must be benchmarked before and after the change.
|
|
|
|
## Running the benchmark
|
|
|
|
```
|
|
$ go test -bench=. -test.benchmem -benchmem .
|
|
```
|
|
|
|
## Real log data
|
|
|
|
The files under `data` define test cases for specific aspects of formatting. To
|
|
test with a log file that represents output under some kind of real load, copy
|
|
the log file into `data/<file name>.log` and run benchmarking as described
|
|
above. `-bench=BenchmarkLogging/<file name without .log suffix>` can be used
|
|
to benchmark just the new file.
|
|
|
|
When using `data/v<some number>/<file name>.log`, formatting will be done at
|
|
that log level. Symlinks can be created to simulating writing of the same log
|
|
data at different levels.
|
|
|
|
No such real data is included in the Kubernetes repo because of their size.
|
|
They can be found in the "artifacts" of this
|
|
https://testgrid.kubernetes.io/sig-instrumentation-tests#kind-json-logging-master
|
|
Prow job:
|
|
- `artifacts/logs/kind-control-plane/containers`
|
|
- `artifacts/logs/kind-*/kubelet.log`
|
|
|
|
With sufficient credentials, `gsutil` can be used to download everything for a job with:
|
|
```
|
|
gsutil -m cp -R gs://kubernetes-jenkins/logs/ci-kubernetes-kind-e2e-json-logging/<job ID> .
|
|
```
|
|
|
|
## Analyzing log data
|
|
|
|
While loading a file, some statistics about it are collected. Those are shown
|
|
when running with:
|
|
|
|
```
|
|
$ go test -v -bench=. -test.benchmem -benchmem .
|
|
```
|