From f2e887f70bbaf1e81f5b35916074dfc1840de1ce Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 3 Mar 2023 13:31:57 -0500 Subject: [PATCH] metrics infrastructure (#128) --- controller/metrics/agent.go | 29 +++++++++++++++++++++++++++ controller/metrics/cf.go | 10 +++++++++ controller/metrics/config.go | 5 +++++ controller/metrics/fileSource.go | 17 ++++++++++++++++ controller/metrics/model.go | 10 +++++++++ controller/metrics/websocketSource.go | 17 ++++++++++++++++ 6 files changed, 88 insertions(+) create mode 100644 controller/metrics/agent.go create mode 100644 controller/metrics/cf.go create mode 100644 controller/metrics/config.go create mode 100644 controller/metrics/fileSource.go create mode 100644 controller/metrics/model.go create mode 100644 controller/metrics/websocketSource.go diff --git a/controller/metrics/agent.go b/controller/metrics/agent.go new file mode 100644 index 00000000..9d5c768f --- /dev/null +++ b/controller/metrics/agent.go @@ -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 +} diff --git a/controller/metrics/cf.go b/controller/metrics/cf.go new file mode 100644 index 00000000..e68ae9c4 --- /dev/null +++ b/controller/metrics/cf.go @@ -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 +} diff --git a/controller/metrics/config.go b/controller/metrics/config.go new file mode 100644 index 00000000..471844de --- /dev/null +++ b/controller/metrics/config.go @@ -0,0 +1,5 @@ +package metrics + +type Config struct { + Source interface{} +} diff --git a/controller/metrics/fileSource.go b/controller/metrics/fileSource.go new file mode 100644 index 00000000..97bbfed4 --- /dev/null +++ b/controller/metrics/fileSource.go @@ -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 +} diff --git a/controller/metrics/model.go b/controller/metrics/model.go new file mode 100644 index 00000000..1201f5be --- /dev/null +++ b/controller/metrics/model.go @@ -0,0 +1,10 @@ +package metrics + +type Source interface { + Start() (chan struct{}, error) + Stop() +} + +type Ingester interface { + Ingest(msg map[string]interface{}) +} diff --git a/controller/metrics/websocketSource.go b/controller/metrics/websocketSource.go new file mode 100644 index 00000000..c4dd1faa --- /dev/null +++ b/controller/metrics/websocketSource.go @@ -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 +}