metrics infrastructure (#128)

This commit is contained in:
Michael Quigley 2023-03-03 13:31:57 -05:00
parent 022084ec88
commit f2e887f70b
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
6 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package metrics
import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func Run(cfg *Config) error {
logrus.Info("starting")
defer logrus.Warn("stopping")
if cfg.Source == nil {
return errors.New("no 'source' configured; exiting")
}
src, ok := cfg.Source.(Source)
if !ok {
return errors.New("invalid 'source'; exiting")
}
srcJoin, err := src.Start()
if err != nil {
return errors.Wrap(err, "error starting source")
}
<-srcJoin
return nil
}

10
controller/metrics/cf.go Normal file
View File

@ -0,0 +1,10 @@
package metrics
import "github.com/michaelquigley/cf"
func GetCfOptions() *cf.Options {
opts := cf.DefaultOptions()
opts.AddFlexibleSetter("file", loadFileSourceConfig)
opts.AddFlexibleSetter("websocket", loadWebsocketSourceConfig)
return opts
}

View File

@ -0,0 +1,5 @@
package metrics
type Config struct {
Source interface{}
}

View File

@ -0,0 +1,17 @@
package metrics
import "github.com/michaelquigley/cf"
type FileSourceConfig struct {
Path string
}
func loadFileSourceConfig(v interface{}, opts *cf.Options) (interface{}, error) {
return nil, nil
}
type fileSource struct{}
func (s *fileSource) Start() (chan struct{}, error) {
return nil, nil
}

View File

@ -0,0 +1,10 @@
package metrics
type Source interface {
Start() (chan struct{}, error)
Stop()
}
type Ingester interface {
Ingest(msg map[string]interface{})
}

View File

@ -0,0 +1,17 @@
package metrics
import "github.com/michaelquigley/cf"
type WebsocketSourceConfig struct {
WebsocketEndpoint string
}
func loadWebsocketSourceConfig(v interface{}, opts *cf.Options) (interface{}, error) {
return nil, nil
}
type websocketSource struct{}
func (s *websocketSource) Start() (chan struct{}, error) {
return nil, nil
}