Skip to content

Add custom period of blocking time #70

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

yurka44
Copy link

@yurka44 yurka44 commented Jul 2, 2018

This changes allow developers to set custom period of blocking time of a call through either an annotation or YAML.

sane4ek-2 added 19 commits June 27, 2018 14:06
We added the package for more convenient development. It allows an IDE
make auto complete.
We will check this field and will discard requests if it is set up blocked.
We added the key for more convenient handling of RateLimitInfo in
service storages.
We added that ability, because sometimes we want to use another period
of time for blocking a specific call, but we want to save a period of
time when somebody can do requests of URLs without restrictions.
We need this event for making different things when a block happens.
We should dispatch that event, because some developers want to do
additional things when block happens. For example, to register block
event into system log.
We added dispatching the event before sending a response. It needs
when we want to send another more reach message in the response. Also it
allows us to make other types of responses.
This feature allows to block the URL or call for custom period of time
which can be not equal period or might be omit at all.
@mcfedr
Copy link
Collaborator

mcfedr commented Jul 2, 2018

This looks like a great feature, if the conflicts could be resolved I'd like to merge it.

*/
public function setKey($key)
{
$this->key = (string)$key;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure why you want to set the key?

Choose a reason for hiding this comment

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

We need the key there.

    # Service/Storage/StorageInterface.php

    /**
     * Set block for the call
     *
     * @param RateLimitInfo $rateLimitInfo
     * @param integer       $periodBlock
     *
     * @return bool
     */
    public function setBlock(RateLimitInfo $rateLimitInfo, $periodBlock);

If we passed only the key and periodBlock into setBlock method we would have to load cache data before setting block in some storages. It's not a good idea to load data if we have already them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better for this to work like the other functions in RateLimitService and have $key as the first parameter

@sane4ek-2
Copy link

@mcfedr we fixed all the conflicts.

if (!$rateLimitInfo->isBlocked() && $rateLimitInfo->getCalls() > $rateLimitInfo->getLimit()) {
$this->rateLimitService->setBlock(
$rateLimitInfo,
$rateLimit->getBlockPeriod() > 0 ? $rateLimit->getBlockPeriod() : $rateLimit->getPeriod()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think If the block period isn't set, there should be no extended block period, as in how system works at the moment.

*/
public function setKey($key)
{
$this->key = (string)$key;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better for this to work like the other functions in RateLimitService and have $key as the first parameter

$info['limit'] = $limit;
$info['calls'] = 1;
$info['reset'] = time() + $period;
$info['blocked'] = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

blocked is a bool, no need to mix it with ints

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.

3 participants