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

Fix regression where URIs as input for the entrypoint no longer worked. #107

Merged
merged 2 commits into from
Jul 8, 2016

Conversation

pilhuhn
Copy link
Member

@pilhuhn pilhuhn commented Jul 8, 2016

Some normalization logic in 2.2.0 introduced a regression where URI:HTTP object were no longer accepted as input for entrypoints.
This pr checks for uri objects and converts them to string if needed.

@simon3z @yaacov

@coveralls
Copy link

coveralls commented Jul 8, 2016

Coverage Status

Coverage increased (+0.1%) to 94.998% when pulling 09955b3 on pilhuhn:re-introduce-endpoint-param-as-uri into b52b1f8 on hawkular:master.

@@ -139,10 +139,11 @@ def normalize_entrypoint_url(entrypoint, suffix_path)
strip_path.nil? || suffix_path = strip_path
strip_path = suffix_path.gsub(%r{^/}, '')
strip_path.nil? || suffix_path = strip_path
strip_entrypoint = entrypoint.gsub(%r{/$}, '')
the_entry_point = (entrypoint.is_a? URI::HTTP) ? entrypoint.to_s : entrypoint

Choose a reason for hiding this comment

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

Why not the simpler entrypoint = entrypoint.to_s?

Copy link
Member Author

Choose a reason for hiding this comment

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

On 8 Jul 2016, at 14:02, Oleg Barenboim wrote:

Why not the simpler entrypoint = entrypoint.to_s?

Isn't a to_s on something that is already a string a bit odd? But sure I
can change that.

Choose a reason for hiding this comment

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

Idiomatic Ruby /cc @Fryguy

@pilhuhn pilhuhn force-pushed the re-introduce-endpoint-param-as-uri branch from 09955b3 to 0cf88f2 Compare July 8, 2016 12:56
@coveralls
Copy link

coveralls commented Jul 8, 2016

Coverage Status

Coverage increased (+0.2%) to 95.009% when pulling 0cf88f2 on pilhuhn:re-introduce-endpoint-param-as-uri into b52b1f8 on hawkular:master.

strip_entrypoint = entrypoint.gsub(%r{/$}, '')
strip_path.nil? && strip_entrypoint = entrypoint
strip_entrypoint = entrypoint.to_s.gsub(%r{/$}, '')
strip_path.nil? && strip_entrypoint = entrypoint.to_s
Copy link
Contributor

Choose a reason for hiding this comment

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

what about empty strings? (I mean '')

Copy link
Member Author

Choose a reason for hiding this comment

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

The internal clients use that method to get to the correct base-endpoint, so I don't think this is an issue that could arise. I can add a guard on suffix_path being empty to warn the developer of a new sub-client - the nil case is easily caught by nil.gsubbailing out :-)

@abonas
Copy link
Contributor

abonas commented Jul 8, 2016

is this applying to all subclients or only main client and metrics?

@pilhuhn pilhuhn force-pushed the re-introduce-endpoint-param-as-uri branch from 0cf88f2 to 6336cf3 Compare July 8, 2016 14:19
@pilhuhn pilhuhn force-pushed the re-introduce-endpoint-param-as-uri branch from 6336cf3 to cd40a17 Compare July 8, 2016 14:26
@pilhuhn
Copy link
Member Author

pilhuhn commented Jul 8, 2016

@abonas when you do Hawkular::Client.new then it applies to all sub-clients. As CM is calling it differently, I did the explicit check for their use case.

@coveralls
Copy link

coveralls commented Jul 8, 2016

Coverage Status

Coverage increased (+0.2%) to 95.014% when pulling cd40a17 on pilhuhn:re-introduce-endpoint-param-as-uri into b52b1f8 on hawkular:master.

strip_path = suffix_path.gsub(%r{/$}, '')
strip_path.nil? || suffix_path = strip_path
strip_path = suffix_path.gsub(%r{^/}, '')
strip_path.nil? || suffix_path = strip_path
strip_entrypoint = entrypoint.gsub(%r{/$}, '')
strip_path.nil? && strip_entrypoint = entrypoint
strip_entrypoint = entrypoint.to_s.gsub(%r{/$}, '')

Choose a reason for hiding this comment

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

I think doing entrypoint = entrypoint.to_s above here should eliminate need to do the to_s conversions below.

@yaacov
Copy link

yaacov commented Jul 8, 2016

@pilhuhn is is better to do client = Hawkular::Client.new ... and then do client.metrics... then the Hawkular::Metrics::Client.new ... we use now ?
I can add it to my todo list :-)

@pilhuhn
Copy link
Member Author

pilhuhn commented Jul 8, 2016

@yaacov I don't think it matters too much in your use-case. Once you need more than one sub-client, it is better to use Hawkular::Client.new and getting the sub-clients from it.

@yaacov did you have a chance to test your code with this change?

@coveralls
Copy link

coveralls commented Jul 8, 2016

Coverage Status

Coverage increased (+0.2%) to 95.016% when pulling cc8a98d on pilhuhn:re-introduce-endpoint-param-as-uri into b52b1f8 on hawkular:master.

strip_entrypoint = entrypoint.gsub(%r{/$}, '')
strip_path.nil? && strip_entrypoint = entrypoint
strip_path.nil? && strip_entrypoint = entrypoint.to_s
Copy link

Choose a reason for hiding this comment

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

in line 143 entrypoint = entrypoint.to_s is converted to string, do we need the .to_s here ?

I checked in CM and this works fine :-) with and without this .to_s

Copy link
Member Author

Choose a reason for hiding this comment

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

you need the to_s as the entrypoint could be a URI::HTTP (what you had originally) and without it the gsub() in line 144 will error out as you have reported :)

Copy link

Choose a reason for hiding this comment

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

entrypoint could be a URI::HTTP

after line 143 entrypoint is string

Copy link
Member Author

Choose a reason for hiding this comment

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

Now I get what you mean - sorry

Copy link
Member

@josejulio josejulio Jul 8, 2016

Choose a reason for hiding this comment

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

There is a to_s in line 143 and other in line 145. I guess the later isn't needed, right?

Copy link

Choose a reason for hiding this comment

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

np. I checked it without the to_s in line 145 and CM metrics wroks :-)

@pilhuhn pilhuhn force-pushed the re-introduce-endpoint-param-as-uri branch from cc8a98d to 709fe46 Compare July 8, 2016 15:37
@pilhuhn
Copy link
Member Author

pilhuhn commented Jul 8, 2016

Ok, when Travis is happy, I will merge it and then release the 2.2.1 version of the gem and PR it on MiQ side

@coveralls
Copy link

coveralls commented Jul 8, 2016

Coverage Status

Coverage increased (+0.2%) to 95.016% when pulling 709fe46 on pilhuhn:re-introduce-endpoint-param-as-uri into b52b1f8 on hawkular:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants