Skip to content

Commit 0c389f9

Browse files
committed
Apply feedback from review and introduce --logtostdout flag
1 parent a5c4c07 commit 0c389f9

File tree

2 files changed

+100
-54
lines changed
  • keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components

2 files changed

+100
-54
lines changed

keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components/README.md

Lines changed: 99 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Items marked with (R) are required *prior to targeting to a milestone / release*
3737
- [ ] (R) Design details are appropriately documented
3838
- [ ] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors)
3939
- [ ] e2e Tests for all Beta API Operations (endpoints)
40-
- [ ] (R) Ensure GA e2e tests for meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
40+
- [ ] (R) Ensure GA e2e tests for meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
4141
- [ ] (R) Minimum Two Week Window for GA e2e tests to prove flake free
4242
- [ ] (R) Graduation criteria is in place
43-
- [ ] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
43+
- [ ] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
4444
- [ ] (R) Production readiness review completed
4545
- [ ] (R) Production readiness review approved
4646
- [ ] "Implementation History" section is up-to-date for milestone
@@ -55,29 +55,42 @@ Items marked with (R) are required *prior to targeting to a milestone / release*
5555
## Summary
5656

5757
This KEP proposes to deprecate and in the future to remove a subset of the klog
58-
command line flags from Kubernetes components to encourage more diverse
59-
approaches to logging in kubernetes ecosystem logging.
58+
command line flags from Kubernetes components, with goal of making logging of
59+
k8s core components simpler, easier to maintain and extend by community.
6060

6161
## Motivation
6262

