Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions providers/openfeature-go-feature-flag-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The `OpenFeature::GoFeatureFlag::Provider` needs some options to be created and
| `endpoint` | **(mandatory)** The URL to access to the relay-proxy.<br />*(example: `https://relay.proxy.gofeatureflag.org/`)* |
| `headers` | A `Hash` object containing the headers to send to the relay-proxy.<br/>*(example to send APIKey: `{"Authorization" => "Bearer my-api-key"}` |
| `instrumentation` | [Faraday instrumentation](https://github.com/lostisland/faraday/blob/main/docs/middleware/included/instrumentation.md) hash |
| `timeout` | Request timeout in seconds ([Faraday request options](https://rubydoc.info/github/lostisland/faraday/Faraday/Connection)). |
The only required option to create a `GoFeatureFlagProvider` is the URL _(`endpoint`)_ to your GO Feature Flag relay-proxy instance.

```ruby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ module OpenFeature
module GoFeatureFlag
module Client
class HttpApi < Common
def initialize(endpoint: nil, custom_headers: nil, instrumentation: nil)
def initialize(endpoint: nil, custom_headers: nil, instrumentation: nil, timeout: nil)
@custom_headers = custom_headers
@faraday_connection = Faraday.new(url: endpoint, headers: headers) do |f|
request_options = {timeout: timeout}
@faraday_connection = Faraday.new(url: endpoint, headers: headers, request: request_options) do |f|
f.request :instrumentation, instrumentation if instrumentation
f.adapter :net_http_persistent do |http|
http.idle_timeout = 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def validate_parameters(flag_key, evaluation_context)
def build_client(options)
case options.type
when "http"
Client::HttpApi.new(endpoint: options.endpoint, custom_headers: options.custom_headers, instrumentation: options.instrumentation)
Client::HttpApi.new(endpoint: options.endpoint, custom_headers: options.custom_headers, instrumentation: options.instrumentation, timeout: options.timeout)
when "unix"
Client::UnixApi.new(endpoint: options.endpoint, custom_headers: options.custom_headers)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ module OpenFeature
module GoFeatureFlag
# This class is the configuration class for the GoFeatureFlagProvider
class Options
attr_accessor :endpoint, :custom_headers, :exporter_metadata, :instrumentation, :type
attr_accessor :endpoint, :custom_headers, :exporter_metadata, :instrumentation, :type, :timeout

def initialize(endpoint: nil, headers: {}, exporter_metadata: {}, instrumentation: nil, type: "http")
def initialize(endpoint: nil, headers: {}, exporter_metadata: {}, instrumentation: nil, type: "http", timeout: nil)
validate_endpoint(endpoint, type)
validate_instrumentation(instrumentation: instrumentation)
@type = type
@endpoint = endpoint
@custom_headers = headers
@exporter_metadata = exporter_metadata
@instrumentation = instrumentation
@timeout = timeout
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
it "should raise if instrumentation is not hash" do
expect { OpenFeature::GoFeatureFlag::Options.new(instrumentation: "custom_name") }.to raise_error(ArgumentError, "Invalid type for instrumentation: String")
end

it "should allow custom timeout" do
options = OpenFeature::GoFeatureFlag::Options.new(endpoint: "http://localhost:1031", timeout: 5)
expect(options.timeout).to eq(5)
end
end
end