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: use tenants from external source #1967

Merged
merged 5 commits into from
Nov 12, 2024

Conversation

icehaunter
Copy link
Contributor

Allows configuring the external source to pull the tenant information from. External source is expected to be an Electric instance.

Notable changes:

  1. If no external source is provided, the system always functions in a single-tenant mode
  2. Since tenant id is not preserved across restarts, in single-tenant mode we hard-code the id to UUID0
  3. If external source is not available, the calls to add a db will fail
  4. If external source has changed while this instance was down, it will try to delete all tenant information it can, pending a feature to clean up shapes after deleted tenants

Closes #1961

Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit 04802ce
🔍 Latest deploy log https://app.netlify.com/sites/electric-next/deploys/67334e7e942328000742f8f6
😎 Deploy Preview https://deploy-preview-1967--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@icehaunter icehaunter force-pushed the ilia/1961-tenants-from-external-api branch from 73820fd to 04802ce Compare November 12, 2024 12:47
@icehaunter icehaunter force-pushed the ilia/1961-tenants-from-external-api branch from 04802ce to f011ea0 Compare November 12, 2024 12:54
Copy link
Contributor

@robacourt robacourt 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 to me

Copy link
Contributor

@msfstef msfstef 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, left some nits!

{:noreply, %{state | load_successful?: true}}

{:error, :unreachable} ->
Process.send_after(self(), :retry_initialization, 500)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: need to add a :backoff here perhaps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I want to. This is called only at startup and normal operations are not working (including serving existing shapes) until this call resolves, so we probably want to hammer the API

Copy link
Contributor

Choose a reason for hiding this comment

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

It's just that, unless it fails because of some transitory issue, it will almost definitely fail because of a configuration issue/mismatch between the API and Electric, and it will keep erroring every 500ms until we manually fix it. The backoff would ensure that if it's a transitory problem it resolves quickly, and if it is not it doesn't needlessly spam the API since our manual fixes are going to happen in the order of minutes hours or days

do: String.replace(string, "%{instance_id}", to_string(instance_id))

@spec collect_ops(Enumerable.t()) :: {map(), map()}
defp collect_ops(ops) do
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we had written an elixir client (?) which we could reuse - if not ignore me!

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@balegas
Copy link
Contributor

balegas commented Nov 12, 2024

@icehaunter can you elaborate a bit more on

If external source has changed while this instance was down, it will try to delete all tenant information it can, pending a feature to clean up shapes after deleted tenants

I read this as: if electric is briefly unavailable and misses an update to some of the tenants it hosts, it will drop all tenants info. Why is that and why can't we do better?

@kevin-dp
Copy link
Contributor

@icehaunter can you elaborate a bit more on

If external source has changed while this instance was down, it will try to delete all tenant information it can, pending a feature to clean up shapes after deleted tenants

I read this as: if electric is briefly unavailable and misses an update to some of the tenants it hosts, it will drop all tenants info. Why is that and why can't we do better?

It won't. What @icehaunter meant is that tenants may have been added and/or deleted while Electric was down. On restart, Electric will get these updates from the control plane. For each tenant that was deleted, Electric will remove the tenant's shape data from disk (remains to be implemented). For each tenant that was added, Electric will create that tenant.

@icehaunter icehaunter merged commit ffd7e13 into main Nov 12, 2024
25 checks passed
@icehaunter icehaunter deleted the ilia/1961-tenants-from-external-api branch November 12, 2024 16:14
end
end)

Enum.reduce(to_add, state, fn %{"id" => tenant_id, "connection_uri" => connection_url},
Copy link
Contributor

Choose a reason for hiding this comment

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

@icehaunter this should be "connection_url" => connection_url - we don't have a way to rename things within the shape currently, could fix this and if possible add a test please?

msfstef added a commit that referenced this pull request Nov 13, 2024
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.

Use external API for tenant information
5 participants