-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat(upgrade): extending upgrade command skeleton #19641
Conversation
As requested in the last comment of #19308 interactive mode will be added, but comments to actual code are welcome |
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.
This is much easier to review, thank you!
cmd/influxd/upgrade/config.go
Outdated
"go.uber.org/zap" | ||
) | ||
|
||
// Backups existing config file and updates it with upgraded config. |
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.
Per Effective Go, the convention for function doc commentary is to start the help string with the name of the function:
Doc comments work best as complete sentences, which allow a wide variety of automated presentations. The first sentence should be a one-sentence summary that starts with the name being declared.
// upgradeConfig will backup the existing config file...
) | ||
|
||
// Generates security upgrade script. | ||
func generateSecurityScript(v1 *influxDBv1, dbBuckets map[string][]string, log *zap.Logger) error { |
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, start the doc comment with the name of the function
cmd/influxd/upgrade/upgrade.go
Outdated
if runtime.GOOS == "windows" { | ||
defaultSsPath = filepath.Join(homeOrAnyDir(), "influxd-upgrade-security.cmd") | ||
} else { | ||
defaultSsPath = filepath.Join(homeOrAnyDir(), "influxd-upgrade-security.sh") | ||
} |
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 are skipping windows for now, so I would not add any additional complexity to support it
cmd/influxd/upgrade/upgrade.go
Outdated
if err != nil { | ||
return err | ||
} | ||
log.Info("starting InfluxDB 1.x upgrade") |
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.
nit: Log messages should be complete sentences and start with a capital. Please see the logging style guide
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.
Ok, thanks for the info about the log guide. I don't remember where I got the wrong idea about starting with lower case.
cmd/influxd/upgrade/upgrade.go
Outdated
if err != nil { | ||
//remove all files | ||
log.Info("database upgrade error, removing data") |
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.
nit: Log messages should be complete sentences and start with a capital. Please see the logging style guide
cmd/influxd/upgrade/upgrade.go
Outdated
// 3. create database in v2.meta | ||
// v2.meta.CreateDatabase(newBucket.ID.String()) | ||
// copy shard info from v1.meta | ||
log.Info("upgrade successfully completed. Start service now") |
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.
nit: Log messages should be complete sentences and start with a capital. Please see the logging style guide
65b5c74
to
34ba3de
Compare
@vlastahajek golint is failing due to the following:
|
8dcb236
to
bc37576
Compare
@stuartcarnie, I'm sorry, in the flood of emails about failed e2e tests I missed the one about build :(. It's fixed now. |
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.
This is much closer!
cmd/influx/bucket.go
Outdated
@@ -3,6 +3,7 @@ package main | |||
import ( | |||
"context" | |||
"fmt" | |||
internal2 "github.com/influxdata/influxdb/v2/internal" |
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.
nit: There is no reason to alias this to internal2
as there are no conflicts
cmd/influx/secret.go
Outdated
@@ -3,6 +3,7 @@ package main | |||
import ( | |||
"context" | |||
"fmt" | |||
internal2 "github.com/influxdata/influxdb/v2/internal" |
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.
nit: no reason to alias this to internal2
as there are no conflicts.
cmd/influx/setup.go
Outdated
@@ -4,18 +4,19 @@ import ( | |||
"context" | |||
"errors" | |||
"fmt" | |||
|
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.
nit: remove space and run goimports -w
internal/input.go
Outdated
@@ -0,0 +1,206 @@ | |||
package internal |
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.
Given these functions are only used by the cmd
package, I'd prefer these be moved to
cmd/internal
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.
ok
internal/input.go
Outdated
case input.ErrInterrupted: | ||
os.Exit(1) | ||
case errPasswordIsTooShort: | ||
ui.Writer.Write(PromptWithColor("Password too short - minimum length is 8 characters!\n\r", ColorRed)) |
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.
nit: no need to add exclamation at the end: !
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.
ok, This came from original cmd/influx/setup.go :)
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 figured it probably did 👍
cmd/influxd/upgrade/upgrade_test.go
Outdated
"path/filepath" | ||
"testing" | ||
|
||
"github.com/docker/docker/pkg/testutil/assert" |
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.
To avoid the proliferation of differing assert
packages, please use stretchr/testify/assert
"github.com/docker/docker/pkg/testutil/assert" | |
"github.com/stretchr/testify/assert" |
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.
This, accidental import, no intention :(
cmd/influxd/upgrade/upgrade_test.go
Outdated
if err := cmd.Execute(); err == nil { | ||
t.Fatal("Must fail") | ||
} else { | ||
assert.Contains(t, err.Error(), "1.x metadb error") | ||
} |
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.
You can additionally import "github.com/stretchr/testify/require" and then use:
if err := cmd.Execute(); err == nil { | |
t.Fatal("Must fail") | |
} else { | |
assert.Contains(t, err.Error(), "1.x metadb error") | |
} | |
err = cmd.Execute() | |
require.Error(t, err) | |
assert.Contains(t, err.Error(), "1.x metadb error") |
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.
Well, I'm a bit confused from the InfluxDB tests code style. I've seen a lot of tests that prefer to use this than the require package. But, great, I personally like the require package. 👍
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.
@vlastahajek there is a difference between require
and assert
.
When a require
condition fails, the test will abort. When an assert
condition fails, it will fail the test but continue execution. To put it another way, require
is like t.Fatal
and assert
is like t.Error
.
It is clear here, that we require an error and then following that we assert the error is the correct value.
If instead we wrote:
assert.Error(t, err)
assert.Contains(t, err.Error(), "1.x metadb error")
This test code would potentially panic on the assert.Contains
line because err
is nil
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.
Yes, I know. I use require in the influxdb-client-go tests heavy . I just felt that the server basic test style doesn't use require.
cmd/influxd/upgrade/upgrade_test.go
Outdated
if err != nil { | ||
t.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.
nit: use require
package:
if err != nil { | |
t.Fatal(err) | |
} | |
require.NoError(t, err) |
cmd/influxd/upgrade/upgrade_test.go
Outdated
if err != nil { | ||
t.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.
nit: use require package
2a000ac
to
ce531b0
Compare
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.
Looks good – thanks for breaking this down!
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.
e2e
tests are failing as a required import was removed from influxd/main.go
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.
Everything is passing and it looks good 👍
@vlastahajek you will need to rebase this before I can merge it |
@stuartcarnie, the goal is to have a clean commit history? |
@vlastahajek yes and you will need to resolve whatever merge conflicts have arisen |
b12c2a4
to
ea8f608
Compare
This PR is 1st of 4 upgrade feature PRs and prepares common code for others.
Mainly introduces cli interface and options checks.
Minimal command line includes parameters for creating admin:
influxd upgrade -b my-bucket -o my-org -u my-user -p my-password
. If at least one of those options are not set, the interactive mode is launched and user is asked for entering values of missing options.Complete help:
V1 and v2 dump commands are also extended about more info.