-
Notifications
You must be signed in to change notification settings - Fork 40
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: unleash-interval header #236
Conversation
Pull Request Test Coverage Report for Build 13585837720Details
💛 - Coveralls |
@@ -116,6 +116,7 @@ def info | |||
{ | |||
'appName': Unleash.configuration.app_name, | |||
'instanceId': Unleash.configuration.instance_id, | |||
'connectionId': Unleash.configuration.connection_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added to registration payload
@@ -23,6 +23,7 @@ class Configuration | |||
:bootstrap_config, | |||
:strategies, | |||
:use_delta_api | |||
attr_reader :connection_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exposing as read only for metrics payload and registration payload
@@ -102,7 +103,7 @@ def set_defaults | |||
self.project_name = nil | |||
self.disable_client = false | |||
self.disable_metrics = false | |||
self.refresh_interval = 10 | |||
self.refresh_interval = 15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixing default
@@ -23,6 +23,7 @@ def generate_report | |||
'specVersion': Unleash::CLIENT_SPECIFICATION_VERSION, | |||
'appName': Unleash.configuration.app_name, | |||
'instanceId': Unleash.configuration.instance_id, | |||
'connectionId': Unleash.configuration.connection_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
metrics payload includes connectionId
@@ -37,7 +38,9 @@ def post | |||
return | |||
end | |||
|
|||
response = Unleash::Util::Http.post(Unleash.configuration.client_metrics_uri, report.to_json) | |||
headers = (Unleash.configuration.http_headers || {}).dup | |||
headers.merge!({ 'UNLEASH-INTERVAL' => Unleash.configuration.metrics_interval.to_s }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was the best "seam" that I found for adding a new header without branching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to change number to string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also considering using header_overrides but I learned that they erase existing headers instead of merging
@@ -37,7 +37,9 @@ def fetch | |||
Unleash.logger.debug "fetch()" | |||
return if Unleash.configuration.disable_client | |||
|
|||
response = Unleash::Util::Http.get(Unleash.configuration.fetch_toggles_uri, etag) | |||
headers = (Unleash.configuration.http_headers || {}).dup | |||
headers.merge!({ 'UNLEASH-INTERVAL' => Unleash.configuration.refresh_interval.to_s }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is another "seam"
@@ -12,10 +12,10 @@ def self.get(uri, etag = nil, headers_override = nil) | |||
http.request(request) | |||
end | |||
|
|||
def self.post(uri, body) | |||
def self.post(uri, body, headers_override = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
making it symmetrical with get
http = http_connection(uri) | ||
|
||
request = Net::HTTP::Post.new(uri.request_uri, http_headers) | ||
request = Net::HTTP::Post.new(uri.request_uri, http_headers(nil, headers_override)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no etag for post, only headers_override
@@ -29,7 +29,8 @@ | |||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | |||
'Content-Type' => 'application/json', | |||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | |||
'Unleash-Sdk' => "unleash-client-ruby:#{Unleash::VERSION}" | |||
'Unleash-Sdk' => "unleash-client-ruby:#{Unleash::VERSION}", | |||
'Unleash-Interval' => '60' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test metrics interval reported correctly
@@ -56,7 +57,8 @@ | |||
'Unleash-Connection-Id' => fixed_uuid, | |||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | |||
'Unleash-Sdk' => "unleash-client-ruby:#{Unleash::VERSION}", | |||
'X-Api-Key' => '123' | |||
'X-Api-Key' => '123', | |||
'Unleash-Interval' => '15' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test fetch toggles interval reported correctly
@@ -213,7 +213,8 @@ | |||
yggdrasilVersion: anything, | |||
specVersion: anything, | |||
platformName: anything, | |||
platformVersion: anything | |||
platformVersion: anything, | |||
connectionId: anything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test connectionId included in the registration payload
@@ -158,7 +159,8 @@ | |||
yggdrasilVersion: anything, | |||
specVersion: anything, | |||
platformName: anything, | |||
platformVersion: anything | |||
platformVersion: anything, | |||
connectionId: anything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test connectionId included in the metrics payload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I think I've made your life harder than it needs to be with the headers override code. I think you have some sane seams here and it looks good though!
About the changes
refresh_interval
to be identical to other SDKs (15s for fetch toggles, it was 10s before despite docs claiming it's 15s)unleash-interval
header to fetch toggles call and send metric call (they are different so can't share HTTP header setting)connectionId
to registration payload and send metrics payloadImportant files
Please check toggle_fetcher and metrics_reporter since I added "seams" in those 2 in order to inject different metrics interval headers.
Discussion points