Add WebSocket output plugin#9188
Conversation
|
Thanks so much for the pull request! |
|
!signed-cla |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
ivorybilled
left a comment
There was a problem hiding this comment.
Code looks good to me, just a couple of linter issues to fix. Thanks!
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
|
@jagularr hello, thanks for looking! Just fixed linter issues |
|
@jagularr is there anything we can do to make this easier to review? |
thanks for your attention. |
Just tried to reproduce this - it works fine for me (I am using Telegraf built from latest commit in my branch). My config: In server console I see sth like this: I.e. JSON format. I am on MacOS, but not sure this can make a difference. Make sure you reloaded Telegraf when changing data format.
I believe that there is nothing to add here to achieve this since IP comes from TCP/IP level or if modified on load balancer level usually can be extracted from |
|
Ok,i reboot and the configuration actually work.Sorry to bother you for my carelessness. |
|
Thanks! looks slick; just have a few comments |
|
@ssoroka hello, thanks for reviewing - pushed some fixes and commented where I think things already work fine. |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
| messageType := ws.BinaryMessage | ||
| if w.UseTextFrames { | ||
| messageType = ws.TextMessage | ||
| } |
There was a problem hiding this comment.
This can be moved to the Init() function I think.
There was a problem hiding this comment.
That just a frame type detection based on config allocated on stack, moving it to WebSocket struct will only make code harder to follow in my opinion.
There was a problem hiding this comment.
TBH I like it more if "one-time things" are not in here, as it clutters the code. But if @ssoroka aggrees we can leave it here.
|
@srebhan to be fair lots of stuff to do outside of Telegraf these days, but I definitely suggest using Gorilla WebSocket - it's robust, widely used, receives security updates. And you already have it in |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
Oh damn, thought I can get rid of it... :-P |
|
@ssoroka hello, I think I addressed all your review comments - could you please take a look? |
|
For reference, here is a first draft on a tutorial using this PR to stream metrics to grafana: |
|
@ssoroka Are you ok with this PR? I see all your review comments are resolved but your review still says you requested changes. |
resolves #
Hello, added a generic WebSocket output plugin. We need it for Grafana to stream data into panels from Telegraf (aiming to introduce basic streaming support in Grafana v8). A video that demonstrates our early work on this (this is a CPU data stream from Telegraf using output plugin code introduced here):
Screen.Recording.2021-04-26.at.10.46.58.mov
We considered going with HTTP output plugin first, but the latency overhead for each HTTP request was pretty big. Unfortunately optimizing HTTP path resulted in pretty "special" HTTP endpoint in Grafana with many useful middleware cut off. More details in this draft pull request.
WebSocket allows us to reuse the same port as HTTP server (so no need to open new ports), also message processing does not require going through all middleware stack - thus reducing overall latency and load on GC.
This plugin works somewhat similar to existing socket_writer output plugin.
One important thing that while Gorilla WebSocket required for plugin to work it already existed in indirect dependencies of Telegraf, Gorilla WebSocket itself is de-facto library for Websocket in Go, well-tested and has zero dependencies itself.
Unit tests cover most things, but to test manually one can do the following:
After this requests should be seen in server log output.