-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reverse log level ordering for zap/otel-agent (#1102)
The zap log levels become more verbose as the log level decreases, which is the inverse of how our other log levels operate. This change reverses the order of our logLevel API when translating it to a zap log level. This is intended to create more consistent API behavior between the different containers. The default continues to be INFO, which maps to the integer value of 5 in our new scheme.
- Loading branch information
1 parent
bd28cd9
commit 83aa714
Showing
7 changed files
with
144 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
pkg/reconcilermanager/controllers/reconciler_container_log_level_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// 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 | ||
// | ||
// http://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. | ||
|
||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
"kpt.dev/configsync/pkg/api/configsync/v1beta1" | ||
"kpt.dev/configsync/pkg/metrics" | ||
) | ||
|
||
func TestMutateContainerLogLevelOtelAgent(t *testing.T) { | ||
testCases := map[string]struct { | ||
logLevel int | ||
expectedLevel string | ||
}{ | ||
"otel-agent with 0 log level": { | ||
logLevel: 0, | ||
expectedLevel: "fatal", | ||
}, | ||
"otel-agent with 1 log level": { | ||
logLevel: 1, | ||
expectedLevel: "panic", | ||
}, | ||
"otel-agent with 2 log level": { | ||
logLevel: 2, | ||
expectedLevel: "dpanic", | ||
}, | ||
"otel-agent with 3 log level": { | ||
logLevel: 3, | ||
expectedLevel: "error", | ||
}, | ||
"otel-agent with 4 log level": { | ||
logLevel: 4, | ||
expectedLevel: "warn", | ||
}, | ||
"otel-agent with 5 log level": { | ||
logLevel: 5, | ||
expectedLevel: "info", | ||
}, | ||
"otel-agent with 6 log level": { | ||
logLevel: 6, | ||
expectedLevel: "debug", | ||
}, | ||
"otel-agent with 7 log level": { | ||
logLevel: 7, | ||
expectedLevel: "debug", | ||
}, | ||
"otel-agent with 8 log level": { | ||
logLevel: 8, | ||
expectedLevel: "debug", | ||
}, | ||
"otel-agent with 9 log level": { | ||
logLevel: 9, | ||
expectedLevel: "debug", | ||
}, | ||
"otel-agent with 10 log level": { | ||
logLevel: 10, | ||
expectedLevel: "debug", | ||
}, | ||
} | ||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
container := &corev1.Container{ | ||
Name: metrics.OtelAgentName, | ||
} | ||
override := []v1beta1.ContainerLogLevelOverride{ | ||
{ | ||
ContainerName: metrics.OtelAgentName, | ||
LogLevel: tc.logLevel, | ||
}, | ||
} | ||
err := mutateContainerLogLevel(container, override) | ||
assert.NoError(t, err) | ||
expectedArgs := []string{fmt.Sprintf("--set=service.telemetry.logs.level=%s", tc.expectedLevel)} | ||
assert.Equal(t, expectedArgs, container.Args) | ||
}) | ||
} | ||
} |