Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update log level to run tests on debug level #5071

Merged
merged 3 commits into from Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/verify-codegen.sh
Expand Up @@ -43,7 +43,7 @@ cp -a "${REPO_ROOT_DIR}/config"/* "${TMP_DIFFROOT}/config"
"${REPO_ROOT_DIR}/hack/update-codegen.sh"
echo "Diffing ${REPO_ROOT_DIR} against freshly generated codegen"
ret=0
diff -Nupr "${REPO_ROOT_DIR}/pkg" "${TMP_DIFFROOT}/pkg" || ret=1
diff -Nupr --no-dereference "${REPO_ROOT_DIR}/pkg" "${TMP_DIFFROOT}/pkg" || ret=1
diff -Nupr --no-dereference "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1

# Restore working tree state
Expand Down
56 changes: 54 additions & 2 deletions pkg/logging/config_test.go
Expand Up @@ -19,17 +19,19 @@ package logging
import (
"testing"

"github.com/google/go-cmp/cmp"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
. "knative.dev/pkg/configmap/testing"
"knative.dev/pkg/logging"
"knative.dev/pkg/system"
_ "knative.dev/pkg/system/testing"

. "knative.dev/pkg/configmap/testing"
)

const testConfigFileName = "test-config-logging"

func TestNewConfigNoEntry(t *testing.T) {
c, err := logging.NewConfigFromConfigMap(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -93,6 +95,56 @@ func TestOurConfig(t *testing.T) {
}
}

func TestLogLevelTestConfig(t *testing.T) {
const wantCfg = `{
"level": "debug",
"development": false,
"outputPaths": ["stdout"],
"errorOutputPaths": ["stderr"],
"encoding": "json",
"encoderConfig": {
"timeKey": "ts",
"levelKey": "level",
"nameKey": "logger",
"callerKey": "caller",
"messageKey": "msg",
"stacktraceKey": "stacktrace",
"lineEnding": "",
"levelEncoder": "",
"timeEncoder": "iso8601",
"durationEncoder": "",
"callerEncoder": ""
}
}
`
const wantLevel = zapcore.DebugLevel
components := []string{
"autoscaler",
"controller",
"queueproxy",
"webhook",
"activator",
}
cm, _ := ConfigMapsFromTestFile(t, testConfigFileName, "loglevel.autoscaler", "loglevel.controller", "loglevel.queueproxy", "loglevel.webhook", "loglevel.activator", "zap-logger-config")
cfg, err := logging.NewConfigFromConfigMap(cm)

if err != nil {
t.Errorf("Expected no errors. got: %v", err)
}
if cfg == nil {
t.Errorf("NewConfigFromConfigMap(actual) = %v, want non-nil", cfg)
}

for _, c := range components {
if got := cfg.LoggingLevel[c]; got != wantLevel {
t.Errorf("LoggingLevel[%q] = %v, want %v", c, got, wantLevel)
}
}
if got := cfg.LoggingConfig; got != wantCfg {
t.Errorf("LoggingConfig = %v, want %v, diff(-want +got) %s", got, wantCfg, cmp.Diff(wantCfg, got))
}
}

func TestNewLoggerFromConfig(t *testing.T) {
c, _, _ := getTestConfig()
_, atomicLevel := logging.NewLoggerFromConfig(c, "queueproxy")
Expand Down
1 change: 1 addition & 0 deletions pkg/logging/testdata/test-config-logging.yaml
103 changes: 103 additions & 0 deletions test/config/config-logging.yaml
@@ -0,0 +1,103 @@
# Copyright 2019 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
name: config-logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for the main file, we symlink it under testdata and validate it's content in a Go test. Can we do the same here to validate changes? Otherwise this looks good to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattmoor Sounds good. Should it be a new test under test/? Which package should it belong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just put it right next to where we test the real config (same test, second symlink)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattmoor sounds good! Just added the test and symlink

namespace: knative-serving
labels:
serving.knative.dev/release: devel

data:
_example: |
################################
# #
# EXAMPLE CONFIGURATION #
# #
################################

# This block is not actually functional configuration,
# but serves to illustrate the available configuration
# options and document them in a way that is accessible
# to users that `kubectl edit` this config map.
#
# These sample configuration options may be copied out of
# this example block and unindented to be in the data block
# to actually change the configuration.

# Common configuration for all Knative codebase
zap-logger-config: |
{
"level": "info",
"development": false,
"outputPaths": ["stdout"],
"errorOutputPaths": ["stderr"],
"encoding": "json",
"encoderConfig": {
"timeKey": "ts",
"levelKey": "level",
"nameKey": "logger",
"callerKey": "caller",
"messageKey": "msg",
"stacktraceKey": "stacktrace",
"lineEnding": "",
"levelEncoder": "",
"timeEncoder": "iso8601",
"durationEncoder": "",
"callerEncoder": ""
}
}

# Log level overrides
# For all components except the autoscaler and queue proxy,
# changes are be picked up immediately.
# For autoscaler and queue proxy, changes require recreation of the pods.
loglevel.controller: "info"
loglevel.autoscaler: "info"
loglevel.queueproxy: "info"
loglevel.webhook: "info"
loglevel.activator: "info"

zap-logger-config: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can leave this out entirely to pick up the default? Not entirely sure though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried applying this yaml without this block and the zap-logger-config was not set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewConfigFromConfigMap function will not pick up logging config without zap-logger-config key. @markusthoemmes were you talking about labels or the zap-logger-config key?

cc @andrew-su

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought was that we'd only need the specific loglevels below and that the broader loggingconfig would be defaulted in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If both are kubectl applied, then applying this without it will strip it in the three way merge.

{
"level": "debug",
"development": false,
"outputPaths": ["stdout"],
"errorOutputPaths": ["stderr"],
"encoding": "json",
"encoderConfig": {
"timeKey": "ts",
"levelKey": "level",
"nameKey": "logger",
"callerKey": "caller",
"messageKey": "msg",
"stacktraceKey": "stacktrace",
"lineEnding": "",
"levelEncoder": "",
"timeEncoder": "iso8601",
"durationEncoder": "",
"callerEncoder": ""
}
}

# Log level overrides
# For all components except the autoscaler and queue proxy,
# changes are be picked up immediately.
# For autoscaler and queue proxy, changes require recreation of the pods.
loglevel.controller: "debug"
loglevel.autoscaler: "debug"
loglevel.queueproxy: "debug"
loglevel.webhook: "debug"
loglevel.activator: "debug"