metrics lint; cache infrastructure (#74, #76)

This commit is contained in:
Michael Quigley 2022-10-19 11:25:08 -04:00
parent 095024c179
commit 83c12e30cb
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 31 additions and 22 deletions

View File

@ -36,15 +36,22 @@ type metricsAgent struct {
cfg *MetricsConfig cfg *MetricsConfig
influx influxdb2.Client influx influxdb2.Client
writeApi api.WriteAPIBlocking writeApi api.WriteAPIBlocking
envCache map[string]*envCacheEntry
zCtx ziti.Context zCtx ziti.Context
zListener edge.Listener zListener edge.Listener
shutdown chan struct{} shutdown chan struct{}
joined chan struct{} joined chan struct{}
} }
type envCacheEntry struct {
env string
lastAccess time.Time
}
func newMetricsAgent(cfg *MetricsConfig) *metricsAgent { func newMetricsAgent(cfg *MetricsConfig) *metricsAgent {
ma := &metricsAgent{ ma := &metricsAgent{
cfg: cfg, cfg: cfg,
envCache: make(map[string]*envCacheEntry),
shutdown: make(chan struct{}), shutdown: make(chan struct{}),
joined: make(chan struct{}), joined: make(chan struct{}),
} }

View File

@ -80,6 +80,7 @@ func (ma *metricsAgent) pushUpdate(mu metricsUpdate) {
} }
func (ma *metricsAgent) sendMetrics() error { func (ma *metricsAgent) sendMetrics() error {
if len(ma.accum) > 0 {
m := &model.Metrics{ m := &model.Metrics{
Namespace: ma.cfg.Identity, Namespace: ma.cfg.Identity,
Sessions: ma.accum, Sessions: ma.accum,
@ -103,5 +104,6 @@ func (ma *metricsAgent) sendMetrics() error {
logrus.Infof("sent %d bytes of metrics data", n) logrus.Infof("sent %d bytes of metrics data", n)
ma.accum = make(map[string]model.SessionMetrics) ma.accum = make(map[string]model.SessionMetrics)
ma.lastSend = time.Now() ma.lastSend = time.Now()
}
return nil return nil
} }