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

Add Zap as the default error log in confighttp #11935

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

tarun-kavipurapu
Copy link

Description

This Issue Fixes the Issue #11820
This is a continuation pull request for #11830

Fixes #11820
-Made the Zap as the default ErrorLog Supplied to the Http server

@tarun-kavipurapu tarun-kavipurapu requested a review from a team as a code owner December 17, 2024 10:48
@dmathieu dmathieu changed the title Fix issue #11820 Add Zap as the default error log in confighttp Dec 17, 2024
.chloggen/zap-default-errorlog.yaml Outdated Show resolved Hide resolved
@@ -478,16 +480,18 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin
next: handler,
includeMetadata: hss.IncludeMetadata,
}
errorLog, err := zap.NewStdLogAt(settings.Logger, zapcore.ErrorLevel)
Copy link
Member

Choose a reason for hiding this comment

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

We should return errors as soon as they happen, not later.

Suggested change
errorLog, err := zap.NewStdLogAt(settings.Logger, zapcore.ErrorLevel)
errorLog, err := zap.NewStdLogAt(settings.Logger, zapcore.ErrorLevel)
if err != nil {
return nil, err
}

Copy link
Author

@tarun-kavipurapu tarun-kavipurapu Dec 17, 2024

Choose a reason for hiding this comment

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

the suggested change was the initial code too
but in
https://github.com/open-telemetry/opentelemetry-collector/pull/11830/files/71c16e0b293b4d6ed25146c4dd295093e672afd7#r1880527497
it was suggested to return server,err so that to avoid coverage report failures.

Copy link
Member

Choose a reason for hiding this comment

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

Then, how about something like:

server := &http.Server{
	Handler:           handler,
	ReadTimeout:       hss.ReadTimeout,
	ReadHeaderTimeout: hss.ReadHeaderTimeout,
	WriteTimeout:      hss.WriteTimeout,
	IdleTimeout:       hss.IdleTimeout,
}

errorLog, err := zap.NewStdLogAt(settings.Logger, zapcore.ErrorLevel)
if err != nil {
	return server, err
}

server.ErrorLog = errorLog
return server, nil

Then, we can handle multiple things that could return errors, and we also keep error return alongside its definition.

Copy link
Author

Choose a reason for hiding this comment

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

I will check the report locally and may be make the change according to it
the command for it is make gotest-with-cover right?

config/confighttp/confighttp.go Show resolved Hide resolved
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.59%. Comparing base (4fc50a8) to head (58267e5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11935   +/-   ##
=======================================
  Coverage   91.59%   91.59%           
=======================================
  Files         448      448           
  Lines       23759    23761    +2     
=======================================
+ Hits        21761    21763    +2     
  Misses       1623     1623           
  Partials      375      375           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tarun-kavipurapu
Copy link
Author

@dmathieu @dmitryax Hey any reason this is waiting to be merged i mean am i expected to make any changes?

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.

confighttp.ToServer should be setting ErrorLog
4 participants