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: bootstrap and timeout initialization #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tore-statsig
Copy link
Contributor

There are two main pieces missing to initialization to make this more robust. We dont want to block application startup because of a) a network request taking too long or b) failure to initialize statsig.

This adds two configuration options:

  1. an initialization timeout
  2. a bootstrap spec

To address this. Bootstrapping will still attempt to sync from the network

end
end

defp update_specs(specs) do
Copy link

Choose a reason for hiding this comment

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

i would expect this to return the updated configs and not just the time, which doesn't seem to be added to the configs that have been updated.

update_specs(response)
{:ok, %{state | last_sync_time: new_time}}
rescue
error ->
Copy link

Choose a reason for hiding this comment

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

what can happen to cause this? It's a little strange to see a try/rescue in elixir code.
I would actually make it so that update_specs can't raise.

@@ -41,9 +47,12 @@ defmodule Statsig.Configs do
@impl true
def init(_) do
:ets.new(@table_name, [:named_table, :set, :public])
initial_state = State.new()
initial_state = case init_from_bootstrap() do
Copy link

Choose a reason for hiding this comment

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

nit: this looks like it wasn't formatted.

Comment on lines +22 to +23
interval = reload_interval()
%__MODULE__{reload_interval: interval}
Copy link

Choose a reason for hiding this comment

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

i kind of prefer the old one.

end

test "uses bootstrapped gate values" do
{:ok, result} = Statsig.check_gate(%Statsig.User{user_id: "12345"}, "test_numeric_user_id")
Copy link

Choose a reason for hiding this comment

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

for gates, there's a three way logic here that I'm not sure you intended.
One option is some kind of error occurring, the other is that the result is true or false.

Can you describe how checking a gate can fail? As a user, I'd prefer:

if Statsig.check_gate?(...) do 
  ...
 end

@@ -41,9 +47,12 @@ defmodule Statsig.Configs do
@impl true
def init(_) do
:ets.new(@table_name, [:named_table, :set, :public])
initial_state = State.new()
initial_state = case init_from_bootstrap() do
Copy link

Choose a reason for hiding this comment

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

Can you document the spec?

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.

2 participants