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

Switch logging to go-kit #144

Merged
merged 5 commits into from Oct 22, 2019
Merged

Conversation

sowmiyamuthuraman
Copy link
Contributor

Fixes #141

@brian-brazil
Copy link
Contributor

Code looks good, can you add the DCO? Test failure looks like a CI issue, retrying.

@brian-brazil
Copy link
Contributor

Ah, you need to update the vendoring.

@sowmiyamuthuraman
Copy link
Contributor Author

@brian-brazil Thanks for the input! updated the vendoring and ammended to the same commit.

@simonpasquier
Copy link
Member

@sowmiyamuthuraman you need to update scripts/errcheck_excludes.txt to pass the CI (see here).

@simonpasquier
Copy link
Member

@sowmiyamuthuraman can you rebase on master and update the scripts/errcheck_excludes.txt file?

Signed-off-by: sowmiya <Sowmiyamuthuraman@gmail.com>
@sowmiyamuthuraman
Copy link
Contributor Author

@simonpasquier i resolved the conflicts and updated the scripts/errcheck_excludes.txt. Can you please help in passing the test?

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
@simonpasquier
Copy link
Member

I've pushed an update to your branch to fix the go.mod file and remove the .idea directory. Make sure you update your local directory.

Tests are failing because Exporter depends on the global logger instance which isn't set in the tests.
You need to add a log.Logger field to the Exporter struct and update NewExporter() accordingly. Then you can pass a log.NewNopLogger() in the tests.

Signed-off-by: sowmiyamuthuraman <sowmiyamuthuraman@gmail.com>
@sowmiyamuthuraman
Copy link
Contributor Author

I've pushed an update to your branch to fix the go.mod file and remove the .idea directory. Make sure you update your local directory.

Tests are failing because Exporter depends on the global logger instance which isn't set in the tests.
You need to add a log.Logger field to the Exporter struct and update NewExporter() accordingly. Then you can pass a log.NewNopLogger() in the tests.

Thanks, @simonpasquier. I have made the suggested changes and amended with the same commit

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

Good work! Just a few comments and it should be good to go.

@@ -170,6 +177,7 @@ func NewExporter(opts consulOpts, kvPrefix, kvFilter string, healthSummary bool)
kvPrefix: kvPrefix,
kvFilter: regexp.MustCompile(kvFilter),
healthSummary: healthSummary,
logger: log.NewLogfmtLogger(os.Stdout),
Copy link
Member

Choose a reason for hiding this comment

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

You should modify the NewExporter function to add a log.Logger parameter and pass it here.


func (l promHTTPLogger) Println(v ...interface{}) {
log.Error(v...)
level.Error(l.logger).Log("msg", v)
Copy link
Member

Choose a reason for hiding this comment

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

rather level.Error(l.logger).Log("msg", fmt.Sprintf(v))

@@ -441,7 +452,9 @@ func main() {
promhttp.HandlerFor(
prometheus.DefaultGatherer,
promhttp.HandlerOpts{
ErrorLog: &promHTTPLogger{},
ErrorLog: &promHTTPLogger{
logger: log.NewLogfmtLogger(os.Stderr),
Copy link
Member

Choose a reason for hiding this comment

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

logger instead of log.NewLogfmtLogger(os.Stderr)


exporter, err := NewExporter(opts, *kvPrefix, *kvFilter, *healthSummary)
if err != nil {
log.Fatalln(err)
level.Error(logger).Log("msg", "Error creating an exporter", "err", err)
Copy link
Member

Choose a reason for hiding this comment

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

(nit) Error creating the exporter

log.Infoln("Starting consul_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
level.Info(logger).Log("msg", "Starting consul_exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", version.BuildContext())
Copy link
Member

Choose a reason for hiding this comment

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

Arguments to Log() should always be even (key+value) so:

level.Info(logger).Log("build_context", version.BuildContext())

@@ -330,14 +338,14 @@ func (e *Exporter) collectHealthSummary(ch chan<- prometheus.Metric, serviceName
func (e *Exporter) collectOneHealthSummary(ch chan<- prometheus.Metric, serviceName string) {
// See https://github.com/hashicorp/consul/issues/1096.
if strings.HasPrefix(serviceName, "/") {
log.Warnf("Skipping service %q because it starts with a slash", serviceName)
level.Warn(e.logger).Log("msg", "Skipping service because it starts with a slash", "service name", serviceName)
Copy link
Member

Choose a reason for hiding this comment

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

"service name" -> "service_name"

Signed-off-by: sowmiyamuthuraman <sowmiyamuthuraman@gmail.com>

func (l promHTTPLogger) Println(v ...interface{}) {
log.Error(v...)
level.Error(l.logger).Log("msg", fmt.Sprintf("%v", v))
Copy link
Member

Choose a reason for hiding this comment

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

Sorry my previous comment was confusing, it should be level.Error(l.logger).Log("msg", fmt.Sprint(v...))

@simonpasquier
Copy link
Member

As #145 got merged, you'd need to rebase on master and adjust the changes. Sorry for the incovenience!

Signed-off-by: sowmiyamuthuraman <sowmiyamuthuraman@gmail.com>
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

👍

@simonpasquier simonpasquier merged commit b68117b into prometheus:master Oct 22, 2019
@simonpasquier
Copy link
Member

Thanks for the work!

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

Successfully merging this pull request may close these issues.

Switch logging to go-kit
3 participants