-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(inputs.firehose): Add new plugin #15988
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syedmhashim I do have some comments, mostly on style, so overall this looks quite promising. I urge you to keep the code as simple and less nested as possible to ease review and debugging. And of course some unit-tests would be great!
Thanks for the review. Will definitely go over the comments and update accordingly. Just FYI, I have been using |
Yeah we do have some older code we didn't adapt yet but things changed both on the golang side as well as on us being more strict with the way things are done. ;-) No worries, we will figure it out together. :-) |
@syedmhashim I'm loosing a bit the track in the discussion above, could you please push an update with the stuff that is clear and then we discuss the unclear parts? |
@srebhan Hey! Just pushed some changes and commented "done" on the threads that I resolved. Sorry for the delay. I got occupied with my job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks much better @syedmhashim! Some more cleanups and comments from my side...
@srebhan Hi! Pushed some changes and added comments where relevant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syedmhashim thanks for the update. I tried to put more concrete suggestions into my review. Overall, I think we are almost there, the only thing missing are unit-tests with a mocked sender...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice @syedmhashim! Some very small things with the biggest being that log messages should start with a captial letter... The only thing missing are the unit-tests...
Hi @srebhan. In addition to the changes that you suggested, I also made some changes to the code(see last commit) that I think would make it more clean and readable. P.S I think it also helps to achieve separation of concern since now all processing of the request is handled by Changes to :
I'd like to hear your thoughts on this |
0138d46
to
9d69797
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syedmhashim thanks for the update. I do have some smaller comments in the code but nothing big.
Regarding the tests, I suggest that you don't test the request separately but simply use a http client and send data to the plugin. You might also want to implement a general test-case setup similar to what we do in socket listener tests...
If you need help with the tests, please provide some payload examples and invite me to your branch and I'll help you to drive this PR over the finish line...
plugins/inputs/firehose/firehose.go
Outdated
"github.com/influxdata/telegraf" | ||
"github.com/influxdata/telegraf/config" | ||
"github.com/influxdata/telegraf/internal" | ||
tlsint "github.com/influxdata/telegraf/plugins/common/tls" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no do have an unwritten convention to use
tlsint "github.com/influxdata/telegraf/plugins/common/tls" | |
common_tls "github.com/influxdata/telegraf/plugins/common/tls" |
i.e. prefix packages in plugins/common
with common_
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
plugins/inputs/firehose/firehose.go
Outdated
f.listener, err = net.Listen("tcp", f.ServiceAddress) | ||
} | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return err | |
return fmt.Errorf("creating listener failed: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
plugins/inputs/firehose/firehose.go
Outdated
go func() { | ||
if err := f.server.Serve(f.listener); err != nil { | ||
if !errors.Is(err, net.ErrClosed) { | ||
f.Log.Errorf("Starting server failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not only on startup but might also return errors later... So how about
f.Log.Errorf("Starting server failed: %v", err) | |
f.Log.Errorf("Server failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
plugins/inputs/firehose/firehose.go
Outdated
err := f.server.Shutdown(context.Background()) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err := f.server.Shutdown(context.Background()) | |
if err != nil { | |
if err := f.server.Shutdown(context.Background()); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
plugins/inputs/firehose/firehose.go
Outdated
func (f *Firehose) handleRequest(req *http.Request) (r *request) { | ||
var err error | ||
if r, err = newRequest(req); err != nil { | ||
f.Log.Errorf("Creating request object failed: %v", err) | ||
return r | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about returning the actual error here and do the logging in ServeHTTP
? This will save a few lines I think
func (f *Firehose) handleRequest(req *http.Request) (r *request) { | |
var err error | |
if r, err = newRequest(req); err != nil { | |
f.Log.Errorf("Creating request object failed: %v", err) | |
return r | |
} | |
func (f *Firehose) handleRequest(req *http.Request) (*request, error) { | |
r, err := newRequest(req) | |
if err != nil { | |
return fmt.Errorf("creating request failed: %w", err) | |
} |
of course you need to modify the code below and in ServeHTTP
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried implementing this but doesn’t help. The line count remains the same as we need to introduce err checking in the ServeHTTP
function. I made some other changes which saves us a couple lines though
@srebhan Hey. Just sent you an invite! The payload needs to be in the following format with
|
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
Summary
The firehose input plugin would be used to receive data from AWS Data Firehose.
Checklist
Related issues
resolves #15870