Skip to content

Conversation

@findingrish
Copy link
Contributor

@findingrish findingrish commented Jan 7, 2021

Problem: Currently we set Event.http.request.url as null in case when http url is relative. This causes problems in some of the consumers of Event.http.request.url

There are 3 changes in this pr:

Event.http.request.url was originally being set using url attributes, although in the case of relative url it was being set as null. That has been changed with this pr. Now we will pass it as it is and let the consumer decide.

Secondly, most of the consumer of full url, use EnrichedSpanUtil#getFullUrl (which internally fetches url from Event.http.request.url), so this method has been updated with a check for absolute url.

Third, SpanEventViewGenerator has been updated to consume whatever is being set in Event.http.request.url instead of full url

The other option is,

  1. Continue setting Event.http.request.url as null for relative url
  2. Fix consumer on case by case basis, for example make SpanEventViewGenerator fallback on the url path instead.
  3. No changes in EnrichedSpanUtil#getFullUrl required

…l.getFullUrl() checks for absolute url now
url.ifPresent(requestBuilder::setUrl);
}

static boolean isAbsoluteUrl(String urlStr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it's the same method defined in EnrichedSpanUtils above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is, since span-normalizer doesn't depend on enriched-span-constants or vice-versa, I just duplicated the code.

return Optional.empty();
}

private static boolean isAbsoluteUrl(String urlStr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Who is using the private function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method getFullHttpUrl


private static boolean isAbsoluteUrl(String urlStr) {
try {
URL url = new URL(new URL("http://hypertrace.org"), urlStr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this http://hypertrace.org?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any other url will be fine too. In case when input url is relative, this provided url makes up for the scheme, authority etc.

if (event.getHttp() != null
&& event.getHttp().getRequest() != null
&& event.getHttp().getRequest().getUrl() != null
&& isAbsoluteUrl(event.getHttp().getRequest().getUrl())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

when the URL isn't full URL, do you want to rather check if you can construct full URL back from scheme, authority, path and query params? That's what I had in mind.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh.. if you're making sure this URL is always full URL, we don't even need this method I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would need it.
Earlier, event.getHttp().getRequest().getUrl() was null in case of relative url. Now since it is being populated in a best effort basis, so it maybe full url or not.
However the consumer of this method EnrichedSpanUtils#getFullHttpUrl would except a full url to be returned or null.
To ensure that behaviour a check has been added to this method.

However I think we can go with this pr first #104 for now. It is a subset of the changes made in this pr.

@codecov
Copy link

codecov bot commented Jan 8, 2021

Codecov Report

Merging #99 (c2c383c) into main (c16397b) will decrease coverage by 0.06%.
The diff coverage is 58.82%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main      #99      +/-   ##
============================================
- Coverage     68.63%   68.56%   -0.07%     
- Complexity      819      822       +3     
============================================
  Files            84       84              
  Lines          3475     3487      +12     
  Branches        367      370       +3     
============================================
+ Hits           2385     2391       +6     
- Misses          946      950       +4     
- Partials        144      146       +2     
Flag Coverage Δ Complexity Δ
unit 68.56% <58.82%> (-0.07%) 0.00 <7.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...nrichedspan/constants/utils/EnrichedSpanUtils.java 52.94% <44.44%> (-0.49%) 22.00 <3.00> (+1.00) ⬇️
...ormalizer/fieldgenerators/HttpFieldsGenerator.java 93.73% <60.00%> (-0.55%) 105.00 <4.00> (+2.00) ⬇️
...ewgenerator/generators/SpanEventViewGenerator.java 9.32% <100.00%> (+1.56%) 5.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c16397b...c2c383c. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Jan 8, 2021

Unit Test Results

  47 files  ±0    47 suites  ±0   47s ⏱️ +2s
239 tests +3  239 ✔️ +3  0 💤 ±0  0 ❌ ±0 

Results for commit c2c383c. ± Comparison against base commit c16397b.

@skjindal93
Copy link
Contributor

Can we close the PR, if it's not needed? I see it's already been taken care of here https://github.com/hypertrace/hypertrace-ingester/pull/108/files. Correct me, if I am wrong

@findingrish
Copy link
Contributor Author

Can we close the PR, if it's not needed? I see it's already been taken care of here https://github.com/hypertrace/hypertrace-ingester/pull/108/files. Correct me, if I am wrong

Yes, closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants