Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

fix: rate limiting categories #381

Merged
merged 13 commits into from
May 5, 2020
Merged

fix: rate limiting categories #381

merged 13 commits into from
May 5, 2020

Conversation

marandaneto
Copy link
Contributor

@marandaneto marandaneto commented Apr 30, 2020

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

rate limiting categories

💡 Motivation and Context

We were using envelope item types and it should be its own category.

💚 How did you test it?

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing

🔮 Next steps

@marandaneto marandaneto changed the title fix/rate limiting categories fix: rate limiting categories Apr 30, 2020
@codecov-io
Copy link

codecov-io commented Apr 30, 2020

Codecov Report

Merging #381 into master will increase coverage by 0.45%.
The diff coverage is 83.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #381      +/-   ##
============================================
+ Coverage     59.23%   59.68%   +0.45%     
- Complexity      772      785      +13     
============================================
  Files            88       88              
  Lines          3562     3612      +50     
  Branches        346      350       +4     
============================================
+ Hits           2110     2156      +46     
- Misses         1299     1303       +4     
  Partials        153      153              
Impacted Files Coverage Δ Complexity Δ
...c/main/java/io/sentry/core/SentryEnvelopeItem.java 80.48% <0.00%> (-0.91%) 10.00 <0.00> (ø)
.../java/io/sentry/core/SentryEnvelopeItemHeader.java 81.81% <ø> (ø) 6.00 <0.00> (ø)
...e/src/main/java/io/sentry/core/SessionAdapter.java 0.00% <0.00%> (-1.95%) 0.00 <0.00> (-2.00)
...c/main/java/io/sentry/core/cache/SessionCache.java 55.13% <0.00%> (ø) 23.00 <0.00> (ø)
...o/sentry/core/SentryEnvelopeItemHeaderAdapter.java 42.85% <50.00%> (-2.15%) 6.00 <0.00> (ø)
...n/java/io/sentry/core/transport/HttpTransport.java 72.39% <88.88%> (+5.93%) 29.00 <12.00> (+9.00)
...e/src/main/java/io/sentry/core/EnvelopeSender.java 67.46% <100.00%> (ø) 15.00 <0.00> (ø)
...e/src/main/java/io/sentry/core/SentryItemType.java 100.00% <100.00%> (ø) 3.00 <3.00> (?)
...java/io/sentry/core/transport/AsyncConnection.java 70.77% <100.00%> (ø) 17.00 <0.00> (ø)
...src/main/java/io/sentry/core/util/StringUtils.java 100.00% <100.00%> (ø) 7.00 <3.00> (+3.00)
... and 3 more

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 4665894...eb5c7d7. Read the comment docs.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Code looks good, a few nitpicks, but the implementation in Cocoa is again different. We either have it wrong here or in Cocoa. We should clarify with @jan-auer before merging.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Really awesome that we have an enum for categories now. I added one h for a test because it could detect a bug.


transport.send(event)
Thread.sleep(2000)
assertFalse(transport.isRetryAfter("wtf"))
Copy link
Member

Choose a reason for hiding this comment

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

m: Maybe it makes sense to assert that the other categories have a retry after active.
Furthermore, we are going away from Retry-After to Rate-Limits, maybe it makes sense to rename this method at some point, it's a little bit confusing for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renaming would be a breaking change as Android is released like this since 2.0 GA.
but still it's a retry after approach. why would it not make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Because it's our custom rate limit approach and I think we just used the retry after header to implement rate-limiting in the first place. But it's not a big deal.

val event = SentryEvent()

transport.send(event)
Thread.sleep(2000)
Copy link
Member

Choose a reason for hiding this comment

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

l: As already pointed out testing with Thread.sleep is not the best idea. Imagine we want to test a maximum timeout of one day. How would we do that? Furthermore, this slows down the test suite a lot if we do it in multiple tests. We don't have to improve this in this PR, but maybe we do it at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

@Test
fun `When default category is present, apply for error category`() {
Copy link
Member

Choose a reason for hiding this comment

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

I think the upper test is already testing if default applies to error. I think we could remove this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indirectly, yes, but I prefer an explicitly test for it.
a change can cause this test to be broken but not the above one. this guarantees that.


whenever(fixture.connection.inputStream).thenThrow(IOException())
whenever(fixture.connection.getHeaderField(eq("X-Sentry-Rate-Limits")))
.thenReturn("60:error:key, 1:error:organization")
Copy link
Member

Choose a reason for hiding this comment

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

h: I think it would be nice to also test if a new timestamp is applied if the category has a longer rate-limiting. Something like this "2:error:organization 3:error:key, 1:error:organization" and then test that the rate limit is actually 3 seconds. Here a DateProvider with whom we could move the date 3 seconds would already be handy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, but this test is being done indirectly by all of the other tests.
I don't mind adding an extra one, but we don't have the DateProvider right now, can do next.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

LGTM

@marandaneto marandaneto merged commit a4f04a7 into getsentry:master May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants