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

Fix metrics logging error; Remove version log #168

Merged
merged 2 commits into from
Dec 27, 2023
Merged

Conversation

jdn5126
Copy link
Contributor

@jdn5126 jdn5126 commented Dec 26, 2023

Issue #, if available:
#103
#49

Description of changes:
This PR fixes two issues:

  1. The metrics server runs in a goroutine. Logging was broken in the metrics server because the call stack was starting at -2 when it needed to start at 0. This PR instantiates a new logger in the metrics goroutine and resolves UTC Logger.check error: failed to get caller #103
  2. During init, the agent was trying to log version information. This information is not properly set, leading to Build info in logs is empty #49. This PR removes that log, as the image tag is sufficient to determine version.

New log looks like:

% kubectl logs -n kube-system aws-node-57t4f -c aws-eks-nodeagent
{"level":"info","ts":"2023-12-26T20:57:29.306Z","caller":"metrics/metrics.go:23","msg":"Serving metrics on ","port":61680}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -56,11 +55,6 @@ func init() {

func main() {
initLogger, _ := getLoggerWithLogLevel("info", "")
initLogger.Info("version",
"GitVersion", version.GitVersion,
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah we never rebuild the same tag so just the tag should be sufficient to identify the commit..

Copy link
Contributor

@jayanthvn jayanthvn left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -135,6 +129,6 @@ func loadControllerConfig() (config.ControllerConfig, error) {

// getLoggerWithLogLevel returns logger with specific log level.
func getLoggerWithLogLevel(logLevel string, logFilePath string) (logr.Logger, error) {
ctrlLogger := logger.New(logLevel, logFilePath)
ctrlLogger := logger.New(logLevel, logFilePath, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: later we can move the logger defaults of 0,1,2..to utils as enum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I considered an enum, but could not come up with any names that make sense, as the value to use is dependent on where the logger will be called from. If you are within a goroutine function, you want 0, as above is the standard library runtime. If you are within the controller handle routines, you want 2, as you want to skip the controller call stack surrounding the function

@@ -43,3 +45,8 @@ func setupMetricsServer() *http.Server {
}
return server
}

func getMetricsLogger() logr.Logger {
ctrlLogger := logger.New("info", "", 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Same as above..this can be a util enum..but can take it up as followup..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UTC Logger.check error: failed to get caller
2 participants