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

Extend RabbitMQ scaler to support count unacked messages #700

Merged
merged 2 commits into from
Apr 8, 2020

Conversation

holyketzer
Copy link
Contributor

Add settings which allows to count total messages count in queue (ready + unacked) to do not scale worker down if some long time processing is going.

By default countUnacked = false and it keeps old behaviour via AMQP protocol, if countUnacked = true it requires also apiHost to be set and uses HTTP management API to get queue info.

AMQP protocol doesn't allow to fetch unacked messages count, that is we need management API here. Technically we an completely switch to management API but as I understand not all servers have it enabled, that is why backward compatibility is saved and countUnacked is optional.

Checklist

It was tested in our Kubernetes cluster

Fixes #356

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>
@tomkerkhove
Copy link
Member

Docs are saying this:

By default countUnacked is false in this case scaler uses AMQP protocol, requires host and only counts messages in the queue and ignores unacked messages.
If countUnacked is true then host is not required but apiHost is required in this case scaler uses HTTP management API and counts messages in the queue + unacked messages count.

Which requires following URLs:

  • Host: amqp://guest:password@localhost:5672/
  • Api Host: https://guest:password@localhost:443/vhostname

One could argue that we should always require guest:password@localhost:5672 to be configured and change protocol based on the flags that are turned on?

Certainly since vhost is being added via kedacore/keda-docs#70 (pending review) which is also the same.

@holyketzer
Copy link
Contributor Author

holyketzer commented Mar 25, 2020

One could argue that we should always require guest:password@localhost:5672 to be configured and change protocol based on the flags that are turned on?

Sure I tried it first (parse AMQP connection string, replace protocol, port, extract vhost) and suddenly discovered that our credentials for AMQP protocol has different permissions level and can't be used to access management API. That is why I introduced new connection string.

We can use all different fields for like host, port, user, password and vhost and share them, or maybe yes, we can use one host setting in different contexts as AMQP or HTTP protocol, but i'm not sure what is more clear, maybe one host is better than host and apiHost

Certainly since vhost is being added via kedacore/keda-docs#70 (pending review) which is also the same.

Hm, we have been using vhost in AMQP connection string since we started to use Keda and it works ). You mean it wasn't documented?

if err != nil {
rabbitmqLog.Error(err, "Error closing rabbitmq connection")
return err
if s.metadata.countUnacked == false {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about s.connection != nil so it'd make sure to dispose the connection if it's at all created.

Copy link
Contributor

@ahmelsayed ahmelsayed left a comment

Choose a reason for hiding this comment

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

Thanks @holyketzer, and appreciate the thorough test. I have one minor comment.

@ahmelsayed
Copy link
Contributor

I'm not very familiar with rabbitmq, so not sure I have anything to add to the discussion. I think having a single host as opposed to apiHost and host but from the description it doesn't seem that they are always compatible? could they be different? can the same user account work with both given the right permissions?

@tomkerkhove
Copy link
Member

One could argue that we should always require guest:password@localhost:5672 to be configured and change protocol based on the flags that are turned on?

Sure I tried it first (parse AMQP connection string, replace protocol, port, extract vhost) and suddenly discovered that our credentials for AMQP protocol has different permissions level and can't be used to access management API. That is why I introduced new connection string.

We can use all different fields for like host, port, user, password and vhost and share them, or maybe yes, we can use one host setting in different contexts as AMQP or HTTP protocol, but i'm not sure what is more clear, maybe one host is better than host and apiHost

I think using host would be better but that would be a breaking change, so let's stick with seperation between the 2 and we'll open an issue to change this for 2.0 - What do you think @zroubalik @ahmelsayed ?

Certainly since vhost is being added via kedacore/keda-docs#70 (pending review) which is also the same.

Hm, we have been using vhost in AMQP connection string since we started to use Keda and it works ). You mean it wasn't documented?

Yes, I've merged it now

@zroubalik
Copy link
Member

zroubalik commented Mar 26, 2020

I'm not very familiar with rabbitmq, so not sure I have anything to add to the discussion. I think having a single host as opposed to apiHost and host but from the description it doesn't seem that they are always compatible? could they be different? can the same user account work with both given the right permissions?

+1 good questions

I agree with @tomkerkhove point on opening a new issue targeted for 2.0 for the breaking change (in case it makes sense to implement it that way wrt the questions raised by @ahmelsayed).

@holyketzer
Copy link
Contributor Author

Ok, I got all the points and going to fix all of them.

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>
@holyketzer
Copy link
Contributor Author

Feedback is accepted I pushed fixes + fix for doc PR

Copy link
Member

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

LGTM from a config/semantics approach

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

LGTM

@zroubalik
Copy link
Member

@ahmelsayed should we merge this one? WDYT?

Copy link
Contributor

@ahmelsayed ahmelsayed left a comment

Choose a reason for hiding this comment

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

LGTM too

@ahmelsayed ahmelsayed merged commit ef7e4e9 into kedacore:master Apr 8, 2020
@ahmelsayed
Copy link
Contributor

Thanks @holyketzer for your contributions!

@holyketzer
Copy link
Contributor Author

Cool thank you guys!

zroubalik pushed a commit to zroubalik/keda that referenced this pull request Apr 9, 2020
* Extend RabbitMQ scaler to support count unacked messages

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>

* Fix code review feedback

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>
ahmelsayed pushed a commit that referenced this pull request Apr 10, 2020
* Extend RabbitMQ scaler to support count unacked messages

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>

* Fix code review feedback

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>
AmithGanesh pushed a commit to AmithGanesh/keda that referenced this pull request May 18, 2020
* Extend RabbitMQ scaler to support count unacked messages

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>

* Fix code review feedback

Signed-off-by: Alex Emelyanov <holyketzer@gmail.com>
Signed-off-by: Amith Ganesh <amith.ganesh1284@gmail.com>
SpiritZhou pushed a commit to SpiritZhou/keda that referenced this pull request Jul 18, 2023
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.

RabbitMQ scale down is not reliable
4 participants