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

Implement Docker healthcheck #4364

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

Conversation

noisersup
Copy link
Member

@noisersup noisersup commented Jun 14, 2024

Description

Closes #4246.

Readiness checklist

  • I added/updated unit tests (and they pass).
  • I added/updated integration/compatibility tests (and they pass).
  • I added/updated comments and checked rendering.
  • I made spot refactorings.
  • I updated user documentation.
  • I ran task all, and it passed.
  • I ensured that PR title is good enough for the changelog.
  • (for maintainers only) I set Reviewers (@FerretDB/core), Milestone (Next), Labels, Project and project's Sprint fields.
  • I marked all done items in this checklist.

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.04%. Comparing base (de509c5) to head (7c357b9).
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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

Flag Coverage Δ
filter-true 67.47% <ø> (-0.31%) ⬇️
hana-1 ?
integration 67.47% <ø> (-0.31%) ⬇️
mongodb-1 5.05% <ø> (+0.09%) ⬆️
postgresql-1 44.01% <ø> (+0.06%) ⬆️
postgresql-2 44.89% <ø> (-0.02%) ⬇️
postgresql-3 42.99% <ø> (-0.05%) ⬇️
postgresql-4 40.27% <ø> (+0.01%) ⬆️
postgresql-5 43.77% <ø> (-0.30%) ⬇️
sqlite-1 43.19% <ø> (+0.06%) ⬆️
sqlite-2 44.03% <ø> (+0.03%) ⬆️
sqlite-3 42.22% <ø> (-0.11%) ⬇️
sqlite-4 39.42% <ø> (+0.05%) ⬆️
sqlite-5 43.01% <ø> (-0.04%) ⬇️
unit 33.04% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@AlekSi AlekSi left a 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

Copy link
Contributor

mergify bot commented Jun 19, 2024

@noisersup this pull request has merge conflicts.

Copy link
Contributor

@chilagrow chilagrow left a 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.

Copy link
Member

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

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

Left some thoughts.


client, err := mongo.Connect(ctx, options.Client().ApplyURI(u))
if err != nil {
l.Fatal(err)
Copy link
Member

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 defers 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.


defer func() {
if err = client.Disconnect(ctx); err != nil {
l.Fatal(err)
Copy link
Member

@rumyantseva rumyantseva Jun 21, 2024

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.

@AlekSi AlekSi added the do not merge PRs that should not be merged label Jun 24, 2024
@AlekSi AlekSi removed the do not merge PRs that should not be merged label Jun 26, 2024
logUUID = ""
}

// It should be preffered for specific single commands/operations over setupLoggerWithStartupMsg.
Copy link
Member

Choose a reason for hiding this comment

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

That comment was ignored

}

if err = client.Ping(ctx, nil); err != nil {
l.Fatal(err)
Copy link
Member

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


u := &url.URL{
Scheme: "mongodb",
Host: fmt.Sprintf("%s:%s", host, port),
Copy link
Member

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 != "" {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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)
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 not log secrets (such as passwords) on level higher than debug

Copy link
Contributor

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?

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member

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)
Copy link
Contributor

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?

}

if err = client.Ping(ctx, nil); err != nil {
l.Fatal(err)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@chilagrow chilagrow left a 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)
Copy link
Contributor

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?

}

if err = client.Ping(ctx, nil); err != nil {
l.Fatal(err)
Copy link
Contributor

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.

@noisersup noisersup requested a review from chilagrow June 28, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/chore Code maintenance improvements
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Implement Docker's HEALTHCHECK
4 participants