-
Notifications
You must be signed in to change notification settings - Fork 378
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
Implement Docker healthcheck #4364
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4364 +/- ##
==========================================
- Coverage 74.31% 74.04% -0.28%
==========================================
Files 323 323
Lines 22364 22398 +34
==========================================
- Hits 16620 16584 -36
- Misses 4563 4607 +44
- Partials 1181 1207 +26 see 12 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are merge conflicts now
@noisersup this pull request has merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments from @AlekSi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some thoughts.
cmd/ferretdb/ping.go
Outdated
|
||
client, err := mongo.Connect(ctx, options.Client().ApplyURI(u)) | ||
if err != nil { | ||
l.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a tricky thing about logs of Fatal level. Fatal causes os.Exit
which means that defer
s won't be executed. In this particular case, let's say we have two items in the urls
slice. Let's say the first item was connected successfully. Disconnect of this item is deferred. Let's say the second item's connection failed here. This defer from the first item will never be called.
So, we either shouldn't defer disconnect (e.g. we can disconnect right after ping) or we shouldn't use Fatal.
cmd/ferretdb/ping.go
Outdated
|
||
defer func() { | ||
if err = client.Disconnect(ctx); err != nil { | ||
l.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here about defers. If more than one things were deferred, the first defer's execution will call os.Exit in case of failure, and the second one won't be executed.
cmd/ferretdb/main.go
Outdated
logUUID = "" | ||
} | ||
|
||
// It should be preffered for specific single commands/operations over setupLoggerWithStartupMsg. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comment was ignored
cmd/ferretdb/ping.go
Outdated
} | ||
|
||
if err = client.Ping(ctx, nil); err != nil { | ||
l.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, process termination might not close all TCP connections properly in some configurations. We have to call client.Disconnect
before checking ping result
cmd/ferretdb/ping.go
Outdated
|
||
u := &url.URL{ | ||
Scheme: "mongodb", | ||
Host: fmt.Sprintf("%s:%s", host, port), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
net.JoinHostPort
|
||
var urls []string | ||
|
||
if cli.Listen.Addr != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about cli.Listen.TLS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we want to implement it? We don't store CA key anywhere to sign temporary client certificate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a temporary client certificate?.. Starting FerretDB with TLS requires passing all needed TLS files that we can use.
If your question is about "Extended Key Usage", I think we can safely ignore it, at least for now
l.Fatal(err) | ||
} | ||
|
||
l.Infof("Ping to %s successful.", u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not log secrets (such as passwords) on level higher than debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is one too many log I think it was commented before, at the moment see for listen addr
l.Debugf("--listen-addr flag is set. Ping to %s will be performed.", cli.Listen.Addr)
l.Debugf("Pinging %s...", u)
l.Infof("Ping to %s successful.", u)
Can we have one for starting such as Pinging blah blah...
and one for success such as Ping success blah blah
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chilagrow #4364 (comment)
I will send a PR codifying that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlekSi Oops, fixed
@chilagrow 2 of the lines you mentioned are only displayed in the debug mode. Normally (on the Info level) we only log the ping success, or when no ping is executed - the skip message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we avoid displaying password even in debug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, everything is a fair game on debug level. First, all information is needed for debugging. Second, we log full requests and responses on debug level that are much more secret than anything else, as they contain actual user data.
l.Fatal(err) | ||
} | ||
|
||
l.Infof("Ping to %s successful.", u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is one too many log I think it was commented before, at the moment see for listen addr
l.Debugf("--listen-addr flag is set. Ping to %s will be performed.", cli.Listen.Addr)
l.Debugf("Pinging %s...", u)
l.Infof("Ping to %s successful.", u)
Can we have one for starting such as Pinging blah blah...
and one for success such as Ping success blah blah
?
cmd/ferretdb/ping.go
Outdated
} | ||
|
||
if err = client.Ping(ctx, nil); err != nil { | ||
l.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a helpful message, logger.Fatal("Ping failed", zap.Error(err))
. All other places too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I got my idea across, see this PR noisersup#5 of what I mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I didn't get across what I meant about comments related to logging. Codified the suggestion noisersup#5
l.Fatal(err) | ||
} | ||
|
||
l.Infof("Ping to %s successful.", u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we avoid displaying password even in debug?
cmd/ferretdb/ping.go
Outdated
} | ||
|
||
if err = client.Ping(ctx, nil); err != nil { | ||
l.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I got my idea across, see this PR noisersup#5 of what I mean.
Description
Closes #4246.
Readiness checklist
task all
, and it passed.@FerretDB/core
), Milestone (Next
), Labels, Project and project's Sprint fields.