Skip to content

Commit 18cdd3a

Browse files
committed
promote experimental code to stable
ktesting is heavily used in Kubernetes already for testing. The test package is also used. The textlogger is not used that much yet because it was still experimental (and thus no replacement for normal klog), but it's simple and unlikely to need any breaking API changes.
1 parent 6632ba5 commit 18cdd3a

File tree

8 files changed

+0
-212
lines changed

8 files changed

+0
-212
lines changed

ktesting/init/init.go

-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ limitations under the License.
1717
// Package init registers the command line flags for k8s.io/klogr/testing in
1818
// the flag.CommandLine. This is done during initialization, so merely
1919
// importing it is enough.
20-
//
21-
// # Experimental
22-
//
23-
// Notice: This package is EXPERIMENTAL and may be changed or removed in a
24-
// later release.
2520
package init
2621

2722
import (

ktesting/options.go

-45
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ import (
2929
// bind command line flags to the instance before passing it to NewTestContext.
3030
//
3131
// Must be constructed with NewConfig.
32-
//
33-
// # Experimental
34-
//
35-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
36-
// later release.
3732
type Config struct {
3833
vstate *verbosity.VState
3934
co configOptions
@@ -54,11 +49,6 @@ func (c *Config) VModule() flag.Value {
5449
}
5550

5651
// ConfigOption implements functional parameters for NewConfig.
57-
//
58-
// # Experimental
59-
//
60-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
61-
// later release.
6252
type ConfigOption func(co *configOptions)
6353

6454
type configOptions struct {
@@ -72,23 +62,13 @@ type configOptions struct {
7262
// AnyToString overrides the default formatter for values that are not
7363
// supported directly by klog. The default is `fmt.Sprintf("%+v")`.
7464
// The formatter must not panic.
75-
//
76-
// # Experimental
77-
//
78-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
79-
// later release.
8065
func AnyToString(anyToString func(value interface{}) string) ConfigOption {
8166
return func(co *configOptions) {
8267
co.anyToString = anyToString
8368
}
8469
}
8570

8671
// VerbosityFlagName overrides the default -testing.v for the verbosity level.
87-
//
88-
// # Experimental
89-
//
90-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
91-
// later release.
9272
func VerbosityFlagName(name string) ConfigOption {
9373
return func(co *configOptions) {
9474
co.verbosityFlagName = name
@@ -97,11 +77,6 @@ func VerbosityFlagName(name string) ConfigOption {
9777

9878
// VModulFlagName overrides the default -testing.vmodule for the per-module
9979
// verbosity levels.
100-
//
101-
// # Experimental
102-
//
103-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
104-
// later release.
10580
func VModuleFlagName(name string) ConfigOption {
10681
return func(co *configOptions) {
10782
co.vmoduleFlagName = name
@@ -114,11 +89,6 @@ func VModuleFlagName(name string) ConfigOption {
11489
// https://github.com/kubernetes/community/blob/9406b4352fe2d5810cb21cc3cb059ce5886de157/contributors/devel/sig-instrumentation/logging.md#logging-conventions),
11590
// which is useful when debugging a failed test. `go test` only shows the log
11691
// output for failed tests. To see all output, use `go test -v`.
117-
//
118-
// # Experimental
119-
//
120-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
121-
// later release.
12292
func Verbosity(level int) ConfigOption {
12393
return func(co *configOptions) {
12494
co.verbosityDefault = level
@@ -129,11 +99,6 @@ func Verbosity(level int) ConfigOption {
12999
// to being printed. Off by default. Unit tests that want to verify that
130100
// log entries are emitted as expected can turn this on and then retrieve
131101
// the captured log through the Underlier LogSink interface.
132-
//
133-
// # Experimental
134-
//
135-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
136-
// later release.
137102
func BufferLogs(enabled bool) ConfigOption {
138103
return func(co *configOptions) {
139104
co.bufferLogs = enabled
@@ -142,11 +107,6 @@ func BufferLogs(enabled bool) ConfigOption {
142107

143108
// NewConfig returns a configuration with recommended defaults and optional
144109
// modifications. Command line flags are not bound to any FlagSet yet.
145-
//
146-
// # Experimental
147-
//
148-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
149-
// later release.
150110
func NewConfig(opts ...ConfigOption) *Config {
151111
c := &Config{
152112
co: configOptions{
@@ -165,11 +125,6 @@ func NewConfig(opts ...ConfigOption) *Config {
165125
}
166126

167127
// AddFlags registers the command line flags that control the configuration.
168-
//
169-
// # Experimental
170-
//
171-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
172-
// later release.
173128
func (c *Config) AddFlags(fs *flag.FlagSet) {
174129
fs.Var(c.vstate.V(), c.co.verbosityFlagName, "number for the log level verbosity of the testing logger")
175130
fs.Var(c.vstate.VModule(), c.co.vmoduleFlagName, "comma-separated list of pattern=N log level settings for files matching the patterns")

ktesting/setup.go

-10
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,12 @@ import (
2424

2525
// DefaultConfig is the global default logging configuration for a unit
2626
// test. It is used by NewTestContext and k8s.io/klogr/testing/init.
27-
//
28-
// # Experimental
29-
//
30-
// Notice: This variable is EXPERIMENTAL and may be changed or removed in a
31-
// later release.
3227
var DefaultConfig = NewConfig()
3328

3429
// NewTestContext returns a logger and context for use in a unit test case or
3530
// benchmark. The tl parameter can be a testing.T or testing.B pointer that
3631
// will receive all log output. Importing k8s.io/klogr/testing/init will add
3732
// command line flags that modify the configuration of that log output.
38-
//
39-
// # Experimental
40-
//
41-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
42-
// later release.
4333
func NewTestContext(tl TL) (logr.Logger, context.Context) {
4434
logger := NewLogger(tl, DefaultConfig)
4535
ctx := logr.NewContext(context.Background(), logger)

ktesting/testinglogger.go

-65
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ limitations under the License.
3434
//
3535
// Serialization of the structured log parameters is done in the same way
3636
// as for klog.InfoS.
37-
//
38-
// # Experimental
39-
//
40-
// Notice: This package is EXPERIMENTAL and may be changed or removed in a
41-
// later release.
4237
package ktesting
4338

4439
import (
@@ -58,23 +53,13 @@ import (
5853
)
5954

6055
// TL is the relevant subset of testing.TB.
61-
//
62-
// # Experimental
63-
//
64-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
65-
// later release.
6656
type TL interface {
6757
Helper()
6858
Log(args ...interface{})
6959
}
7060

7161
// NopTL implements TL with empty stubs. It can be used when only capturing
7262
// output in memory is relevant.
73-
//
74-
// # Experimental
75-
//
76-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
77-
// later release.
7863
type NopTL struct{}
7964

8065
func (n NopTL) Helper() {}
@@ -83,11 +68,6 @@ func (n NopTL) Log(args ...interface{}) {}
8368
var _ TL = NopTL{}
8469

8570
// BufferTL implements TL with an in-memory buffer.
86-
//
87-
// # Experimental
88-
//
89-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
90-
// later release.
9171
type BufferTL struct {
9272
strings.Builder
9373
}
@@ -109,11 +89,6 @@ var _ TL = &BufferTL{}
10989
//
11090
// Verbosity can be modified at any time through the Config.V and
11191
// Config.VModule API.
112-
//
113-
// # Experimental
114-
//
115-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
116-
// later release.
11792
func NewLogger(t TL, c *Config) logr.Logger {
11893
l := tlogger{
11994
shared: &tloggerShared{
@@ -141,11 +116,6 @@ func NewLogger(t TL, c *Config) logr.Logger {
141116

142117
// Buffer stores log entries as formatted text and structured data.
143118
// It is safe to use this concurrently.
144-
//
145-
// # Experimental
146-
//
147-
// Notice: This interface is EXPERIMENTAL and may be changed or removed in a
148-
// later release.
149119
type Buffer interface {
150120
// String returns the log entries in a format that is similar to the
151121
// klog text output.
@@ -156,32 +126,17 @@ type Buffer interface {
156126
}
157127

158128
// Log contains log entries in the order in which they were generated.
159-
//
160-
// # Experimental
161-
//
162-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
163-
// later release.
164129
type Log []LogEntry
165130

166131
// DeepCopy returns a copy of the log. The error instance and key/value
167132
// pairs remain shared.
168-
//
169-
// # Experimental
170-
//
171-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
172-
// later release.
173133
func (l Log) DeepCopy() Log {
174134
log := make(Log, 0, len(l))
175135
log = append(log, l...)
176136
return log
177137
}
178138

179139
// LogEntry represents all information captured for a log entry.
180-
//
181-
// # Experimental
182-
//
183-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
184-
// later release.
185140
type LogEntry struct {
186141
// Timestamp stores the time when the log entry was created.
187142
Timestamp time.Time
@@ -214,38 +169,18 @@ type LogEntry struct {
214169

215170
// LogType determines whether a log entry was created with an Error or Info
216171
// call.
217-
//
218-
// # Experimental
219-
//
220-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
221-
// later release.
222172
type LogType string
223173

224174
const (
225175
// LogError is the special value used for Error log entries.
226-
//
227-
// Experimental
228-
//
229-
// Notice: This value is EXPERIMENTAL and may be changed or removed in
230-
// a later release.
231176
LogError = LogType("ERROR")
232177

233178
// LogInfo is the special value used for Info log entries.
234-
//
235-
// Experimental
236-
//
237-
// Notice: This value is EXPERIMENTAL and may be changed or removed in
238-
// a later release.
239179
LogInfo = LogType("INFO")
240180
)
241181

242182
// Underlier is implemented by the LogSink of this logger. It provides access
243183
// to additional APIs that are normally hidden behind the Logger API.
244-
//
245-
// # Experimental
246-
//
247-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
248-
// later release.
249184
type Underlier interface {
250185
// GetUnderlying returns the testing instance that logging goes to.
251186
// It returns nil when the test has completed already.

test/output.go

-27
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ limitations under the License.
1515
*/
1616

1717
// Package test contains a reusable unit test for logging output and behavior.
18-
//
19-
// # Experimental
20-
//
21-
// Notice: This package is EXPERIMENTAL and may be changed or removed in a
22-
// later release.
2318
package test
2419

2520
import (
@@ -48,11 +43,6 @@ import (
4843
//
4944
// The returned flag set has the klog flags registered. It can
5045
// be used to make further changes to the klog configuration.
51-
//
52-
// # Experimental
53-
//
54-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
55-
// later release.
5646
func InitKlog(tb testing.TB) *flag.FlagSet {
5747
state := klog.CaptureState()
5848
tb.Cleanup(state.Restore)
@@ -77,11 +67,6 @@ func InitKlog(tb testing.TB) *flag.FlagSet {
7767
}
7868

7969
// OutputConfig contains optional settings for Output.
80-
//
81-
// # Experimental
82-
//
83-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
84-
// later release.
8570
type OutputConfig struct {
8671
// NewLogger is called to create a new logger. If nil, output via klog
8772
// is tested. Support for -vmodule is optional. ClearLogger is called
@@ -553,12 +538,6 @@ var _, _, printWithKlogLine, _ = runtime.Caller(0) // anchor for finding the lin
553538
//
554539
// Loggers will be tested with direct calls to Info or
555540
// as backend for klog.
556-
//
557-
// # Experimental
558-
//
559-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
560-
// later release. The test cases and thus the expected output also may
561-
// change.
562541
func Output(t *testing.T, config OutputConfig) {
563542
for n, test := range tests {
564543
t.Run(n, func(t *testing.T) {
@@ -879,12 +858,6 @@ func Output(t *testing.T, config OutputConfig) {
879858
//
880859
// Loggers will be tested with direct calls to Info or
881860
// as backend for klog.
882-
//
883-
// # Experimental
884-
//
885-
// Notice: This function is EXPERIMENTAL and may be changed or removed in a
886-
// later release. The test cases and thus the expected output also may
887-
// change.
888861
func Benchmark(b *testing.B, config OutputConfig) {
889862
for n, test := range tests {
890863
b.Run(n, func(b *testing.B) {

test/zapr.go

-10
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ package test
1818

1919
// ZaprOutputMappingDirect provides a mapping from klog output to the
2020
// corresponding zapr output when zapr is called directly.
21-
//
22-
// # Experimental
23-
//
24-
// Notice: This package is EXPERIMENTAL and may be changed or removed in a
25-
// later release.
2621
func ZaprOutputMappingDirect() map[string]string {
2722
return map[string]string{
2823
`I output.go:<LINE>] "test" akey="<&>"
@@ -282,11 +277,6 @@ I output.go:<LINE>] "odd WithValues" keyWithoutValue="(MISSING)"
282277
// - zap drops keys with missing values, here we get "(MISSING)".
283278
// - zap does not de-duplicate key/value pairs, here klog does that
284279
// for it.
285-
//
286-
// # Experimental
287-
//
288-
// Notice: This package is EXPERIMENTAL and may be changed or removed in a
289-
// later release.
290280
func ZaprOutputMappingIndirect() map[string]string {
291281
mapping := ZaprOutputMappingDirect()
292282

0 commit comments

Comments
 (0)