63-
Early on Kubernetes adopted glog logging library for logging. Overtime the glog
64-
was forked to klog and multiple improvements were implemented, but features put
65-
into klog only piled up and were never removed. Introduction of alternative log
66-
formats like JSON created a conundrum, should we implement all klog features for
67-
JSON? Most of them don't make sense and method for their configuration leaves
68-
much to be desired. Klog features are controlled by set of global flags that
69-
remain last bastion of global state in k/k repository. Those flags don't have a
70-
single naming standard (some start with log prefix, some not), don't comply to
71-
k8s flag naming (use underscore instead of hyphen) and many other problems. We
72-
need to revisit how logging configuration is done in klog so it can work with
73-
alternative log formats and comply with current best practices.
74-
75-
Large number of features added to klog has lead to large drop in quality.
76-
[#90804](https://github.com/kubernetes/kubernetes/pull/90804) shows example
77-
where kubeup (canonical way to deploy kubernetes for testing) could not use
78-
klog feature to write log files due to scalability issues. The maintainers of
79-
klog decided it's easier to re-implementing a canonical klog feature in external
80-
project than debugging the underlying problem.
63+
Early on Kubernetes adopted glog logging library for logging. There was no
64+
larger motivation for picking glog, as the Go ecosystem was in its infancy at
65+
that time and there were no alternatives. As Kubernetes community needs grew
66+
glog was not flexible enough, prompting creation of its fork klog. By forking we
67+
inherited a lot of glog features that we never intended to support. Introduction
68+
of alternative log formats like JSON created a conundrum, should we implement
69+
all klog features for JSON? Most of them don't make sense and method for their
70+
configuration leaves much to be desired. Klog features are controlled by set of
71+
global flags that remain last bastion of global state in k/k repository. Those
72+
flags don't have a single naming standard (some start with log prefix, some
73+
not), don't comply to k8s flag naming (use underscore instead of hyphen) and
74+
many other problems. We need to revisit how logging configuration is done in
75+
klog, so it can work with alternative log formats and comply with current best
76+
practices.
77+
78+
Lack of investment and growing number of klog features impacted project quality.
79+
Klog has multiple problems, including:
80+
* performance is much worse than alternatives, for example 7-8x than
81+
[JSON format](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging#logger-implementation-performance)
82+
* doesn't support throughput to fulfill Kubernetes scalability requirements
83+
[kubernetes/kubernetes#90804](https://github.com/kubernetes/kubernetes/pull/90804)
84+
* complexity and confusion caused by maintaining backward compatibility for
85+
legacy glog features and flags. For example
86+
[kuberrnetes/klog#54](https://github.com/kubernetes/klog/issues/54)
87+
88+
Fixing all those issues would require big investment into logging, but would not
89+
solve the underlying problem of having to maintain a logging library. We have
90+
already seen cases like [kubernetes/kubernetes#90804](https://github.com/kubernetes/kubernetes/pull/90804)
91+
where it's easier to reimplement a klog feature in external project than fixing
92+
the problem in klog. To conclude, we should drive to reduce maintenance cost and
93+
improve quality by narrowing scope of logging library.
8194

8295
As for what configuration options should be standardized for all logging formats
8396
I would look into 12 factor app standard (https://12factor.net/). It defines
@@ -91,8 +104,8 @@ best practices.
91104
### Goals
92105

93106
* Unblock development of alternative logging formats
94-
* Improve quality of logging in k8s core components
95-
* Logging should use configuration mechanism developed by WG component-standard
107+
* Narrow scope of logging with more opinionated approach and smaller set of features
108+
* Reduce complexity of logging configuration and follow standard component configuration mechanism.
96109

97110
### Non-Goals
98111

@@ -102,24 +115,36 @@ best practices.
102115

103116
I propose that Kubernetes core components (kube-apiserver, kube-scheduler,
104117
kube-controller-manager, kubelet) should drop flags that extend
105-
logging over events streams or klog specific features. This change should be
118+
logging over events streams or klog specific features. This change should be
106119
scoped to only those components and not affect broader klog community.
107120

121+
With removal of output stream manipulation flags we need to provide a set of sane
122+
defaults and convention that will prevent logging formats implementations to
123+
diverge and reintroduce their own flags. As logs should be treated as event
124+
streams I would propose that we separate two main streams "info" and "error"
125+
based on log method called. As error logs should usually be treated with higher
126+
priority, having two streams prevents single pipeline from being clogged down
127+
(for example [kubernetes/klog#209](https://github.com/kubernetes/klog/issues/209)). For
128+
logging formats writing to standard streams, we should follow UNIX standard
129+
of mapping "info" logs to stdout and "error" logs to stderr.
130+
108131
Flags that should be deprecated:
109132

110-
* --log-dir, --log-file, --log-flush-frequency - responsible for writing to
111-
files and syncs to disk.
112-
Motivation: Remove complexity to make alternative loggers easier to implement
113-
and reducing feature surface to improve quality.
114-
* --logtostderr, --alsologtostderr, --one-output, --stderrthreshold -
115-
responsible enabling/disabling writing to stderr (vs file).
133+
* --log-dir, --log-file, --log-flush-frequency - responsible for writing to
134+
files and syncs to disk.
135+
Motivation: Not critical as there are easy to set up alternatives like:
136+
shell redirection, systemd service management or docker log driver. Removing
137+
them reduces complexity and allows development of non-text loggers like one
138+
writing to journal.
139+
* --logtostderr, --alsologtostderr, --one-output, --stderrthreshold -
140+
responsible enabling/disabling writing to stderr (vs file).
116141
Motivation: Not needed if writing to files is removed.
117-
* --log-file-max-size, --skip-log-headers - responsible configuration of file
118-
rotation.
142+
* --log-file-max-size, --skip-log-headers - responsible configuration of file
143+
rotation.
119144
Motivation: Not needed if writing to files is removed.
120-
* --add-dir-header, --skip-headers - klog format specific flags .
145+
* --add-dir-header, --skip-headers - klog format specific flags .
121146
Motivation: don't apply to other log formats
122-
* --log-backtrace-at - an legacy glog feature.
147+
* --log-backtrace-at - an legacy glog feature.
123148
Motivation: No trace of anyone using this feature.
124149

125150
Flag deprecation should comply with standard k8s policy and require 3 releases before removal.
@@ -129,16 +154,16 @@ This leaves that two flags that should be implemented by all log formats
129154
* -v - control global log verbosity of Info logs
130155
* --vmodule - control log verbosity of Info logs on per file level
131156

132-
Those flags were chosen as they have direct effect of which logs are written,
157+
Those flags were chosen as they have direct effect of which logs are written,
133158
directly impacting log volume and component performance.
134159

135160
### User Stories
136161

137162
#### Writing logs to files
138163

139-
We should use go-runner as a official fallback for users that want to retain
140-
writing logs to files. go-runner runs as parent process to components binary
141-
reading it's stdout/stderr and is able to route them to files. go-runner is
164+
We should use go-runner as a official fallback for users that want to retain
165+
writing logs to files. go-runner runs as parent process to components binary
166+
reading it's stdout/stderr and is able to route them to files. go-runner is
142167
already released as part of official K8s images it should be as simple as changing:
143168

144169
```
@@ -153,9 +178,9 @@ to
153178

154179
### Caveats
155180

156-
Is it ok for K8s components to drop support for subset of klog flags?
181+
Is it ok for K8s components to drop support for subset of klog flags?
157182

158-
Technically K8s already doesn't support klog flags. Klog flags are renamed to
183+
Technically K8s already doesn't support klog flags. Klog flags are renamed to
159184
comply with K8s flag naming convention (underscores are replaced with hyphens).
160185
Full klog support was never promised to users and removal of those flags should
161186
be treated as removal of any other flag.
@@ -172,15 +197,33 @@ to community when compared to forcing closed list of features on everyone.
172197

173198
#### Users don't want to use go-runner as replacement.
174199

175-
TODO
200+
There are multiple alternatives that allow users to redirect logs to a file.
201+
Exact solution depends on users preferred way to run the process with one shared
202+
property, all of them supports consuming stdout/stderr. For example shell
203+
redirection, systemd service management or
204+
[docker logging driver](https://docs.docker.com/config/containers/logging/configure/).
205+
Not all of them support log rotation, but it's users responsibility to know
206+
complementary tooling that provides it. For example tools like
207+
[logrotate](https://linux.die.net/man/8/logrotate).
176208

177209
#### Log processing in parent process causes performance problems
178210

179-
TODO
211+
Passing logs through a parent process is a normal linux pattern used by
212+
systemd-run, docker or containerd. For kubernetes we already use go-runner in
213+
scalability testing to read apiserver logs and write them to file. Before we
214+
reach Beta we should conduct detailed throughput testing of go-runner to
215+
validate upper limit, but we don't expect any performance problem just based on
216+
architecture.
180217

181218
## Design Details
182219

183-
TODO
220+
Splitting stdout from stderr would be a breaking change in both klog and
221+
kubernetes components. To avoid that I propose to introduce new logging flag
222+
`--logtostdout` in klog that will allow writing info logs to stdout. This flag
223+
will be used avoid introducing breaking change in klog. For Kubernetes components
224+
we would use this flag to start testing this change and delay enabling this flag
225+
by default by one release when we will hit Beta. As any other klog flag it
226+
should be deprecated when this effort hits GA.
184227

185228
### Test Plan
186229

@@ -195,12 +238,15 @@ all existing klog features.
195238
- Kubernetes logging configuration drops global state
196239
- Go-runner is feature complementary to klog flags planned for deprecation
197240
- Projects in Kubernetes Org are migrated to go-runner
241+
- Add --logtostdout flag to klog disabled by default
242+
- Use --logtostdout in kubernetes tests
198243

199244
#### Beta
200245

201-
- Go-runner project is well maintained and documented
202-
- Documentation on switching go-runner is publicly available
246+
- Go-runner project is well maintained and documented
247+
- Documentation on migrating off klog flags is publicly available
203248
- Kubernetes klog flags are marked as deprecated
249+
- Split stdout and stderr logs in Kubernetes components by default
204250

205251
#### GA
206252

@@ -221,19 +267,19 @@ N/A
221267

222268
## Drawbacks
223269

224-
Deprecating klog features outside klog might create confusion in community.
225-
Large part of community doesn't know that klog was created from necessity and
226-
is not the end goal for logging in Kubernetes. We should do due diligence to
227-
let community know about our plans and their impact on external components
270+
Deprecating klog features outside klog might create confusion in community.
271+
Large part of community doesn't know that klog was created from necessity and
272+
is not the end goal for logging in Kubernetes. We should do due diligence to
273+
let community know about our plans and their impact on external components
228274
depending on klog.
229275

230276
## Alternatives
231277

232-
### Continue supporting all klog features
233-
At some point we should migrate all logging
278+
### Continue supporting all klog features
279+
At some point we should migrate all logging
234280
configuration to Options or Configuration. Doing so while supporting all klog
235281
features makes their future removal much harder.
236282

237-
### Release klog 3.0 with removed features
283+
### Release klog 3.0 with removed features
238284
Removal of those features cannot be done without whole k8s community instead of
239285
just k8s core components

keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components/kep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ creation-date: 2021-07-30
1010
reviewers:
1111
- TBD
1212
approvers:
13-
- TBD
13+
- ehashman
1414

1515
see-also:
1616
- "/keps/sig-instrumentation/1602-structured-logging"

0 commit comments

Comments
 (0)