ExpediaGroup / cyclotron

A web platform for constructing dashboards.
https://www.cyclotron.io/
MIT License
1.56k stars 112 forks source link

Server Side Events in dataSource #42

Closed abdulazizali77 closed 5 years ago

abdulazizali77 commented 5 years ago

Hi,

Were trying to create a dataSource using SSE / data push, but guessing that its not supported, what we see is that there is no API to update data directly eg dataSourceFactory.broadcastData(newDataSet) and all of the data sources do a polling data pull by starting runner on each interval, or maybe were mising something, havent looked at using dataService nor looking at the $rootScope yet, can you confirm our doubts?

If we wanted to integrate SSE/ data push, what would you recommend is the best way as an interface in dataSourceFactory ?

baumandm commented 5 years ago

Correct, this is currently not a built-in feature. dataSourceFactory wraps most of the common functionality to make it easier to build new data sources, but it only supports a single data update unless you use the timer.

You can implement a Data Source from scratch, and basically just open a web socket that connects to the server, receives events, and whenever the data events occur, calls $rootScope.$broadcast('dataSource:' + options.name + ':data', ....).

An easier implementation would be to add a custom Script that uses a web socket to collect server-side events into a global variable. Then have a JavaScript Data Source with a short refresh timer that periodically broadcasts the collected data. It would be slightly buffered and inefficient if the refresh is too frequent, but depending on event frequency that might be sufficient.

abdulazizali77 commented 5 years ago

Thanks for the reply @baumandm, yeah im actually trying the first $rootScope.$broadcast option still figuring out why the widgets arent updating and i did think the second option would be my best bet if i couldnt get the first option to work

abdulazizali77 commented 5 years ago

@baumandm oh one option which looks interesting is cyclotronDataService buckets, but guessing buckets are meant to be used as adhoc data placeholders only, they dont connect to the real datastore that the widgets use? couldnt actually find anything/other examples aside from the annotation chart using this feature

baumandm commented 5 years ago

cyclotronDataService is lightweight storage of data within Cyclotron itself. You could push events to it and have a Data Source pull it out, but it would still be a pull model instead of a push. There is some information about it at /help?q=CyclotronData