mirror of https://github.com/knative/pkg.git
Drop the fixed list of `knative/serving` components from logging. (#22)
This commit is contained in:
parent
8b7b2d7cfb
commit
9d1975b29f
|
@ -96,14 +96,15 @@ type Config struct {
|
||||||
LoggingLevel map[string]zapcore.Level
|
LoggingLevel map[string]zapcore.Level
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigFromMap creates a LoggingConfig from the supplied map
|
// NewConfigFromMap creates a LoggingConfig from the supplied map,
|
||||||
func NewConfigFromMap(data map[string]string) (*Config, error) {
|
// expecting the given list of components.
|
||||||
|
func NewConfigFromMap(data map[string]string, components ...string) (*Config, error) {
|
||||||
lc := &Config{}
|
lc := &Config{}
|
||||||
if zlc, ok := data["zap-logger-config"]; ok {
|
if zlc, ok := data["zap-logger-config"]; ok {
|
||||||
lc.LoggingConfig = zlc
|
lc.LoggingConfig = zlc
|
||||||
}
|
}
|
||||||
lc.LoggingLevel = make(map[string]zapcore.Level)
|
lc.LoggingLevel = make(map[string]zapcore.Level)
|
||||||
for _, component := range []string{"controller", "queueproxy", "webhook", "activator", "autoscaler"} {
|
for _, component := range components {
|
||||||
if ll, ok := data["loglevel."+component]; ok {
|
if ll, ok := data["loglevel."+component]; ok {
|
||||||
if len(ll) > 0 {
|
if len(ll) > 0 {
|
||||||
level, err := levelFromString(ll)
|
level, err := levelFromString(ll)
|
||||||
|
@ -117,9 +118,10 @@ func NewConfigFromMap(data map[string]string) (*Config, error) {
|
||||||
return lc, nil
|
return lc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigFromConfigMap creates a LoggingConfig from the supplied ConfigMap
|
// NewConfigFromConfigMap creates a LoggingConfig from the supplied ConfigMap,
|
||||||
func NewConfigFromConfigMap(configMap *corev1.ConfigMap) (*Config, error) {
|
// expecting the given list of components.
|
||||||
return NewConfigFromMap(configMap.Data)
|
func NewConfigFromConfigMap(configMap *corev1.ConfigMap, components ...string) (*Config, error) {
|
||||||
|
return NewConfigFromMap(configMap.Data, components...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func levelFromString(level string) (*zapcore.Level, error) {
|
func levelFromString(level string) (*zapcore.Level, error) {
|
||||||
|
@ -132,9 +134,10 @@ func levelFromString(level string) (*zapcore.Level, error) {
|
||||||
|
|
||||||
// UpdateLevelFromConfigMap returns a helper func that can be used to update the logging level
|
// UpdateLevelFromConfigMap returns a helper func that can be used to update the logging level
|
||||||
// when a config map is updated
|
// when a config map is updated
|
||||||
func UpdateLevelFromConfigMap(logger *zap.SugaredLogger, atomicLevel zap.AtomicLevel, levelKey string) func(configMap *corev1.ConfigMap) {
|
func UpdateLevelFromConfigMap(logger *zap.SugaredLogger, atomicLevel zap.AtomicLevel,
|
||||||
|
levelKey string, components ...string) func(configMap *corev1.ConfigMap) {
|
||||||
return func(configMap *corev1.ConfigMap) {
|
return func(configMap *corev1.ConfigMap) {
|
||||||
loggingConfig, err := NewConfigFromConfigMap(configMap)
|
loggingConfig, err := NewConfigFromConfigMap(configMap, components...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Failed to parse the logging configmap. Previous config map will be used.", zap.Error(err))
|
logger.Error("Failed to parse the logging configmap. Previous config map will be used.", zap.Error(err))
|
||||||
return
|
return
|
||||||
|
|
|
@ -191,7 +191,7 @@ func TestInvalidLevel(t *testing.T) {
|
||||||
"zap-logger-config": wantCfg,
|
"zap-logger-config": wantCfg,
|
||||||
"loglevel.queueproxy": "invalid",
|
"loglevel.queueproxy": "invalid",
|
||||||
},
|
},
|
||||||
})
|
}, "queueproxy")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected errors. got nothing")
|
t.Errorf("Expected errors. got nothing")
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ func getTestConfig() (*Config, string, string) {
|
||||||
"zap-logger-config": wantCfg,
|
"zap-logger-config": wantCfg,
|
||||||
"loglevel.queueproxy": wantLevel,
|
"loglevel.queueproxy": wantLevel,
|
||||||
},
|
},
|
||||||
})
|
}, "queueproxy")
|
||||||
return c, wantCfg, wantLevel
|
return c, wantCfg, wantLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ func TestUpdateLevelFromConfigMap(t *testing.T) {
|
||||||
{"debug", zapcore.DebugLevel},
|
{"debug", zapcore.DebugLevel},
|
||||||
}
|
}
|
||||||
|
|
||||||
u := UpdateLevelFromConfigMap(logger, atomicLevel, "controller")
|
u := UpdateLevelFromConfigMap(logger, atomicLevel, "controller", "controller")
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
cm.Data["loglevel.controller"] = tt.setLevel
|
cm.Data["loglevel.controller"] = tt.setLevel
|
||||||
u(cm)
|
u(cm)
|
||||||
|
|
Loading…
Reference in New Issue