Live: include a streaming event manager (#26537)

This commit is contained in:
Ryan McKinley
2020-07-27 00:26:16 -07:00
committed by GitHub
parent 3defb4441e
commit 339138d61a
23 changed files with 895 additions and 432 deletions

View File

@@ -10,11 +10,11 @@ import (
"path"
"sync"
"github.com/grafana/grafana/pkg/services/live"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/api/live"
"github.com/grafana/grafana/pkg/api/routing"
httpstatic "github.com/grafana/grafana/pkg/api/static"
"github.com/grafana/grafana/pkg/bus"
@@ -48,12 +48,11 @@ func init() {
}
type HTTPServer struct {
log log.Logger
macaron *macaron.Macaron
context context.Context
streamManager *live.StreamManager
httpSrv *http.Server
middlewares []macaron.Handler
log log.Logger
macaron *macaron.Macaron
context context.Context
httpSrv *http.Server
middlewares []macaron.Handler
RouteRegister routing.RouteRegister `inject:""`
Bus bus.Bus `inject:""`
@@ -71,12 +70,25 @@ type HTTPServer struct {
BackendPluginManager backendplugin.Manager `inject:""`
PluginManager *plugins.PluginManager `inject:""`
SearchService *search.SearchService `inject:""`
Live *live.GrafanaLive
}
func (hs *HTTPServer) Init() error {
hs.log = log.New("http.server")
hs.streamManager = live.NewStreamManager()
// Set up a websocket broker
if hs.Cfg.IsLiveEnabled() { // feature flag
node, err := live.InitalizeBroker()
if err != nil {
return err
}
hs.Live = node
// Spit random walk to example
go live.RunRandomCSV(hs.Live, "random-2s-stream", 2000, 0)
go live.RunRandomCSV(hs.Live, "random-flakey-stream", 400, .6)
}
hs.macaron = hs.newMacaron()
hs.registerRoutes()
@@ -91,7 +103,6 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
hs.context = ctx
hs.applyRoutes()
hs.streamManager.Run(ctx)
hs.httpSrv = &http.Server{
Addr: fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort),