Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Fix prom-migrator version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
niconosenzo authored and cevian committed Apr 9, 2021
1 parent 4f6eb08 commit c8bd679
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 16 deletions.
22 changes: 22 additions & 0 deletions cmd/prom-migrator/main.go
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/timescale/promscale/pkg/migration-tool/reader"
"github.com/timescale/promscale/pkg/migration-tool/utils"
"github.com/timescale/promscale/pkg/migration-tool/writer"
"github.com/timescale/promscale/pkg/version"
)

const (
Expand Down Expand Up @@ -48,11 +49,19 @@ type config struct {

func main() {
conf := new(config)
args := os.Args[1:]
if shouldProceed := parseArgs(args); !shouldProceed {
os.Exit(0)
}

parseFlags(conf, os.Args[1:])

if err := log.Init(log.Config{Format: "logfmt", Level: "debug"}); err != nil {
fmt.Println("Version: ", version.PromMigrator)
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
log.Info("Version", version.PromMigrator)
if err := validateConf(conf); err != nil {
log.Error("msg", "could not parse flags", "error", err)
os.Exit(1)
Expand Down Expand Up @@ -169,6 +178,19 @@ func parseFlags(conf *config, args []string) {
convertSecFlagToMs(conf)
}

func parseArgs(args []string) (shouldProceed bool) {
shouldProceed = true // Some flags like 'version' are just to get information and not proceed the actual execution. We should stop in such cases.
for _, flag := range args {
flag = flag[1:]
switch flag {
case "version":
shouldProceed = false
fmt.Println(version.PromMigrator)
}
}
return
}

func convertSecFlagToMs(conf *config) {
// remote-storages tend to respond to time in milliseconds. So, we convert the received values in seconds to milliseconds.
conf.mint = conf.mintSec * 1000
Expand Down
4 changes: 2 additions & 2 deletions cmd/promscale/main.go
Expand Up @@ -21,13 +21,13 @@ func main() {
cfg := &runner.Config{}
cfg, err := runner.ParseFlags(cfg, args)
if err != nil {
fmt.Println("Version: ", version.Version, "Commit Hash: ", version.CommitHash)
fmt.Println("Version: ", version.Promscale, "Commit Hash: ", version.CommitHash)
fmt.Println("Fatal error: cannot parse flags: ", err)
os.Exit(1)
}
err = log.Init(cfg.LogCfg)
if err != nil {
fmt.Println("Version: ", version.Version, "Commit Hash: ", version.CommitHash)
fmt.Println("Version: ", version.Promscale, "Commit Hash: ", version.CommitHash)
fmt.Println("Fatal error: cannot start logger: ", err)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pgclient/config.go
Expand Up @@ -54,7 +54,7 @@ const (
)

var (
DefaultApp = fmt.Sprintf("promscale@%s", version.Version)
DefaultApp = fmt.Sprintf("promscale@%s", version.Promscale)
excessDBFlagsError = fmt.Errorf("failed to build DB credentials with provided flags. Please use either db flags or db-uri not both")
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/args.go
Expand Up @@ -18,7 +18,7 @@ func ParseArgs(args []string) (shouldProceed bool) {
switch flag {
case "version":
shouldProceed = false
fmt.Println(version.Version)
fmt.Println(version.Promscale)
}
}
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/client.go
Expand Up @@ -22,7 +22,7 @@ import (
)

var (
appVersion = pgmodel.VersionInfo{Version: version.Version, CommitHash: version.CommitHash}
appVersion = pgmodel.VersionInfo{Version: version.Promscale, CommitHash: version.CommitHash}
migrationLockError = fmt.Errorf("Could not acquire migration lock. Ensure there are no other connectors running and try again.")
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/runner.go
Expand Up @@ -29,7 +29,7 @@ var (
)

func Run(cfg *Config) error {
log.Info("msg", "Version:"+version.Version+"; Commit Hash: "+version.CommitHash)
log.Info("msg", "Version:"+version.Promscale+"; Commit Hash: "+version.CommitHash)
log.Info("config", util.MaskPassword(fmt.Sprintf("%+v", cfg)))

if cfg.APICfg.ReadOnly {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/end_to_end_tests/main_test.go
Expand Up @@ -227,7 +227,7 @@ func performMigrate(t testing.TB, connectURL string, superConnectURL string) {
t.Fatal(err)
}
defer conn.Release()
err = runner.SetupDBState(conn.Conn(), pgmodel.VersionInfo{Version: version.Version, CommitHash: "azxtestcommit"}, nil, extOptions)
err = runner.SetupDBState(conn.Conn(), pgmodel.VersionInfo{Version: version.Promscale, CommitHash: "azxtestcommit"}, nil, extOptions)
if err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/tests/end_to_end_tests/migrate_test.go
Expand Up @@ -33,8 +33,8 @@ func TestMigrate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if dbVersion != version.Version {
t.Errorf("Version unexpected:\ngot\n%s\nwanted\n%s", dbVersion, version.Version)
if dbVersion != version.Promscale {
t.Errorf("Version unexpected:\ngot\n%s\nwanted\n%s", dbVersion, version.Promscale)
}

readOnly := testhelpers.GetReadOnlyConnection(t, *testDatabase)
Expand All @@ -44,7 +44,7 @@ func TestMigrate(t *testing.T) {
t.Fatal(err)
}
defer conn.Release()
err = pgmodel.CheckDependencies(conn.Conn(), pgmodel.VersionInfo{Version: version.Version}, false, extOptions)
err = pgmodel.CheckDependencies(conn.Conn(), pgmodel.VersionInfo{Version: version.Promscale}, false, extOptions)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -232,8 +232,8 @@ func TestMigrateTwice(t *testing.T) {
t.Fatal(err)
}

if versionString != version.Version {
t.Fatalf("wrong version, expected %v got %v", version.Version, versionString)
if versionString != version.Promscale {
t.Fatalf("wrong version, expected %v got %v", version.Promscale, versionString)
}
}
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/tests/upgrade_tests/upgrade_test.go
Expand Up @@ -342,9 +342,9 @@ func withDBStartingAtOldVersionAndUpgrading(

defer func() { _ = closer.Close() }()

t.Logf("upgrading versions %v => %v", prevVersion, version.Version)
t.Logf("upgrading versions %v => %v", prevVersion, version.Promscale)
connectURL := testhelpers.PgConnectURL(*testDatabase, testhelpers.NoSuperuser)
migrateToVersion(t, connectURL, version.Version, "azxtestcommit")
migrateToVersion(t, connectURL, version.Promscale, "azxtestcommit")

if extensionState.UsesMultinode() {
//add a node after upgrade; this tests strictly more functionality since we already have one node set up before
Expand Down Expand Up @@ -386,7 +386,7 @@ func withNewDBAtCurrentVersion(t testing.TB, DBName string, extensionState testh

defer func() { _ = closer.Close() }()
testhelpers.WithDB(t, DBName, testhelpers.NoSuperuser, true, extensionState, func(_ *pgxpool.Pool, t testing.TB, connectURL string) {
migrateToVersion(t, connectURL, version.Version, "azxtestcommit")
migrateToVersion(t, connectURL, version.Promscale, "azxtestcommit")

// need to get a new pool after the Migrate to catch any GUC changes made during Migrate
db, err := pgxpool.Connect(context.Background(), connectURL)
Expand Down
3 changes: 2 additions & 1 deletion pkg/version/version.go
Expand Up @@ -37,7 +37,8 @@ var (
// since an app version must uniquely determine the state of the schema.
// It is customary to bump the version by incrementing the numeral after
// the `dev` tag. The SQL migration script name must correspond to the /new/ version.
Version = "0.3.1-dev.0"
Promscale = "0.3.1-dev.0"
PromMigrator = "0.0.1-beta.2"
CommitHash = ""
EarliestUpgradeTestVersion = "0.1.0"
EarliestUpgradeTestVersionMultinode = "0.1.4" //0.1.4 earliest version that supports tsdb 2.0
Expand Down

0 comments on commit c8bd679

Please sign in to comment.