Skip to content

Commit 45235ff

Browse files
pohlyk8s-publishing-bot
authored andcommitted
logs: make LoggingConfiguration an unversioned API
Making the LoggingConfiguration part of the versioned component-base/config API had the theoretic advantage that components could have offered different configuration APIs with experimental features limited to alpha versions (for example, sanitization offered only in a v1alpha1.KubeletConfiguration). Some components could have decided to only use stable logging options. In practice, this wasn't done. Furthermore, we don't want different components to make different choices regarding which logging features they offer to users. It should always be the same everywhere, for the sake of consistency. This can be achieved with a saner Go API by dropping the distinction between internal and external LoggingConfiguration types. Different stability levels of indidividual fields have to be covered by documentation (done) and potentially feature gates (not currently done). Advantages: - everything related to logging is under component-base/logs; previously this was scattered across different packages and different files under "logs" (why some code was in logs/config.go vs. logs/options.go vs. logs/logs.go always confused me again and again when coming back to the code): - long-term config and command line API are clearly separated into the "api" package underneath that - logs/logs.go itself only deals with legacy global flags and logging configuration - removal of separate Go APIs like logs.BindLoggingFlags and logs.Options - LogRegistry becomes an implementation detail, with less code and less exported functionality (only registration needs to be exported, querying is internal) Kubernetes-commit: 1aceac797d404b4ac3b3d02fe43d495d1f645aba
1 parent bb30c96 commit 45235ff

30 files changed

+941
-1045
lines changed

config/types.go

-132
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ limitations under the License.
1717
package config
1818

1919
import (
20-
"fmt"
21-
"strconv"
22-
"strings"
23-
"time"
24-
25-
"github.com/spf13/pflag"
26-
27-
"k8s.io/apimachinery/pkg/api/resource"
2820
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2921
)
3022

