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

✨ use globally unique connection IDs for providers #3492

Merged
merged 3 commits into from
Mar 6, 2024

Conversation

imilchev
Copy link
Member

@imilchev imilchev commented Mar 5, 2024

Use globally unique connection IDs for providers. This allows us to call Connect multiple times for providers without having to create new connections in the process. It also helps us to do cross-provider connections in the future since 1 asset will always have 1 connection ID for all providers it talks to.

New flow
Connection IDs are assigned by the coordinator. If a connection has no ID yet, it gets one from the coordinator which makes sure it is globally unique.

  • Made sure cloned inventories are cloned without the connection ID. This makes sure discovered assets get their own connection ID
  • Made sure that we first check if a connection with this ID exists for the current provider. If there is one, we return that and we do not create a new connection
  • This flow is only used for cnquery/cnspec clients that support it. Old clients will use the old way

Old flow
The old flow is maximally contained in the base Service struct that is reused by all providers. When we clean that up in v12, most of the changes will be in that struct. The old flow is triggered only when we attempt to create a runtime with connection ID 0. This indicates cnquery/cnspec is an old version and doesn't set IDs externally. The old flow will also create a new runtime for an asset that calls Connect for a second time

imilchev added 2 commits March 5, 2024 14:30
Signed-off-by: Ivan Milchev <[email protected]>
Copy link
Contributor

github-actions bot commented Mar 5, 2024

Test Results

2 849 tests   2 848 ✅  1m 17s ⏱️
  186 suites      1 💤
    5 files        0 ❌

Results for commit 1f22fc6.

♻️ This comment has been updated with latest results.

@@ -417,7 +417,7 @@ func (cfg *Config) Clone(opts ...CloneOption) *Config {
}

clonedObject := proto.Clone(cfg).(*Config)

clonedObject.Id = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

we aren't relying on the Id to be copied anywhere, where Clone is called. That's why I opt to make it default that the ID isn't copied. If in the future we have cases that we need to copy the ID too, we can add an option to clone the ID too and fix it with that:

clone := inv.Clone(WithId())

Signed-off-by: Ivan Milchev <[email protected]>
@imilchev imilchev marked this pull request as ready for review March 5, 2024 15:05
Copy link
Member

@arlimus arlimus left a comment

Choose a reason for hiding this comment

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

Awesome!! Thank you for creating globally unique conn IDs ⭐

@imilchev imilchev merged commit eed1b07 into main Mar 6, 2024
14 checks passed
@imilchev imilchev deleted the ivan/global-connection-ids branch March 6, 2024 10:31
@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants