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(outputs.nats): Introduce NATS Jetstream option #14236

Merged
merged 18 commits into from
Jan 23, 2024

Conversation

neelayu
Copy link
Contributor

@neelayu neelayu commented Nov 1, 2023

Required for all PRs

resolves #14235

@telegraf-tiger telegraf-tiger bot added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins labels Nov 1, 2023
Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I have added some initial high-level questions.

Additionally, please resolve the test issues:

plugins/outputs/nats/nats.go:124:29  revive   unused-parameter: parameter 'stream' seems to be unused, consider removing or renaming it as _
plugins/outputs/nats/nats.go:124:29  unparam  `(*NATS).createStream` - `stream` is unused

plugins/outputs/nats/nats_test.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats_test.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/README.md Outdated Show resolved Hide resolved
plugins/outputs/nats/README.md Outdated Show resolved Hide resolved
plugins/outputs/nats/README.md Outdated Show resolved Hide resolved
@powersj powersj added the waiting for response waiting for response from contributor label Nov 7, 2023
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/sample.conf Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
@neelayu
Copy link
Contributor Author

neelayu commented Nov 17, 2023

@powersj and @Hipska Sorry I was occupied with work, so did not get a chance to review the comments. I'll address them in the coming week. Thank you for your patience

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Nov 17, 2023
@neelayu neelayu requested review from Hipska and powersj November 30, 2023 10:26
Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Thank you for the updates! I think if we can get the config cleaned up, we are nearly there.

Thanks again!

plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/README.md Outdated Show resolved Hide resolved
plugins/outputs/nats/README.md Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
## Jetstream specific configuration. If specified, telegraf will use Jetstream to publish messages
# [outputs.nats.jetstream]
## Specifies whether telegraf should create the stream at the startup or not. It will only create if it doesn't exist.
# auto_create_stream = true
Copy link
Contributor

Choose a reason for hiding this comment

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

This default value is missing from the init or Init methods, so default currently is false instead of true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reworked the logic. can you go through it again?

plugins/outputs/nats/nats_test.go Show resolved Hide resolved
@neelayu neelayu force-pushed the nats-js branch 2 times, most recently from 631cedb to 7b876c6 Compare January 5, 2024 13:02
Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Thanks for the large update! I have a couple suggestions to clean up the config and I want to chat with the other maintainer about the use of the TOML parser in the plugin. Otherwise, this looks great.

plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/README.md Outdated Show resolved Hide resolved
plugins/outputs/nats/sample.conf Outdated Show resolved Hide resolved
plugins/outputs/nats/nats_test.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats_test.go Show resolved Hide resolved
Copy link
Contributor

@Hipska Hipska 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, still have a look at the linters as they still fail.

Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Thanks for driving this!

I rebased on master and cleaned up the one lint issue.

@powersj powersj added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Jan 17, 2024
@powersj powersj assigned srebhan and unassigned powersj Jan 17, 2024
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@neelayu thanks for the nice contribution. I do have some comments...

plugins/outputs/nats/sample.conf Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
if err != nil {
return fmt.Errorf("failed to create or update stream: %w", err)
}
n.Log.Infof("stream (%s) successfully created or updated", n.Jetstream.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be a debug message? In any case it should start with an uppercase letter...

Comment on lines 162 to 236
func (n *NATS) convertToJetstreamConfig(streamConfig *jetstream.StreamConfig) {
telegrafStreamConfig := reflect.ValueOf(n.Jetstream).Elem()
natsStreamConfig := reflect.ValueOf(streamConfig).Elem()
for i := 0; i < telegrafStreamConfig.NumField(); i++ {
destField := natsStreamConfig.FieldByName(telegrafStreamConfig.Type().Field(i).Name)
if destField.IsValid() && destField.CanSet() {
destField.Set(telegrafStreamConfig.Field(i))
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This has footgun potential as you circumvent Golangs type-checking. If for example one field is removed upstream (or the type is changed) you silently will ignore the Telegraf setting and nobody will notice until some unexpected behavior happens. I really would feel better if we explicitly set the config-fields here (even though this bloats the code) or if we use the jetstream.StreamConfig directly in the Telegraf configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using jetstream.StreamConfig directly was done before, but rejected since it didn't have toml conversion, but only json.

Copy link
Member

Choose a reason for hiding this comment

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

Well it is not absolutely necessary to have toml tags, but I agree and would prefer the explicit setting of options. The question is, do we really need to expose all those options or can we live with the defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is not necessary to have toml tags. but there are some fields which did not support toml unmarshalling such as retention, limits. This is the reason why in the configuration, users are expected to pass integer values for such fields because it we can resuse the Stringer interface defined on those types.

There are use cases when we definitely need full set of options.

Copy link
Member

Choose a reason for hiding this comment

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

@neelayu ok, so we can go with the full set of options, but I really think we should not hamper the user experience with the integers just because it's more convenient to use the String() interface. So please use speaking-strings where possible and do the explicit transformation. @powersj what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will make the changes.

@srebhan srebhan changed the title feat(outputs.nats): Introduce NATS Jetstream as an option for NATS output plugin feat(outputs.nats): Introduce NATS Jetstream option Jan 18, 2024
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@neelayu thanks for the update, just a few more minor comments. I added suggestions so it is quick for you to change those. I do have one more question about subject appending (in the code) and would love to hear your opinion there.

plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats_test.go Outdated Show resolved Hide resolved
neelayu and others added 2 commits January 22, 2024 15:59
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
@neelayu
Copy link
Contributor Author

neelayu commented Jan 22, 2024

@srebhan Thanks for your code suggestions. One important thing I learnt in this PR is, even if the code becomes verbose, its okay to do it. Its nice to see that telegraf doesn't compromise on code quality 😄

plugins/outputs/nats/nats.go Outdated Show resolved Hide resolved
plugins/outputs/nats/nats.go Show resolved Hide resolved
@telegraf-tiger
Copy link
Contributor

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

@neelayu thank you for all the effort you put into this PR!

@srebhan srebhan merged commit 06c1366 into influxdata:master Jan 23, 2024
26 checks passed
@github-actions github-actions bot added this to the v1.30.0 milestone Jan 23, 2024
hhiroshell pushed a commit to hhiroshell/telegraf that referenced this pull request Feb 1, 2024
Co-authored-by: Joshua Powers <powersj@fastmail.com>
Co-authored-by: Thomas Casteleyn <thomas.casteleyn@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Jetstream in NATS output plugin
4 participants