@@ -86,127 +78,3 @@ type DebuggingConfiguration struct {
8678
// enableProfiling is true.
8779
EnableContentionProfiling bool
8880
}
89-
90-
// LoggingConfiguration contains logging options
91-
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information.
92-
type LoggingConfiguration struct {
93-
// Format Flag specifies the structure of log messages.
94-
// default value of format is `text`
95-
Format string
96-
// Maximum number of nanoseconds (i.e. 1s = 1000000000) between log
97-
// flushes. Ignored if the selected logging backend writes log
98-
// messages without buffering.
99-
FlushFrequency time.Duration
100-
// Verbosity is the threshold that determines which log messages are
101-
// logged. Default is zero which logs only the most important
102-
// messages. Higher values enable additional messages. Error messages
103-
// are always logged.
104-
Verbosity VerbosityLevel
105-
// VModule overrides the verbosity threshold for individual files.
106-
// Only supported for "text" log format.
107-
VModule VModuleConfiguration
108-
// [Experimental] Options holds additional parameters that are specific
109-
// to the different logging formats. Only the options for the selected
110-
// format get used, but all of them get validated.
111-
Options FormatOptions
112-
}
113-
114-
// FormatOptions contains options for the different logging formats.
115-
type FormatOptions struct {
116-
// [Experimental] JSON contains options for logging format "json".
117-
JSON JSONOptions
118-
}
119-
120-
// JSONOptions contains options for logging format "json".
121-
type JSONOptions struct {
122-
// [Experimental] SplitStream redirects error messages to stderr while
123-
// info messages go to stdout, with buffering. The default is to write
124-
// both to stdout, without buffering.
125-
SplitStream bool
126-
// [Experimental] InfoBufferSize sets the size of the info stream when
127-
// using split streams. The default is zero, which disables buffering.
128-
InfoBufferSize resource.QuantityValue
129-
}
130-
131-
// VModuleConfiguration is a collection of individual file names or patterns
132-
// and the corresponding verbosity threshold.
133-
type VModuleConfiguration []VModuleItem
134-
135-
var _ pflag.Value = &VModuleConfiguration{}
136-
137-
// VModuleItem defines verbosity for one or more files which match a certain
138-
// glob pattern.
139-
type VModuleItem struct {
140-
// FilePattern is a base file name (i.e. minus the ".go" suffix and
141-
// directory) or a "glob" pattern for such a name. It must not contain
142-
// comma and equal signs because those are separators for the
143-
// corresponding klog command line argument.
144-
FilePattern string
145-
// Verbosity is the threshold for log messages emitted inside files
146-
// that match the pattern.
147-
Verbosity VerbosityLevel
148-
}
149-
150-
// String returns the -vmodule parameter (comma-separated list of pattern=N).
151-
func (vmodule *VModuleConfiguration) String() string {
152-
var patterns []string
153-
for _, item := range *vmodule {
154-
patterns = append(patterns, fmt.Sprintf("%s=%d", item.FilePattern, item.Verbosity))
155-
}
156-
return strings.Join(patterns, ",")
157-
}
158-
159-
// Set parses the -vmodule parameter (comma-separated list of pattern=N).
160-
func (vmodule *VModuleConfiguration) Set(value string) error {
161-
// This code mirrors https://github.com/kubernetes/klog/blob/9ad246211af1ed84621ee94a26fcce0038b69cd1/klog.go#L287-L313
162-
163-
for _, pat := range strings.Split(value, ",") {
164-
if len(pat) == 0 {
165-
// Empty strings such as from a trailing comma can be ignored.
166-
continue
167-
}
168-
patLev := strings.Split(pat, "=")
169-
if len(patLev) != 2 || len(patLev[0]) == 0 || len(patLev[1]) == 0 {
170-
return fmt.Errorf("%q does not have the pattern=N format", pat)
171-
}
172-
pattern := patLev[0]
173-
// 31 instead of 32 to ensure that it also fits into int32.
174-
v, err := strconv.ParseUint(patLev[1], 10, 31)
175-
if err != nil {
176-
return fmt.Errorf("parsing verbosity in %q: %v", pat, err)
177-
}
178-
*vmodule = append(*vmodule, VModuleItem{FilePattern: pattern, Verbosity: VerbosityLevel(v)})
179-
}
180-
return nil
181-
}
182-
183-
func (vmodule *VModuleConfiguration) Type() string {
184-
return "pattern=N,..."
185-
}
186-
187-
// VerbosityLevel represents a klog or logr verbosity threshold.
188-
type VerbosityLevel uint32
189-
190-
var _ pflag.Value = new(VerbosityLevel)
191-
192-
func (l *VerbosityLevel) String() string {
193-
return strconv.FormatInt(int64(*l), 10)
194-
}
195-
196-
func (l *VerbosityLevel) Get() interface{} {
197-
return *l
198-
}
199-
200-
func (l *VerbosityLevel) Set(value string) error {
201-
// Limited to int32 for compatibility with klog.
202-
v, err := strconv.ParseUint(value, 10, 31)
203-
if err != nil {
204-
return err
205-
}
206-
*l = VerbosityLevel(v)
207-
return nil
208-
}
209-
210-
func (l *VerbosityLevel) Type() string {
211-
return "Level"
212-
}

config/types_test.go

-119
This file was deleted.

config/v1alpha1/conversion.go

-8
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,3 @@ func Convert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionConfig
5151
func Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(in *config.LeaderElectionConfiguration, out *LeaderElectionConfiguration, s conversion.Scope) error {
5252
return autoConvert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(in, out, s)
5353
}
54-
55-
func Convert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in *LoggingConfiguration, out *config.LoggingConfiguration, s conversion.Scope) error {
56-
return autoConvert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in, out, s)
57-
}
58-
59-
func Convert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in *config.LoggingConfiguration, out *LoggingConfiguration, s conversion.Scope) error {
60-
return autoConvert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in, out, s)
61-
}

config/v1alpha1/defaults.go

