dial identity in metrics agent for frontend (#74, #76)

This commit is contained in:
Michael Quigley 2022-10-14 13:40:29 -04:00
parent e9941914d9
commit 8c0261f3ad
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 23 additions and 4 deletions

View File

@ -28,7 +28,10 @@ type httpListen struct {
}
func NewHTTP(cfg *Config) (*httpListen, error) {
ma := newMetricsAgent()
ma, err := newMetricsAgent(cfg.Identity)
if err != nil {
return nil, err
}
go ma.run()
zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.Identity)

View File

@ -3,12 +3,18 @@ package frontend
import (
"fmt"
"github.com/openziti-test-kitchen/zrok/util"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/config"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"time"
)
type metricsAgent struct {
metrics map[string]sessionMetrics
updates chan metricsUpdate
zCtx ziti.Context
}
type sessionMetrics struct {
@ -23,11 +29,21 @@ type metricsUpdate struct {
bytesWritten int64
}
func newMetricsAgent() *metricsAgent {
func newMetricsAgent(identityName string) (*metricsAgent, error) {
zif, err := zrokdir.ZitiIdentityFile(identityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting '%v' identity file", identityName)
}
zCfg, err := config.NewFromFile(zif)
if err != nil {
return nil, errors.Wrapf(err, "error loading '%v' identity", identityName)
}
logrus.Infof("loaded '%v' identity", identityName)
return &metricsAgent{
metrics: make(map[string]sessionMetrics),
updates: make(chan metricsUpdate, 10240),
}
zCtx: ziti.NewContextWithConfig(zCfg),
}, nil
}
func (ma *metricsAgent) run() {
@ -56,7 +72,7 @@ func (ma *metricsAgent) run() {
out += fmt.Sprintf("\t[%v]: %s/%s (%s)\n", k, util.BytesToSize(v.bytesRead), util.BytesToSize(v.bytesWritten), age.String())
}
out += "}\n"
//fmt.Println(out)
}
}
}