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
|
@ -20,6 +20,7 @@ import (
|
|||
// Agent runs telegraf and collects data based on the given config
|
||||
type Agent struct {
|
||||
Config *config.Config
|
||||
Version string
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
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()
|
||||
|
||||
wg.Add(1)
|
||||
|
|
|
@ -174,6 +174,7 @@ func main() {
|
|||
}
|
||||
|
||||
ag, err := agent.NewAgent(c)
|
||||
ag.Version = Version
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -21,18 +21,20 @@ type Service struct {
|
|||
hosts []*client.Host
|
||||
logger *log.Logger
|
||||
hostname string
|
||||
version string
|
||||
adminPort string
|
||||
|
||||
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{
|
||||
hosts: c.Hosts,
|
||||
hostname: hostname,
|
||||
logger: log.New(os.Stdout, "[enterprise]", log.Ldate|log.Ltime),
|
||||
adminPort: fmt.Sprintf(":%d", c.AdminPort),
|
||||
shutdown: shutdown,
|
||||
version: version,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +62,7 @@ func (s *Service) registerProduct(cl *client.Client) (token string, secret strin
|
|||
Host: s.hostname,
|
||||
ClusterID: "8675309",
|
||||
Name: "telegraf",
|
||||
Version: "0.10.1.dev",
|
||||
Version: s.version,
|
||||
AdminURL: "http://" + s.hostname + s.adminPort,
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ func Test_RegistersWithEnterprise(t *testing.T) {
|
|||
|
||||
shutdown := make(chan struct{})
|
||||
defer close(shutdown)
|
||||
e := enterprise.NewEnterprise(c, expected, shutdown)
|
||||
e := enterprise.NewEnterprise(c, expected, "test", shutdown)
|
||||
e.Open()
|
||||
|
||||
timeout := time.After(1 * time.Millisecond)
|
||||
|
@ -80,7 +80,7 @@ func Test_StartsAdminInterface(t *testing.T) {
|
|||
|
||||
shutdown := make(chan struct{})
|
||||
defer close(shutdown)
|
||||
e := enterprise.NewEnterprise(c, hostname, shutdown)
|
||||
e := enterprise.NewEnterprise(c, hostname, "test", shutdown)
|
||||
e.Open()
|
||||
|
||||
timeout := time.After(1 * time.Millisecond)
|
||||
|
@ -113,7 +113,7 @@ func Test_ClosesAdminInterface(t *testing.T) {
|
|||
}
|
||||
|
||||
shutdown := make(chan struct{})
|
||||
e := enterprise.NewEnterprise(c, hostname, shutdown)
|
||||
e := enterprise.NewEnterprise(c, hostname, "test", shutdown)
|
||||
e.Open()
|
||||
|
||||
timeout := time.After(1 * time.Millisecond)
|
||||
|
|
Loading…
Reference in New Issue