-30
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package v1alpha1
1919
import (
2020
"time"
2121

22-
"k8s.io/apimachinery/pkg/api/resource"
2322
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
utilpointer "k8s.io/utils/pointer"
2524
)
@@ -97,32 +96,3 @@ func NewRecommendedDebuggingConfiguration() *DebuggingConfiguration {
9796
RecommendedDebuggingConfiguration(ret)
9897
return ret
9998
}
100-
101-
// RecommendedLoggingConfiguration defaults logging configuration.
102-
// This will set the recommended default
103-
// values, but they may be subject to change between API versions. This function
104-
// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
105-
// function to allow consumers of this type to set whatever defaults for their
106-
// embedded configs. Forcing consumers to use these defaults would be problematic
107-
// as defaulting in the scheme is done as part of the conversion, and there would
108-
// be no easy way to opt-out. Instead, if you want to use this defaulting method
109-
// run it in your wrapper struct of this type in its `SetDefaults_` method.
110-
func RecommendedLoggingConfiguration(obj *LoggingConfiguration) {
111-
if obj.Format == "" {
112-
obj.Format = "text"
113-
}
114-
var empty resource.QuantityValue
115-
if obj.Options.JSON.InfoBufferSize == empty {
116-
obj.Options.JSON.InfoBufferSize = resource.QuantityValue{
117-
// This is similar, but not quite the same as a default
118-
// constructed instance.
119-
Quantity: *resource.NewQuantity(0, resource.DecimalSI),
120-
}
121-
// This sets the unexported Quantity.s which will be compared
122-
// by reflect.DeepEqual in some tests.
123-
_ = obj.Options.JSON.InfoBufferSize.String()
124-
}
125-
if obj.FlushFrequency == 0 {
126-
obj.FlushFrequency = 5 * time.Second
127-
}
128-
}

config/v1alpha1/types.go

-61
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
"time"
21-
22-
"k8s.io/apimachinery/pkg/api/resource"
2320
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2421
)
2522

@@ -83,61 +80,3 @@ type ClientConnectionConfiguration struct {
8380
// burst allows extra queries to accumulate when a client is exceeding its rate.
8481
Burst int32 `json:"burst"`
8582
}
86-
87-
// LoggingConfiguration contains logging options
88-
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information.
89-
type LoggingConfiguration struct {
90-
// Format Flag specifies the structure of log messages.
91-
// default value of format is `text`
92-
Format string `json:"format,omitempty"`
93-
// Maximum number of nanoseconds (i.e. 1s = 1000000000) between log
94-
// flushes. Ignored if the selected logging backend writes log
95-
// messages without buffering.
96-
FlushFrequency time.Duration `json:"flushFrequency"`
97-
// Verbosity is the threshold that determines which log messages are
98-
// logged. Default is zero which logs only the most important
99-
// messages. Higher values enable additional messages. Error messages
100-
// are always logged.
101-
Verbosity uint32 `json:"verbosity"`
102-
// VModule overrides the verbosity threshold for individual files.
103-
// Only supported for "text" log format.
104-
VModule VModuleConfiguration `json:"vmodule,omitempty"`
105-
// [Experimental] Options holds additional parameters that are specific
106-
// to the different logging formats. Only the options for the selected
107-
// format get used, but all of them get validated.
108-
Options FormatOptions `json:"options,omitempty"`
109-
}
110-
111-
// FormatOptions contains options for the different logging formats.
112-
type FormatOptions struct {
113-
// [Experimental] JSON contains options for logging format "json".
114-
JSON JSONOptions `json:"json,omitempty"`
115-
}
116-
117-
// JSONOptions contains options for logging format "json".
118-
type JSONOptions struct {
119-
// [Experimental] SplitStream redirects error messages to stderr while
120-
// info messages go to stdout, with buffering. The default is to write
121-
// both to stdout, without buffering.
122-
SplitStream bool `json:"splitStream,omitempty"`
123-
// [Experimental] InfoBufferSize sets the size of the info stream when
124-
// using split streams. The default is zero, which disables buffering.
125-
InfoBufferSize resource.QuantityValue `json:"infoBufferSize,omitempty"`
126-
}
127-
128-
// VModuleConfiguration is a collection of individual file names or patterns
129-
// and the corresponding verbosity threshold.
130-
type VModuleConfiguration []VModuleItem
131-
132-
// VModuleItem defines verbosity for one or more files which match a certain
133-
// glob pattern.
134-
type VModuleItem struct {
135-
// FilePattern is a base file name (i.e. minus the ".go" suffix and
136-
// directory) or a "glob" pattern for such a name. It must not contain
137-
// comma and equal signs because those are separators for the
138-
// corresponding klog command line argument.
139-
FilePattern string `json:"filePattern"`
140-
// Verbosity is the threshold for log messages emitted inside files
141-
// that match the pattern.
142-
Verbosity uint32 `json:"verbosity"`
143-
}

0 commit comments

Comments
 (0)