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

Fix hostname defaults #2393

Merged
merged 2 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#2376](https://github.com/influxdb/influxdb/pull/2376): Encode all types of integers. Thanks @jtakkala.
- [#2376](https://github.com/influxdb/influxdb/pull/2376): Add shard path to existing diags value. Fix issue #2369.
- [#2386](https://github.com/influxdb/influxdb/pull/2386): Fix shard datanodes stats getting appended too many times
- [#2393](https://github.com/influxdb/influxdb/pull/2393): Fix default hostname for connecting to cluster.

## v0.9.0-rc26 [04-21-2015]

Expand Down
8 changes: 8 additions & 0 deletions cmd/influxd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const (
// DefaultAPIReadTimeout represents the duration before an API request times out.
DefaultAPIReadTimeout = 5 * time.Second

// DefaultHostName represents the default host name to use if it is never provided
DefaultHostName = "localhost"

// DefaultBindAddress represents the bind address to use if none is specified
DefaultBindAddress = "0.0.0.0"

// DefaultClusterPort represents the default port the cluster runs ons.
DefaultClusterPort = 8086

Expand Down Expand Up @@ -227,6 +233,8 @@ type Config struct {
// NewConfig returns an instance of Config with reasonable defaults.
func NewConfig() *Config {
c := &Config{}
c.Hostname = DefaultHostName
c.BindAddress = DefaultBindAddress
c.Port = DefaultClusterPort

c.Data.Enabled = DefaultDataEnabled
Expand Down
43 changes: 20 additions & 23 deletions cmd/influxd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Node struct {
DataNode *influxdb.Server
raftLog *raft.Log

hostname string

adminServer *admin.Server
clusterListener net.Listener // The cluster TCP listener
apiListener net.Listener // The API TCP listener
Expand All @@ -56,15 +58,13 @@ func (s *Node) ClusterAddr() net.Addr {
}

func (s *Node) ClusterURL() *url.URL {
h, p, e := net.SplitHostPort(s.ClusterAddr().String())
// Find out which port the cluster started on
_, p, e := net.SplitHostPort(s.ClusterAddr().String())
if e != nil {
panic(e)
}
if h == "::" || h == "" {
h = "localhost"
}

h = net.JoinHostPort(h, p)
h := net.JoinHostPort(s.hostname, p)
return &url.URL{
Scheme: "http",
Host: h,
Expand Down Expand Up @@ -189,34 +189,31 @@ func (s *Node) closeClusterListener() error {
return err
}

func (cmd *RunCommand) ParseConfig(path, hostname string) error {
var err error

func (cmd *RunCommand) ParseConfig(path string) error {
// Parse configuration file from disk.
if path != "" {
var err error
cmd.config, err = ParseConfigFile(path)

if err != nil {
return fmt.Errorf("error parsing configuration %s - %s\n", path, err)
}
// Override config properties.
if hostname != "" {
cmd.config.Hostname = hostname
log.Printf("using configuration at: %s\n", path)
} else {
var err error
cmd.config, err = NewTestConfig()

if err != nil {
return fmt.Errorf("error parsing default config: %s\n", err)
}

log.Printf("using configuration at: %s\n", path)
return nil
log.Println("no configuration provided, using default settings")
}

cmd.config, err = NewTestConfig()
if err != nil {
return fmt.Errorf("error parsing default config: %s\n", err)
}
// Override config properties.
if hostname != "" {
cmd.config.Hostname = hostname
if cmd.hostname != "" {
cmd.config.Hostname = cmd.hostname
}
log.Println("no configuration provided, using default settings")
cmd.node.hostname = cmd.config.Hostname
return nil
}

Expand Down Expand Up @@ -249,7 +246,7 @@ func (cmd *RunCommand) Run(args ...string) error {
log.Printf("GOMAXPROCS set to %d", runtime.GOMAXPROCS(0))

// Parse config
if err := cmd.ParseConfig(configPath, hostname); err != nil {
if err := cmd.ParseConfig(configPath); err != nil {
log.Fatal(err)
}

Expand Down Expand Up @@ -321,7 +318,7 @@ func (cmd *RunCommand) Open(config *Config, join string) *Node {
if err := cmd.node.openClusterListener(cmd.config.ClusterAddr(), h); err != nil {
log.Fatalf("Cluster server failed to listen on %s. %s ", cmd.config.ClusterAddr(), err)
}
log.Printf("Cluster server listening on %s", cmd.node.ClusterURL().String())
log.Printf("Cluster server listening on %s", cmd.node.ClusterAddr().String())

// Open broker & raft log, initialize or join as necessary.
if cmd.config.Broker.Enabled {
Expand Down