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

Replicate counter identity rules #51

Merged
merged 5 commits into from
Oct 15, 2019
Merged

Conversation

mdimjasevic
Copy link
Contributor

@mdimjasevic mdimjasevic commented Oct 11, 2019

This patch closes #13. It introduces a time unit to CounterKey to differentiate rules that are the same in everything but the time unit. If the time unit stays the same, but the rate limit changes, fencer does the same as lyft/ratelimit.

@mdimjasevic mdimjasevic self-assigned this Oct 11, 2019
… no test failure due to external side effects. 2) Remove automatic test case detection due to test dependencies.
Copy link

@effectfully effectfully left a comment

Choose a reason for hiding this comment

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

LGTM.

@mdimjasevic mdimjasevic merged commit 302967d into master Oct 15, 2019
@mdimjasevic mdimjasevic deleted the mdimjasevic/13-counter-rules branch October 15, 2019 06:55
counterKey2 :: CounterKey
counterKey2 = counterKey1 { counterKeyUnit = Hour }

fromMaybe' :: Maybe a -> a
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this different from fromJust?

Choose a reason for hiding this comment

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

It prints the stack trace when something goes wrong, so that it's at least clear where the error happened. fromJust outputs

*** Exception: Maybe.fromJust: Nothing

and no indication whatsoever where things went wrong.

@@ -71,6 +81,78 @@ test_loadRulesRecursively =
(sortOn domainDefinitionId [domain1, domain2])
(sortOn domainDefinitionId definitions)

-- | Test that a rule limit unit change adds a new counter and leaves
-- the old one intact.
Copy link
Contributor

@neongreen neongreen Oct 21, 2019

Choose a reason for hiding this comment

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

I have several suggestions regarding this test.

First of all, it does not test the actual logic used by the server. It does the lookup on its own instead of using getLimit. To make it more faithful, I would propose:

  • moving shouldRateLimitDescriptor to Fencer.AppState and renaming it
  • perhaps also renaming Fencer.AppState to Fencer.Logic or something
  • removing the export of recordHits and not using recordHits in the test

Then the test would also get moved to Fencer.Logic.Test since it's not related to the Fencer.Rules module.

Secondly, here's what this test does:

  load definitions1
  hit counterKey1

  load definitions2
  assert (counterKey1 hasn't changed after 'load definitions2')
  assert (counterKey2 doesn't exist after 'load definitions2')

This does not match the description of the test ("Test that a rule limit unit change adds a new counter [...]"). Also, there are bad implementations it does not catch – for instance, what if counters are removed during recordHits and not during loadRules?

Here's a scenario I would propose instead:

  // change the limit to e.g. 4 instead of 400000

  load definitions1
  status <- hit "generic_key/dream11_order_create"
  assert (counterRemainingLimit status == 3)

  load definitions2
  status <- hit "generic_key/dream11_order_create"
  assert (counterRemainingLimit status == 3)  // unaffected by the previous 'hit'

  load definitions1
  status <- hit "generic_key/dream11_order_create"
  assert (counterRemainingLimit status == 2)  // the old counter has persisted!

tests = testGroup "All tests"
[ types
, rules
-- 'after' is needed to avoid running the 'rules' and 'server' tests
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the reason why you got rid of tasty-discover? If yes, perhaps let's instead disable the parallelism by running tests with +RTS -N1 -RTS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I couldn't set the order of test execution when tasty-discover was used.

If I am not missing anything, +RTS -N1 -RTS would mean the program hangs because it would not be able to fork a thread and start a gRPC server.

Choose a reason for hiding this comment

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

@neongreen

If yes, perhaps let's instead disable the parallelism by running tests with +RTS -N1 -RTS.

I don't think it's a good idea as it solves a pretty much already solved problem, but also makes tests slower.

@mdimjasevic

If I am not missing anything, +RTS -N1 -RTS would mean the program hangs because it would not be able to fork a thread and start a gRPC server.

Threads are forkable with -threaded even with a single core.

@neongreen
Copy link
Contributor

neongreen commented Oct 21, 2019 via email

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.

Replicate counter identity rules
3 participants