Skip to content
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changed from version 0.12.0 to master

- 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
an `arangodb upgrade --starter.endpoint=...` command.
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -86,6 +87,7 @@ var (
logService logging.Service
showVersion bool
id string
advertisedEndpoint string
agencySize int
arangodPath string
arangodJSPath string
Expand Down Expand Up @@ -192,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 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")
Expand Down Expand Up @@ -568,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)
Expand Down Expand Up @@ -707,6 +714,7 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo
ArangodPath: arangodPath,
ArangoSyncPath: arangoSyncPath,
ArangodJSPath: arangodJSPath,
AdvertisedEndpoint: advertisedEndpoint,
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the advertised endpoint should be checked (when non-empty) to make sure it is a valid format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, also here we had decided to not do any sanity checks. It it does not suffice the endpoint specification, the affected services will complain. Effectively like wrong passthrough options

Copy link
Contributor

Choose a reason for hiding this comment

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

Not so sure on the "no sanity checks". If we decided to that, it sounds like a bad decision.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now test was added. Problem solved.

Copy link
Contributor

Choose a reason for hiding this comment

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

Secondly I suggest to allow the use of "http" & "https" schemes in here and automatically transform them to "tcp" & "ssl"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had that discussion and decided to the contrary. It had to suffice the enpoint scheme. Keep in mind that this was supposed to not be interpreted in any way and match the endpoint specification and was the reason we decided to not call it advertised-address. No sanity checks no nothing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I strongly disagree on this. The starter is supposed to make life easier and having think about "tcp://" or "ssl://" where everyone knows about "http://" and "https://" does not help.
Also we don't have to check anything except replace an "http://" prefix with "tcp://" (and https...)

MasterPort: masterPort,
RrPath: rrPath,
DataDir: dataDir,
Expand Down
20 changes: 20 additions & 0 deletions service/arangod_config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ import (
"github.com/rs/zerolog"
)

var (
urlFixer = strings.NewReplacer(
"http://", "tcp://",
"https://", "ssl://",
)
)

// fixupEndpointURLSchemeForArangod changes endpoint URL schemes used by Starter to ones used by arangodb.
// E.g. "http://localhost:8529" -> "tcp://localhost:8529"
func fixupEndpointURLSchemeForArangod(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) {
Expand Down Expand Up @@ -216,6 +229,13 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC
optionPair{"--cluster.my-role", "SINGLE"},
)
}
if serverType == ServerTypeCoordinator || serverType == ServerTypeResilientSingle {
if config.AdvertisedEndpoint != "" {
options = append(options,
optionPair{"--cluster.my-advertised-endpoint", fixupEndpointURLSchemeForArangod(config.AdvertisedEndpoint)},
)
}
}
if serverType != ServerTypeAgent && serverType != ServerTypeSingle {
for _, p := range clusterConfig.AllAgents() {
options = append(options,
Expand Down
1 change: 1 addition & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Config struct {
ArangodPath string
ArangodJSPath string
ArangoSyncPath string
AdvertisedEndpoint string
MasterPort int
RrPath string
DataDir string
Expand Down