-
Notifications
You must be signed in to change notification settings - Fork 700
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
Adjust consumer creation to nats-server v2.9.0 #1080
Changes from all commits
8842548
7d21454
2bdb6d0
c101ec9
583e80c
5c4567f
069041d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,34 +259,45 @@ type consumerResponse struct { | |
|
||
// AddConsumer will add a JetStream consumer. | ||
func (js *js) AddConsumer(stream string, cfg *ConsumerConfig, opts ...JSOpt) (*ConsumerInfo, error) { | ||
if cfg != nil && cfg.Durable != _EMPTY_ { | ||
consInfo, err := js.ConsumerInfo(stream, cfg.Durable) | ||
if cfg == nil { | ||
cfg = &ConsumerConfig{} | ||
} | ||
consumerName := cfg.Name | ||
if consumerName == _EMPTY_ { | ||
consumerName = cfg.Durable | ||
} | ||
if consumerName != _EMPTY_ { | ||
consInfo, err := js.ConsumerInfo(stream, consumerName) | ||
if err != nil && !errors.Is(err, ErrConsumerNotFound) && !errors.Is(err, ErrStreamNotFound) { | ||
return nil, err | ||
} | ||
|
||
if consInfo != nil { | ||
sameConfig := checkConfig(&consInfo.Config, cfg) | ||
if sameConfig != nil { | ||
return nil, fmt.Errorf("%w: creating consumer %q on stream %q", ErrConsumerNameAlreadyInUse, cfg.Durable, stream) | ||
return nil, fmt.Errorf("%w: creating consumer %q on stream %q", ErrConsumerNameAlreadyInUse, consumerName, stream) | ||
} | ||
} | ||
} | ||
|
||
return js.upsertConsumer(stream, cfg, opts...) | ||
return js.upsertConsumer(stream, consumerName, cfg, opts...) | ||
} | ||
|
||
func (js *js) UpdateConsumer(stream string, cfg *ConsumerConfig, opts ...JSOpt) (*ConsumerInfo, error) { | ||
if cfg == nil { | ||
return nil, ErrConsumerConfigRequired | ||
} | ||
if cfg.Durable == _EMPTY_ { | ||
consumerName := cfg.Name | ||
if consumerName == _EMPTY_ { | ||
consumerName = cfg.Durable | ||
} | ||
if consumerName == _EMPTY_ { | ||
return nil, ErrConsumerNameRequired | ||
} | ||
return js.upsertConsumer(stream, cfg, opts...) | ||
return js.upsertConsumer(stream, consumerName, cfg, opts...) | ||
} | ||
|
||
func (js *js) upsertConsumer(stream string, cfg *ConsumerConfig, opts ...JSOpt) (*ConsumerInfo, error) { | ||
func (js *js) upsertConsumer(stream, consumerName string, cfg *ConsumerConfig, opts ...JSOpt) (*ConsumerInfo, error) { | ||
if err := checkStreamName(stream); err != nil { | ||
return nil, err | ||
} | ||
|
@@ -304,13 +315,21 @@ func (js *js) upsertConsumer(stream string, cfg *ConsumerConfig, opts ...JSOpt) | |
} | ||
|
||
var ccSubj string | ||
if cfg != nil && cfg.Durable != _EMPTY_ { | ||
if err := checkConsumerName(cfg.Durable); err != nil { | ||
return nil, err | ||
} | ||
ccSubj = fmt.Sprintf(apiDurableCreateT, stream, cfg.Durable) | ||
if consumerName == _EMPTY_ { | ||
// if consumer name is empty, use the legacy ephemeral endpoint | ||
ccSubj = fmt.Sprintf(apiLegacyConsumerCreateT, stream) | ||
} else if err := checkConsumerName(consumerName); err != nil { | ||
return nil, err | ||
} else if !js.nc.serverMinVersion(2, 9, 0) || (cfg.Durable != "" && js.opts.featureFlags.useDurableConsumerCreate) { | ||
// if server version is lower than 2.9.0 or user set the useDurableConsumerCreate flag, use the legacy DURABLE.CREATE endpoint | ||
ccSubj = fmt.Sprintf(apiDurableCreateT, stream, consumerName) | ||
} else { | ||
ccSubj = fmt.Sprintf(apiConsumerCreateT, stream) | ||
// if above server version 2.9.0, use the endpoints with consumer name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not checking the server name, what I think should be done is just in checking if the new config Name is specified. If it is, then that signals the intent to use the new API endpoints. If user specifies Name, but connects to an older server, they will get a timeout: this is not ideal, but I don't think checking server version is reliable anyway (could be connected to one 2.9.0, but server accepting the request be older version, or vice versa). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, I'll change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, just to clarify - when user provides only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should then possibly set the Name to the Durable before calling js.AddConsumer(). But then, I agree that we have the situation where this is not a user choice and so connecting to older server would be a problem... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So from what I understand, we have following options:
Looking at those, I would still lean towards option 3 - I could strip version check in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pure version orientated approach means users do not get a chance to say they need time to update infrastructure like ACLs and so forth to start using it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, not sure how big of an issue that would be vs forcing the user to intentionally start using the new API by changing their application code (IMO this transition should ideally be seamless, as the user of client library I don't need to care about the API subjects). What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a class of user who care deeply to lock down the APIs according to needs. Also a class of user who have spent considerable time in navigating the API subjects for cross account use via imports and exports. A major design feature of these API subjects is to enable that lock down. Or to be selectively imported to manage permissions and restrictions. The Venn diagrams of users likely to pay for NATS and those who care deeply for subject security probsbly has quite a lot of overlap. So you might not care, but I think we should consider if introducing new features in the most user hostile way possible is perhaps not the right thing - especially considering the users most likely affected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue with the ACL is possibly real, but in reality, the same logic can be applied the other way. If they deploy the new client but don't update the servers, they can update their ACLs and then deploy the servers. The client possibly could have a way of rejecting the use of the new API (I do for test purposes). But at some point, the clients become too complex and too flexible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question is how do users know? Do we have effective communication channels to tell people about these changes? Release notes and blog post are notoriously ineffective - especially as ours tend to be enormous. So do we feel users are served well enough by the communication and warning we give them about upcoming changes? In another world these would be considered breaking changes and tooling and just human behaviour is aware of major changes. These are not just new features. They majorly change existing code simply because it happens to point at another version server. As much as I loathe the go major version change behaviour this does demonstrate the utility of that. |
||
if cfg.FilterSubject == _EMPTY_ || cfg.FilterSubject == ">" { | ||
ccSubj = fmt.Sprintf(apiConsumerCreateT, stream, consumerName) | ||
} else { | ||
ccSubj = fmt.Sprintf(apiConsumerCreateWithFilterSubjectT, stream, consumerName, cfg.FilterSubject) | ||
} | ||
} | ||
|
||
resp, err := js.apiRequestWithContext(o.ctx, js.apiSubj(ccSubj), req) | ||
|
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.
Seems like a good compromise to me, allows people to opt out of a feature should they be in a situation where server updates isnt possible.
Of course in other projects this is opt in -> opt out -> remove flag over 3 releases. But seems this is the best we can do at present.
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.
The main issue with this is that the default client behavior is still to use the new feature. So really they have to change code, so they could also hold upgrading the server or the client. If there's a flag, my guess is it should be opt-in, rather than opt-out.
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.
My preference would be an opt-in also.
To your point "they could also hold upgrading the server"....this is just not the case, our default answer to any support question is "upgrade the server", users might not be in a position to cange code etc, hence why I prefer opt-in.
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 guess the way these type of changes are rolled out is to wait for a few releases before making the default if there is no alternative, I like the feature flags approach from the PR, maybe we could have eventually an option for the JetStream context to always use latest features instead or to enable a subset of them.
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.
UseLatestJSFeatures()
would be a nice addition in the future for sure. I would probably lean towards merging this PR as is (with having the opt-out option if needed, to be deprecated and removed in future releases), not to change the behavior vs other clients right now. If we decide we want to have future features like this opt-in, we need to be consistent across all clients. As some of the clients are already released without a feature flag, I don't think it's good to have this discrepancy.