From 511d49c88204e91962cc4cf3cbae63b7d1a3e587 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Tue, 7 Aug 2018 15:51:53 +0200 Subject: [PATCH 01/11] add advertised endpoint to cluster / active fo --- CHANGELOG.md | 2 ++ main.go | 4 +++- service/arangod_config_builder.go | 11 +++++++++++ service/service.go | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57684e25..fe643fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changed from version 0.12.0 to master +- Added advertised endpoint to coordinators and active fo + - Database upgrade procedure has changed. It is now much more automated and can be triggered using an `arangodb upgrade --starter.endpoint=...` command. diff --git a/main.go b/main.go index cfd99f50..0b027455 100644 --- a/main.go +++ b/main.go @@ -86,6 +86,7 @@ var ( logService logging.Service showVersion bool id string + advertisedEndpoint string agencySize int arangodPath string arangodJSPath string @@ -192,7 +193,7 @@ func init() { pf.StringVar(&logDir, "log.dir", getEnvVar("LOG_DIR", ""), "Custom log file directory.") f.IntVar(&logRotateFilesToKeep, "log.rotate-files-to-keep", defaultLogRotateFilesToKeep, "Number of files to keep when rotating log files") f.DurationVar(&logRotateInterval, "log.rotate-interval", defaultLogRotateInterval, "Time between log rotations (0 disables log rotation)") - + f.StringVar(&advertisedEndpoint, "cluster.advertised-endpoint", "", "An external endpoint for this cluster") f.IntVar(&agencySize, "cluster.agency-size", 3, "Number of agents in the cluster") f.BoolSliceVar(&startAgent, "cluster.start-agent", nil, "should an agent instance be started") f.BoolSliceVar(&startDBserver, "cluster.start-dbserver", nil, "should a dbserver instance be started") @@ -707,6 +708,7 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo ArangodPath: arangodPath, ArangoSyncPath: arangoSyncPath, ArangodJSPath: arangodJSPath, + AdvertisedEndpoint: advertisedEndpoint, MasterPort: masterPort, RrPath: rrPath, DataDir: dataDir, diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index 1e9cca56..24c63c84 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -202,6 +202,11 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC optionPair{"--foxx.queues", "true"}, optionPair{"--server.statistics", "true"}, ) + if config.AdvertisedEndpoint != "" { + options = append(options, + optionPair{"--cluster.my-advertised-endpoint", config.AdvertisedEndpoint}, + ) + } case ServerTypeSingle: options = append(options, optionPair{"--foxx.queues", "true"}, @@ -209,12 +214,18 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC ) case ServerTypeResilientSingle: options = append(options, + optionPair{"--cluster.my-advertised-endpoint", config.AdvertisedEndpoint}, optionPair{"--foxx.queues", "true"}, optionPair{"--server.statistics", "true"}, optionPair{"--replication.automatic-failover", "true"}, optionPair{"--cluster.my-address", myTCPURL}, optionPair{"--cluster.my-role", "SINGLE"}, ) + if config.AdvertisedEndpoint != "" { + options = append(options, + optionPair{"--cluster.my-advertised-endpoint", config.AdvertisedEndpoint}, + ) + } } if serverType != ServerTypeAgent && serverType != ServerTypeSingle { for _, p := range clusterConfig.AllAgents() { diff --git a/service/service.go b/service/service.go index 8d55d2b1..87c450c8 100644 --- a/service/service.go +++ b/service/service.go @@ -58,6 +58,7 @@ type Config struct { ArangodPath string ArangodJSPath string ArangoSyncPath string + AdvertisedEndpoint string MasterPort int RrPath string DataDir string From 888cbffb51b399461d4435c4e9cc6bc972b8867f Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Thu, 9 Aug 2018 13:29:34 +0200 Subject: [PATCH 02/11] removed entry that is already appended after being checked againts not being empty --- service/arangod_config_builder.go | 1 - 1 file changed, 1 deletion(-) diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index 24c63c84..eab644e2 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -214,7 +214,6 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC ) case ServerTypeResilientSingle: options = append(options, - optionPair{"--cluster.my-advertised-endpoint", config.AdvertisedEndpoint}, optionPair{"--foxx.queues", "true"}, optionPair{"--server.statistics", "true"}, optionPair{"--replication.automatic-failover", "true"}, From c59497b61bd4c0b786bdd486d4642d63061cf567 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Tue, 21 Aug 2018 15:09:01 +0200 Subject: [PATCH 03/11] allow for http/https url schemes to be passed on to advertised-endpoints --- service/arangod_config_builder.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index eab644e2..55f3ace7 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -45,6 +45,19 @@ import ( "github.com/rs/zerolog" ) +var ( + urlFixer = strings.NewReplacer( + "http://", "tcp://", + "https://", "ssl://", + ) +) + +// FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by go. +// E.g. "http://localhost:8529" -> "tcp://localhost:8529" +func FixupEndpointURLScheme(u string) string { + return urlFixer.Replace(u) +} + // createArangodConf creates an arangod.conf file in the given host directory if it does not yet exists. // The arangod.conf file contains all settings that are considered static for the lifetime of the server. func createArangodConf(log zerolog.Logger, bsCfg BootstrapConfig, myHostDir, myContainerDir, myPort string, serverType ServerType, features DatabaseFeatures) ([]Volume, configFile, error) { @@ -204,7 +217,7 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC ) if config.AdvertisedEndpoint != "" { options = append(options, - optionPair{"--cluster.my-advertised-endpoint", config.AdvertisedEndpoint}, + optionPair{"--cluster.my-advertised-endpoint", FixupEndpointURLScheme(config.AdvertisedEndpoint)}, ) } case ServerTypeSingle: @@ -222,7 +235,7 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC ) if config.AdvertisedEndpoint != "" { options = append(options, - optionPair{"--cluster.my-advertised-endpoint", config.AdvertisedEndpoint}, + optionPair{"--cluster.my-advertised-endpoint", FixupEndpointURLScheme(config.AdvertisedEndpoint)}, ) } } From 239ee0b089c154556459e2d78a1a5a5b623dab89 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Tue, 21 Aug 2018 15:13:32 +0200 Subject: [PATCH 04/11] touch up comment --- service/arangod_config_builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index 55f3ace7..5aa28852 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -52,7 +52,7 @@ var ( ) ) -// FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by go. +// FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by arangodb. // E.g. "http://localhost:8529" -> "tcp://localhost:8529" func FixupEndpointURLScheme(u string) string { return urlFixer.Replace(u) From 55c33ddad20b52f1053d9a9933b573c9a695df69 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Tue, 21 Aug 2018 15:23:12 +0200 Subject: [PATCH 05/11] try parsing advertised endpoint and fatal error if failing --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index 0b027455..a1426f46 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ import ( "context" "fmt" "io/ioutil" + "net/url" "os" "os/signal" "path/filepath" @@ -569,6 +570,11 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo log.Fatal().Err(err).Msgf("Unsupport image pull policy '%s'", dockerImagePullPolicy) } + // Sanity checking URL scheme on advertised endpoints + if _, err := url.Parse(advertisedEndpoint); err != nil { + log.Fatal().Err(err).Msgf("Advertised cluster endpoint %s does not meet URL standards", advertisedEndpoint) + } + // Expand home-dis (~) in paths arangodPath = mustExpand(arangodPath) arangodJSPath = mustExpand(arangodJSPath) From 796cf3043cb8eba0eedd3c8e284cc3f57638c5bd Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Tue, 11 Sep 2018 15:15:45 +0200 Subject: [PATCH 06/11] Formatted code --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index a1426f46..91634515 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ import ( "context" "fmt" "io/ioutil" - "net/url" + "net/url" "os" "os/signal" "path/filepath" From 82c286ea959fbbac2fe45cefd28e9aede7715e64 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Tue, 11 Sep 2018 15:18:13 +0200 Subject: [PATCH 07/11] Fixed typos --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe643fd7..495080f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changed from version 0.12.0 to master -- Added advertised endpoint to coordinators and active fo +- Added advertised endpoint to coordinators and active failover servers. - Database upgrade procedure has changed. It is now much more automated and can be triggered using From c960e9cef07986e490d2acf5b8423f230907b3a9 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Tue, 11 Sep 2018 15:18:29 +0200 Subject: [PATCH 08/11] Description improvement --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 91634515..e8c4ca9c 100644 --- a/main.go +++ b/main.go @@ -194,7 +194,7 @@ func init() { pf.StringVar(&logDir, "log.dir", getEnvVar("LOG_DIR", ""), "Custom log file directory.") f.IntVar(&logRotateFilesToKeep, "log.rotate-files-to-keep", defaultLogRotateFilesToKeep, "Number of files to keep when rotating log files") f.DurationVar(&logRotateInterval, "log.rotate-interval", defaultLogRotateInterval, "Time between log rotations (0 disables log rotation)") - f.StringVar(&advertisedEndpoint, "cluster.advertised-endpoint", "", "An external endpoint for this cluster") + f.StringVar(&advertisedEndpoint, "cluster.advertised-endpoint", "", "An external endpoint for the servers started by this Starter") f.IntVar(&agencySize, "cluster.agency-size", 3, "Number of agents in the cluster") f.BoolSliceVar(&startAgent, "cluster.start-agent", nil, "should an agent instance be started") f.BoolSliceVar(&startDBserver, "cluster.start-dbserver", nil, "should a dbserver instance be started") From dc4d1f9bf15d0121584456bd6bf8e81769dff4a2 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Tue, 11 Sep 2018 15:20:24 +0200 Subject: [PATCH 09/11] Fixed typo --- service/arangod_config_builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index 5aa28852..e7ad5f8f 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -52,7 +52,7 @@ var ( ) ) -// FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by arangodb. +// FixupEndpointURLScheme changes endpoint URL schemes used by Starter to ones used by arangodb. // E.g. "http://localhost:8529" -> "tcp://localhost:8529" func FixupEndpointURLScheme(u string) string { return urlFixer.Replace(u) From a6284ee30753929a3770f9dbc1664ef66b8a0c2f Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Tue, 11 Sep 2018 15:22:51 +0200 Subject: [PATCH 10/11] Simplified code --- service/arangod_config_builder.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index e7ad5f8f..a95abbb4 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -215,11 +215,6 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC optionPair{"--foxx.queues", "true"}, optionPair{"--server.statistics", "true"}, ) - if config.AdvertisedEndpoint != "" { - options = append(options, - optionPair{"--cluster.my-advertised-endpoint", FixupEndpointURLScheme(config.AdvertisedEndpoint)}, - ) - } case ServerTypeSingle: options = append(options, optionPair{"--foxx.queues", "true"}, @@ -233,6 +228,8 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC optionPair{"--cluster.my-address", myTCPURL}, optionPair{"--cluster.my-role", "SINGLE"}, ) + } + if serverType == ServerTypeCoordinator || serverType == ServerTypeResilientSingle { if config.AdvertisedEndpoint != "" { options = append(options, optionPair{"--cluster.my-advertised-endpoint", FixupEndpointURLScheme(config.AdvertisedEndpoint)}, From e5cdde2e7a0c2c0bc0ddf5f9166f6dffd86a0424 Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Tue, 11 Sep 2018 15:27:07 +0200 Subject: [PATCH 11/11] Limit function scope --- service/arangod_config_builder.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index a95abbb4..86010de6 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -52,9 +52,9 @@ var ( ) ) -// FixupEndpointURLScheme changes endpoint URL schemes used by Starter to ones used by arangodb. +// fixupEndpointURLSchemeForArangod changes endpoint URL schemes used by Starter to ones used by arangodb. // E.g. "http://localhost:8529" -> "tcp://localhost:8529" -func FixupEndpointURLScheme(u string) string { +func fixupEndpointURLSchemeForArangod(u string) string { return urlFixer.Replace(u) } @@ -232,7 +232,7 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC if serverType == ServerTypeCoordinator || serverType == ServerTypeResilientSingle { if config.AdvertisedEndpoint != "" { options = append(options, - optionPair{"--cluster.my-advertised-endpoint", FixupEndpointURLScheme(config.AdvertisedEndpoint)}, + optionPair{"--cluster.my-advertised-endpoint", fixupEndpointURLSchemeForArangod(config.AdvertisedEndpoint)}, ) } }