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

Improve jetstream documentation #1532

Merged
merged 6 commits into from Jan 26, 2024
Merged

Improve jetstream documentation #1532

merged 6 commits into from Jan 26, 2024

Conversation

piotrpio
Copy link
Collaborator

This is the first part of improving jetstream package documentation.
This PR updates documantation for core jetstream (no KV or Object Store), by expanding docs to struct fields, as well as having more detailed documentation on public methods and interfaces.

What will be added in subsequent PRs:

  • KV/Object store documentation improvements, together with respective section in README
  • Code examples

Signed-off-by: Piotr Piotrowski piotr@synadia.com

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio piotrpio requested a review from Jarema January 24, 2024 16:32
Copy link
Member

@Jarema Jarema 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 huge improvement for the docs!

Some comments added.

jetstream/consumer.go Show resolved Hide resolved
jetstream/consumer.go Outdated Show resolved Hide resolved
jetstream/consumer.go Show resolved Hide resolved
jetstream/consumer.go Outdated Show resolved Hide resolved
jetstream/consumer.go Outdated Show resolved Hide resolved
OptStartTime *time.Time `json:"opt_start_time,omitempty"`
ReplayPolicy ReplayPolicy `json:"replay_policy"`
// FilterSubjects is a set of subjects that overlap with the subjects
// bound to the stream to filter delivered messages. Requires
Copy link
Member

Choose a reason for hiding this comment

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

same point on overlap as before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

jetstream/jetstream.go Outdated Show resolved Hide resolved
jetstream/jetstream.go Show resolved Hide resolved
// Consumer interface is returned, serving as a hook to operate on a consumer (e.g. fetch messages)

// CreateConsumer creates a consumer on a given stream with given
// config. If consumer already exists, ErrConsumerExists is returned.
Copy link
Member

Choose a reason for hiding this comment

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

It will not return error if consumer already exists, but the config is exactly the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

jetstream/stream_config.go Outdated Show resolved Hide resolved
piotrpio and others added 2 commits January 25, 2024 10:06
Co-authored-by: Tomasz Pietrek <tomasz@nats.io>
Co-authored-by: Tomasz Pietrek <tomasz@nats.io>
Copy link
Contributor

@ripienaar ripienaar left a comment

Choose a reason for hiding this comment

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

really great effort

jetstream/consumer.go Show resolved Hide resolved
jetstream/consumer.go Outdated Show resolved Hide resolved
FetchNoWait(batch int) (MessageBatch, error)
// Consume can be used to continuously receive messages and handle them with the provided callback function

// Consume can be used to continuously receive messages and handle them
Copy link
Contributor

Choose a reason for hiding this comment

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

Under what circumstances will it not be continuous? Similar question on the description of the struct itself and others mentioning continuous consumption.

I don't know this API so maybe asking dumb questions sorry

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is I think not worded properly. Consume and Messages are continuous and will never stop with exception of a few conditions:

  • user calls Stop/Drain
  • consumer deleted
  • consumer not found after server reconnect (after multiple retries)

That's true for standard pull consumer anyway, for ordered consumer "consumer deleted" is not terminal - we just create a new one. So I don't think this is something that I would put as a comment on the Consumer interface.

I will reword the descriptions to make sure it's clear that those methods are intentionally endless.

// Next is used to retrieve the next message from the stream.
// This method will block until the message is retrieved or timeout is reached.

// Next is used to retrieve the next message from the stream. This
Copy link
Contributor

Choose a reason for hiding this comment

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

from the consumer... I know its technically fetching from the stream but saying its from the consumer makes it clear it is subject to all the filtering and policies configured there maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed.

// message, including its sequence numbers and timestamp.
Delivered SequenceInfo `json:"delivered"`

// AckFloor tracks the highest sequence number of a message that has
Copy link
Contributor

Choose a reason for hiding this comment

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

Indicates the message before the first unacknowledged message - maybe something like that? It is confusing for sure

jetstream/stream_config.go Show resolved Hide resolved
jetstream/stream_config.go Show resolved Hide resolved
Deleted []uint64 `json:"deleted"`

// NumDeleted is the number of messages that have been removed from the
// stream.
Copy link
Contributor

Choose a reason for hiding this comment

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

is a bit more nuance than just have been removed. It's about gaps so if the stream has 1,10,11 deleted is 9, but if the stream has 10,11 deleted is 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's another weird tough thing to explain concisely...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to:

		// NumDeleted is the number of messages that have been removed from the
		// stream. Only deleted messages causing a gap in stream sequence numbers
		// are counted. Messages deleted at the beginning or end of the stream
		// are not counted.

// messages on.
NumSubjects uint64 `json:"num_subjects"`

// Subjects is a list of subjects the stream has received messages on.
Copy link
Contributor

Choose a reason for hiding this comment

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

list of subjects and message counts per subject.

If asked do you do paged requests to get them all behind the scenes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, since recently I do (it was actually missing in the new API)

jetstream/stream_config.go Show resolved Hide resolved
@jclasley
Copy link

Thank you so much for this, it is going to make adoption of NATS easier for teams and reinforces my faith in the team moving forward!

@piotrpio piotrpio force-pushed the improve-jetstream-docs branch 2 times, most recently from 48e18b2 to d5135d8 Compare January 26, 2024 13:21
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio
Copy link
Collaborator Author

Thanks for the detailed reviews. I believe I address all of the comments (still not sure what to do with the links: #1532 (comment)).

Copy link
Contributor

@ripienaar ripienaar left a comment

Choose a reason for hiding this comment

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

amazing, some minor nits else LGTM

@@ -0,0 +1,89 @@
package jetstream
Copy link
Contributor

Choose a reason for hiding this comment

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

needs copyright blurb

@@ -0,0 +1,26 @@
package jetstream
Copy link
Contributor

Choose a reason for hiding this comment

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

copyright

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

LGTM!

Great effort!

@piotrpio piotrpio merged commit 94eaa2a into main Jan 26, 2024
2 checks passed
@piotrpio piotrpio deleted the improve-jetstream-docs branch January 26, 2024 18:44
@evanofslack
Copy link
Contributor

I just wanted to mention, these doc additions are super helpful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants