Skip to content

Commit

Permalink
Support setting the hostname of the agent via environment variable. (#54
Browse files Browse the repository at this point in the history
)

* Support setting the hostname of the agent via environment variable.

* Apply the same logic for the port
  • Loading branch information
doertedev-instana authored and pglombardo committed Jul 25, 2018
1 parent 9dcca59 commit 493edb4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
18 changes: 12 additions & 6 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io/ioutil"
"net/http"
"os"
"strconv"
"time"
)
Expand Down Expand Up @@ -57,13 +58,18 @@ func (r *agentS) makeURL(prefix string) string {
}

func (r *agentS) makeHostURL(host string, prefix string) string {
var port int
if r.sensor.options.AgentPort == 0 {
port = agentDefaultPort
} else {
port = r.sensor.options.AgentPort
envPort := os.Getenv("INSTANA_AGENT_PORT")
port := agentDefaultPort
if r.sensor.options.AgentPort > 0 {
return r.makeFullURL(host, r.sensor.options.AgentPort, prefix)
}
if envPort == "" {
return r.makeFullURL(host, port, prefix)
}
port, err := strconv.Atoi(envPort)
if err != nil {
return r.makeFullURL(host, agentDefaultPort, prefix)
}

return r.makeFullURL(host, port, prefix)
}

Expand Down
15 changes: 10 additions & 5 deletions fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ func (r *fsmS) lookupAgentHost(e *f.Event) {
}
}
}

if r.agent.sensor.options.AgentHost != "" {
go r.checkHost(r.agent.sensor.options.AgentHost, cb)
} else {
go r.checkHost(agentDefaultHost, cb)
hostNames := []string{
r.agent.sensor.options.AgentHost,
os.Getenv("INSTANA_AGENT_HOST"),
agentDefaultHost,
}
for _, name := range hostNames {
if name != "" {
go r.checkHost(name, cb)
return
}
}
}

Expand Down

0 comments on commit 493edb4

Please sign in to comment.