Skip to content
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(new sink): New nats sink #3605

Merged
merged 28 commits into from
Nov 16, 2020
Merged

Conversation

erhlee-bird
Copy link
Contributor

Introduces a new NATS log sink.
Closes #1399.

@erhlee-bird
Copy link
Contributor Author

To begin with, the code is basically just a straight copy of the console sink.
I've been able to compile and confirm with a basic setup that messages are being sent to NATS.

I copied some of the structure from various PRs I found in the repo, but definitely am missing a ton of things like documentation and metadata.

Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
@jamtur01
Copy link
Contributor

Hi @erhlee-bird! Thanks for contributing. Anything we can help with here to get this out of draft?

@erhlee-bird
Copy link
Contributor Author

erhlee-bird commented Oct 14, 2020

Hey @jamtur01, I just started looking at this again today.

I've verified that I have a steel-thread running via hand-jammed integration tests.

I believe the next steps are

  • populate .meta/sinks/nats.toml.erb with requisite data
  • add in unit and integration tests
  • rebase to latest
  • run through the staging ci with bors?

Am I missing anything there?

  • update code to work with latest conventions on master
  • add cue-based documentation

@jamtur01 jamtur01 marked this pull request as ready for review October 14, 2020 18:06
@jamtur01 jamtur01 added the domain: sinks Anything related to the Vector's sinks label Oct 14, 2020
@jamtur01
Copy link
Contributor

We just replaced the .meta stuff with Cue-based docs - have a look at the docs in docs/ for examples and we're not using Bors right now due to some bugs but otherwise, that sounds great!

Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
@erhlee-bird
Copy link
Contributor Author

@jamtur01, I think current is ready for review!

Thanks for the poke

@jamtur01
Copy link
Contributor

@erhlee-bird Looks like you just need to run cue fmt on the docs:

cue fmt docs/**/*.cue

Will work.

Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Cargo.toml Outdated Show resolved Hide resolved
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
@erhlee-bird
Copy link
Contributor Author

I'm not sure why the cue docs check is failing.
Any pointers there? I don't have any errors locally running make check-docs.

Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great, thanks @erhlee-bird . I left some inline comments to address, but it is pretty close.

In addition to the in-line comments, I'd like to see us handle failed publishes differently by:

  • Using the acker() from the SinkContext (available in build) to only ack messages that were successfully published
  • Retry failed publishes indefinitely
  • Set reconnect_buffer_size on the nats client to 0 bytes so that the client doesn't buffer internally (to avoid message loss)

You can see the kafka sink for an example of the acking (open https://github.com/timberio/vector/blob/master/src/sinks/kafka.rs and search for "ack"). This will allow messages to sit in an intermediate buffer in vector until they can successfully be published to nats.

Let me know if that isn't clear.

Just noting that we should probably follow this work up with:

  • TLS support
  • Credentials support (user/pass, token, credentials file, nkey)

We can open separate issues for those once this is merged.

Thanks again!

src/sinks/nats.rs Outdated Show resolved Hide resolved
src/sinks/nats.rs Outdated Show resolved Hide resolved
}

configuration: {
url: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we've switched to calling this sort of configuration endpoint per #1775, but that does feel weird in this context. I like url. I'm curious what @ktff thinks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I saw the endpoint for other examples like Pulsar that looked similar.

I set it to url just to try and mimic the verbiage used by the nats.go library and the nats.io docs, but totally understand if it would make more sense to stay consistent within Vector context.

impl NatsSink {
fn new(config: NatsSinkConfig) -> Self {
let options = nats::Options::new();
let nc = options.connect(&config.url).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems to initialize the outbound connection, which we generally try to avoid during component build time. Could we defer the connect to the run method? We should emit an error and propagate up an Err if it fails to connect (rather than panicing). I do note that it handles reconnects internally.

Also, could we set a user configurable name here? https://docs.rs/nats/0.8.0/nats/struct.Options.html#method.with_name . We could default to vector but let users override in the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a separate connect function to the SinkConfig.

Added the name config item.

src/sinks/nats.rs Outdated Show resolved Hide resolved
src/sinks/nats.rs Outdated Show resolved Hide resolved
src/sinks/nats.rs Outdated Show resolved Hide resolved
src/sinks/nats.rs Outdated Show resolved Hide resolved
src/sinks/nats.rs Outdated Show resolved Hide resolved
src/sinks/nats.rs Outdated Show resolved Hide resolved
@jszwedko
Copy link
Member

I neglected that we aren't supporting encoding configuration here either. It would be nice to do that for consistency before this is merged. Again, the kafka sink (or the console sink) would be good references here.

Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
@erhlee-bird
Copy link
Contributor Author

@jszwedko I think I addressed all of your comments and am ready for another review.

Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few last comments, but otherwise this looks good! Thanks for all of your work @erhlee-bird

And yes, @praveenperera , if you could sign-off the two commits, that would fix the DCO check.

src/sinks/nats.rs Outdated Show resolved Hide resolved
src/sinks/nats.rs Outdated Show resolved Hide resolved
docs/reference/components/sinks/nats.cue Show resolved Hide resolved
@jszwedko
Copy link
Member

jszwedko commented Nov 12, 2020

I would like to get one more review on this just given it is a new component. @JeanMertz do you mind taking a look? Neglected that @lukesteensen was already tagged here.

@praveenperera
Copy link
Contributor

A few last comments, but otherwise this looks good! Thanks for all of your work @erhlee-bird

And yes, @praveenperera , if you could sign-off the two commits, that would fix the DCO check.

Hey i’m not sure how to sign off on old commits. Since there have been new commits by @erhlee-bird after mine. I could rebase but don’t think I have permission to write to this branch.

@jszwedko
Copy link
Member

@praveenperera 👍 it looks like you have access now at least? I think you can:

$ git rebase -i HEAD~20
# mark 2f8fcd0 and 9aab169 for edit
# when the rebase pauses, `git commit --amend --signoff && git rebase --continue`
$ git push -f

praveenperera and others added 5 commits November 12, 2020 14:52
Signed-off-by: Praveen Perera <praveen@avencera.com>
Signed-off-by: Praveen Perera <praveen@avencera.com>
Store `nats::Options` in owned struct
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
Signed-off-by: Eric Lee <erhlee.bird@gmail.com>
@jszwedko jszwedko removed the request for review from JeanMertz November 13, 2020 14:57
Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed one more commit adding the integration tests to CI and an example of templating for the subject config.

Otherwise, this looks good to me! Thanks for pushing this over the line @erhlee-bird and @praveenperera !

And template example for subject config

Signed-off-by: Jesse Szwedko <jesse@szwedko.me>
@jszwedko jszwedko removed the request for review from jamtur01 November 13, 2020 16:51
Copy link
Member

@lukesteensen lukesteensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@jamtur01 jamtur01 merged commit b8f83d7 into vectordotdev:master Nov 16, 2020
@jamtur01
Copy link
Contributor

jamtur01 commented Nov 16, 2020

@erhlee-bird @praveenperera Thanks! Awesome contribution.

image

mengesb pushed a commit to jacobbraaten/vector that referenced this pull request Dec 9, 2020
Co-authored-by: James Turnbull <james@lovedthanlost.net>
Co-authored-by: Praveen Perera <ppraveen25@gmail.com>
Co-authored-by: Jesse Szwedko <jesse@szwedko.me>
Signed-off-by: Brian Menges <brian.menges@anaplan.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: sinks Anything related to the Vector's sinks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New nats sink
5 participants