-
Notifications
You must be signed in to change notification settings - Fork 39
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: client identification headers #224
Conversation
@@ -54,6 +54,9 @@ def http_headers | |||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | |||
'UNLEASH-INSTANCEID' => self.instance_id, | |||
'UNLEASH-APPNAME' => self.app_name, | |||
'X-UNLEASH-APPNAME' => self.app_name, | |||
'X-UNLEASH-CONNECTION-ID' => @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.
we want this one to be private internal detail of each SDK
@@ -54,6 +54,9 @@ def http_headers | |||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | |||
'UNLEASH-INSTANCEID' => self.instance_id, | |||
'UNLEASH-APPNAME' => self.app_name, | |||
'X-UNLEASH-APPNAME' => self.app_name, | |||
'X-UNLEASH-CONNECTION-ID' => @connection_id, | |||
'X-UNLEASH-SDK' => "unleash-ruby@#{Unleash::VERSION}", |
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.
common naming convention across SDKs
@@ -54,6 +54,9 @@ def http_headers | |||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | |||
'UNLEASH-INSTANCEID' => self.instance_id, | |||
'UNLEASH-APPNAME' => self.app_name, | |||
'X-UNLEASH-APPNAME' => self.app_name, |
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 will replace UNLEASH-APPNAME
over time
RSpec.describe Unleash::Client do | ||
after do | ||
WebMock.reset! | ||
File.delete(Unleash.configuration.backup_file) if File.exist?(Unleash.configuration.backup_file) | ||
end | ||
|
||
it "Uses custom http headers when initializing client" do | ||
fixed_uuid = "123e4567-e89b-12d3-a456-426614174000" | ||
allow(SecureRandom).to receive(:uuid).and_return(fixed_uuid) |
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.
since we don't expose connection id we need to mock the generation
Pull Request Test Coverage Report for Build 12867886511Details
💛 - Coveralls |
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.
Yep, seems reasonable to me!
lib/unleash/configuration.rb
Outdated
@@ -87,6 +90,7 @@ def set_defaults | |||
self.environment = 'default' | |||
self.url = nil | |||
self.instance_id = SecureRandom.uuid | |||
@connection_id = SecureRandom.uuid |
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 the dumbest comment I've ever left on a PR ever but the change in syntax here is a bit jarring. Any chance we can move this line either to the top of the bottom of this function?
Honestly I won't even be offended if you just ignore me
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 actually makes perfect sense to me. Had the same thought :) Moving it to the bottom
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.
Thank you! I appreciate you haha
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.
Mostly bike shedding, but since you ask:
- Any reasons why you use uppercase for the headers here in the Ruby SDK but lowercase in the node SDK? (IIRC the mocks ignore the case in the headers, but that doesn't mean that we should have them different across different SDKs, if the point is to standardize)
- Any links to any more formal docs/specs? I think a link to the PR in the node SDK is ok too, but would be even better if there was a link to something a tiny bit more formal.
- In an ideal world the commit message would include:
- the migration path between the headers (which header is going to be replacing which),
- the rationale ("standardization across SDKs" should suffice, but "client identification headers" is a bit on the opaque side for my taste).
- Ideally also add a link/hook to point 2. (either which commit in the node SDK is used as a base, or a link to the docs/spec).
But the code itself is quite sane and i enjoy nit-picking. So if you feel like merging as is, I don't frown for a moment either.
@rarruda Thanks so much for taking the time to review this PR.
|
About the changes
This PR adds standardised client identification headers to the feature and metrics calls that the client makes to Unleash. The headers are:
x-unleash-appname
: the name of the application that is using the client.UNLEASH-APPNAME
will be deleted in another PR (expand/contract pattern)x-unleash-connection-id
: an internal unique identifier for the current instance of the client generated by the built-in crypto libx-unleash-sdk
: sdk information in the formatunleash-ruby@<version>
following referenceunleash-node@<version>
naming patternAll the headers are intended for the Unleash team so clients should not be affected.
The main use cases we have are:
Reference implementation: Unleash/unleash-client-node#690
Important files
Discussion points