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

Allow messages published on $JS.EVENT.ADVISORY.API to be exported via a service #4275

Closed
piotrpio opened this issue Jun 28, 2023 · 0 comments · Fixed by #4302
Closed

Allow messages published on $JS.EVENT.ADVISORY.API to be exported via a service #4275

piotrpio opened this issue Jun 28, 2023 · 0 comments · Fixed by #4302
Assignees

Comments

@piotrpio
Copy link
Contributor

piotrpio commented Jun 28, 2023

Use case:

I want to aggregate JetStream advisory events from multiple accounts on one aggregate account. This would allow nats-surveyor to maintain a single connection with the server to gather JetStream advisory metrics from multiple accounts.

I have the following config:

jetstream: {max_mem_store: 64GB, max_file_store: 10TB}
accounts {
	A {
		jetstream: enabled
		users: [ {user: pp, password: foo} ]
		imports [
			{ service: { account: AGG, subject: '$JS.EVENT.ADVISORY.ACC.A.>' }, to: '$JS.EVENT.ADVISORY.>' }
		]
	}
	AGG {
		users: [ {user: agg, password: foo} ]
		exports: [
			{ service: '$JS.EVENT.ADVISORY.ACC.*.>', response: Singleton, account_token_position: 5 }
		]
	}
}

Intended behavior

  1. On JetStream events, server publishes messages on $JS.EVENT.ADVISORY.> in account A.
  2. Account AGG exports a service with account_token_position on which the advisory events should be forwarded
  3. All advosory messages from account A should be available on $JS.EVENT.ADVISORY.ACC.A.>

Actual behavior
Advisory events published on subjects other than $JS.EVENT.ADVISORY.API (e.g. $JS.EVENT.ADVISORY.STREAM.CREATED.ORDERS) are mapped correctly and available on account AGG. Messages published on $JS.EVENT.ADVISORY.API (the audit messages) are not available on AGG.

Additional information

  • Behavior is the same whether or not mapping is used, e.g. exporting $JS.EVENT.> -> $JS.EVENT.> does not fix the issue
  • Intended behavior can be achieved using stream export from account A to account AGG and in that case it works fine (I can subscribe on $JS.EVENT.ADVOSORY.ACC.A.> and all events are available. However, using service exports would be a desirable solution since with services I can utilize account_token_position and have a single export on account AGG instead of an import per account.
  • This seems to be caused by some advisory events being published using Server.sendInternalAccountMsg() (those are not forwarded) - https://github.com/nats-io/nats-server/blob/main/server/jetstream_api.go#L4332C29-L4332C29
  • The same behavior is present when attempting to export service latency subjects (which also uses sendInternalAccountMsg())
  • I am not sure whether this behavior is intentional or not, but seems to be inconsistent given it differs depending on whether stream export or service export is used.

I added a test to show the issue: 3b19e16
The first test (TestJetStreamAccountImportJSAdvisoriesAsService) uses service exports (and fails) and the second uses stream exports (which succeeds). Both tests have the same scenario:

  1. On account JS, subscribe to $JS.EVENT.ADVISORY.>
  2. On account AGG, subscribe to $JS.EVENT.ADVISORY.ACC.JS.>
  3. Create a stream on account JS
  4. Expect two messages on both subscriptions:
  • an action event on $JS.EVENT.ADVISORY.STREAM.CREATED.ORDERS
  • an api audit event on $JS.EVENT.ADVISORY.API
derekcollison added a commit that referenced this issue Jul 12, 2023
This should fix #4275 by allowing advisories to be copied into other
accounts via service imports.

Signed-off-by: Neil Twigg <neil@nats.io>
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 a pull request may close this issue.

2 participants