metrics service name; metrics agent shutdown (#74, #76)

This commit is contained in:
Michael Quigley 2022-10-13 15:50:12 -04:00
parent dae4e9b1ec
commit 41d5c2b652
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 35 additions and 16 deletions

View File

@ -7,13 +7,13 @@ import (
) )
type Config struct { type Config struct {
Endpoint *EndpointConfig Endpoint *EndpointConfig
Proxy *ProxyConfig Proxy *ProxyConfig
Email *EmailConfig Email *EmailConfig
Registration *RegistrationConfig Registration *RegistrationConfig
Store *store.Config Store *store.Config
Ziti *ZitiConfig Ziti *ZitiConfig
MetricsConfig *MetricsConfig Metrics *MetricsConfig
} }
type EndpointConfig struct { type EndpointConfig struct {

View File

@ -44,8 +44,14 @@ func Run(cfg *Config) error {
return errors.Wrap(err, "error opening store") return errors.Wrap(err, "error opening store")
} }
mtr = newMetricsAgent(cfg.MetricsConfig) if cfg.Metrics != nil {
go mtr.run() mtr = newMetricsAgent(cfg.Metrics)
go mtr.run()
defer func() {
mtr.stop()
mtr.join()
}()
}
server := rest_server_zrok.NewServer(api) server := rest_server_zrok.NewServer(api)
defer func() { _ = server.Shutdown() }() defer func() { _ = server.Shutdown() }()

View File

@ -2,11 +2,11 @@ package controller
import ( import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"time"
) )
type MetricsConfig struct { type MetricsConfig struct {
Influx *InfluxConfig ServiceName string
Influx *InfluxConfig
} }
type InfluxConfig struct { type InfluxConfig struct {
@ -17,18 +17,31 @@ type InfluxConfig struct {
} }
type metricsAgent struct { type metricsAgent struct {
cfg *MetricsConfig cfg *MetricsConfig
shutdown chan struct{}
joined chan struct{}
} }
func newMetricsAgent(cfg *MetricsConfig) *metricsAgent { func newMetricsAgent(cfg *MetricsConfig) *metricsAgent {
return &metricsAgent{cfg: cfg} return &metricsAgent{
cfg: cfg,
shutdown: make(chan struct{}),
joined: make(chan struct{}),
}
} }
func (mtr *metricsAgent) run() { func (mtr *metricsAgent) run() {
logrus.Info("starting") logrus.Info("starting")
defer logrus.Info("exiting") defer logrus.Info("exiting")
defer close(mtr.joined)
for { <-mtr.shutdown
time.Sleep(24 * time.Hour) }
}
func (mtr *metricsAgent) stop() {
close(mtr.shutdown)
}
func (mtr *metricsAgent) join() {
<-mtr.joined
} }