Skip to content

Commit

Permalink
fix flag_config_fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Aug 2, 2024
1 parent 721113f commit 1146fa3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/experiment/flag/flag_config_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def initialize(api_key, logger, server_url = 'https://api.lab.amplitude.com')
@api_key = api_key
@server_url = server_url
@logger = logger
@http = PersistentHttpClient.get(server_url, { read_timeout: FLAG_CONFIG_TIMEOUT }, @api_key)
end

# Fetch local evaluation mode flag configs from the Experiment API server.
Expand All @@ -24,7 +23,8 @@ def fetch_v1
'X-Amp-Exp-Library' => "experiment-ruby-server/#{VERSION}"
}
request = Net::HTTP::Get.new("#{@server_url}/sdk/v1/flags", headers)
response = @http.request(request)
http = PersistentHttpClient.get(@server_url, { read_timeout: FLAG_CONFIG_TIMEOUT }, @api_key)
response = http.request(request)
raise "flagConfigs - received error response: #{response.code}: #{response.body}" unless response.is_a?(Net::HTTPOK)

@logger.debug("[Experiment] Fetch flag configs: #{response.body}")
Expand All @@ -39,7 +39,8 @@ def fetch_v2
'X-Amp-Exp-Library' => "experiment-ruby-server/#{VERSION}"
}
request = Net::HTTP::Get.new("#{@server_url}/sdk/v2/flags?v=0", headers)
response = @http.request(request)
http = PersistentHttpClient.get(@server_url, { read_timeout: FLAG_CONFIG_TIMEOUT }, @api_key)
response = http.request(request)
raise "flagConfigs - received error response: #{response.code}: #{response.body}" unless response.is_a?(Net::HTTPOK)

@logger.debug("[Experiment] Fetch flag configs: #{response.body}")
Expand All @@ -58,7 +59,8 @@ def fetch
'X-Amp-Exp-Library' => "experiment-ruby-server/#{VERSION}"
}
request = Net::HTTP::Get.new("#{@server_url}/sdk/rules?eval_mode=local", headers)
response = @http.request(request)
http = PersistentHttpClient.get(@server_url, { read_timeout: FLAG_CONFIG_TIMEOUT }, @api_key)
response = http.request(request)
raise "flagConfigs - received error response: #{response.code}: #{response.body}" unless response.is_a?(Net::HTTPOK)

flag_configs = parse(response.body)
Expand Down

0 comments on commit 1146fa3

Please sign in to comment.