Pull Version down into enterprise service
We need to report the current version, but it's only available as a link-time variable in the main package. Since we can't import this without incurring the wrath of the Go compiler's no-circular dependency rule, we need to pull this down through the agent.
This commit is contained in:
parent
c3c9e80f0a
commit
d08a694248
|
@ -19,7 +19,8 @@ import (
|
||||||
|
|
||||||
// Agent runs telegraf and collects data based on the given config
|
// Agent runs telegraf and collects data based on the given config
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAgent returns an Agent struct based off the given Config
|
// NewAgent returns an Agent struct based off the given Config
|
||||||
|
@ -329,7 +330,7 @@ func (a *Agent) Run(shutdown chan struct{}) error {
|
||||||
}
|
}
|
||||||
ticker := time.NewTicker(a.Config.Agent.Interval.Duration)
|
ticker := time.NewTicker(a.Config.Agent.Interval.Duration)
|
||||||
|
|
||||||
ent := enterprise.NewEnterprise(a.Config.Agent.Enterprise, a.Config.Agent.Hostname, shutdown)
|
ent := enterprise.NewEnterprise(a.Config.Agent.Enterprise, a.Config.Agent.Hostname, a.Version, shutdown)
|
||||||
go ent.Open()
|
go ent.Open()
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
|
@ -174,6 +174,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ag, err := agent.NewAgent(c)
|
ag, err := agent.NewAgent(c)
|
||||||
|
ag.Version = Version
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,18 +21,20 @@ type Service struct {
|
||||||
hosts []*client.Host
|
hosts []*client.Host
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
hostname string
|
hostname string
|
||||||
|
version string
|
||||||
adminPort string
|
adminPort string
|
||||||
|
|
||||||
shutdown chan struct{}
|
shutdown chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnterprise(c Config, hostname string, shutdown chan struct{}) *Service {
|
func NewEnterprise(c Config, hostname, version string, shutdown chan struct{}) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
hosts: c.Hosts,
|
hosts: c.Hosts,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
logger: log.New(os.Stdout, "[enterprise]", log.Ldate|log.Ltime),
|
logger: log.New(os.Stdout, "[enterprise]", log.Ldate|log.Ltime),
|
||||||
adminPort: fmt.Sprintf(":%d", c.AdminPort),
|
adminPort: fmt.Sprintf(":%d", c.AdminPort),
|
||||||
shutdown: shutdown,
|
shutdown: shutdown,
|
||||||
|
version: version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ func (s *Service) registerProduct(cl *client.Client) (token string, secret strin
|
||||||
Host: s.hostname,
|
Host: s.hostname,
|
||||||
ClusterID: "8675309",
|
ClusterID: "8675309",
|
||||||
Name: "telegraf",
|
Name: "telegraf",
|
||||||
Version: "0.10.1.dev",
|
Version: s.version,
|
||||||
AdminURL: "http://" + s.hostname + s.adminPort,
|
AdminURL: "http://" + s.hostname + s.adminPort,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ func Test_RegistersWithEnterprise(t *testing.T) {
|
||||||
|
|
||||||
shutdown := make(chan struct{})
|
shutdown := make(chan struct{})
|
||||||
defer close(shutdown)
|
defer close(shutdown)
|
||||||
e := enterprise.NewEnterprise(c, expected, shutdown)
|
e := enterprise.NewEnterprise(c, expected, "test", shutdown)
|
||||||
e.Open()
|
e.Open()
|
||||||
|
|
||||||
timeout := time.After(1 * time.Millisecond)
|
timeout := time.After(1 * time.Millisecond)
|
||||||
|
@ -80,7 +80,7 @@ func Test_StartsAdminInterface(t *testing.T) {
|
||||||
|
|
||||||
shutdown := make(chan struct{})
|
shutdown := make(chan struct{})
|
||||||
defer close(shutdown)
|
defer close(shutdown)
|
||||||
e := enterprise.NewEnterprise(c, hostname, shutdown)
|
e := enterprise.NewEnterprise(c, hostname, "test", shutdown)
|
||||||
e.Open()
|
e.Open()
|
||||||
|
|
||||||
timeout := time.After(1 * time.Millisecond)
|
timeout := time.After(1 * time.Millisecond)
|
||||||
|
@ -113,7 +113,7 @@ func Test_ClosesAdminInterface(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown := make(chan struct{})
|
shutdown := make(chan struct{})
|
||||||
e := enterprise.NewEnterprise(c, hostname, shutdown)
|
e := enterprise.NewEnterprise(c, hostname, "test", shutdown)
|
||||||
e.Open()
|
e.Open()
|
||||||
|
|
||||||
timeout := time.After(1 * time.Millisecond)
|
timeout := time.After(1 * time.Millisecond)
|
||||||
|
|
Loading…
Reference in New Issue