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

Add redis as an (optional) session store backend #3450

Closed
wants to merge 3 commits into from

Conversation

djmaze
Copy link
Contributor

@djmaze djmaze commented Mar 16, 2021

As discussed on the community forum, it is currently a bit of a struggle to make a Zammad work on a multi-machine cluster. The main problem is the use of a shared directory as a kind of message queue for the sessions. Sharing that directory via a distributed filesystem turns out to be really problematic.

A much more suitable tool for this kind of work is Redis. I thus refactored the sessions module to allow for different store backends and implemented a Redis backend in addition to the file backend.

In my local tests, this seems to work well. I still have to try this out in production though.

I am a bit unsure with the naming (is store the right term to use for the backends?). Also, I did not yet have a look at the tests in order to see if or how the new backend can be tested.

In order to use this, you need to set the env variable REDIS_URL to a running Redis server for the Zammad services.

Let me know what you think of this.

@djmaze
Copy link
Contributor Author

djmaze commented Mar 17, 2021

As Github does not want to finish running the tests, I did it all locally. Both with and without a REDIS_URL. In both cases, the following tests failed on my machine:

rspec ./spec/requests/integration/github_spec.rb:91 # GitHub request handling does save ticket issues
rspec ./spec/requests/integration/gitlab_spec.rb:96 # GitLab request handling does save ticket issues
rspec ./spec/requests/proxy_spec.rb:41 # Manage > Settings > System > Network request handling when proxy settings uses invalid config with unknown proxy
rspec ./spec/requests/proxy_spec.rb:51 # Manage > Settings > System > Network request handling when proxy settings uses invalid config with invalid proxy username
rspec ./spec/requests/proxy_spec.rb:61 # Manage > Settings > System > Network request handling when proxy settings uses invalid config with invalid proxy password

The detailed error messages look like they are not related to my changes but maybe to my development setup. (As I was not able to find any documentation on how to setup a development environment, there might be something missing.)

@djmaze djmaze marked this pull request as ready for review March 17, 2021 14:54
@MrGeneration
Copy link
Member

Hey,

maybe this can help you a bit further:
https://docs.zammad.org/en/latest/contributing/ci.html#local

Documentation on this regard currently lacks a bit. Sorry! :-(

@djmaze
Copy link
Contributor Author

djmaze commented Mar 17, 2021

Well, that seems to be outdated. I took the commands out of .github/ci.sh since that is what the CI is currently doing.

@MrGeneration
Copy link
Member

Well, that seems to be outdated. I took the commands out of .github/ci.sh since that is what the CI is currently doing.

Not exactly, it's quite fresh actually. ;-x
zammad/zammad-documentation#163

@thorsteneckel
Copy link
Contributor

Hi @djmaze - I'm stunned! Fantastic to receive a PR for this. We're currently right before the 4.0 release so I don't find much time for other things. I just wanted to let you know that these were all tests we added / changed over the last week(s). We haven't had the chance to see the impact on PRs. Looks like there's something broken on our side. Please ignore them for now.
I'll get back to you with more detailed feedback, solutions and a review as fast as I can. This might take 1 or 2 weeks though.

@monotek
Copy link
Member

monotek commented Mar 17, 2021

Linking for reference: #1601

@@ -40,6 +40,9 @@ class Application < Rails::Application
# define cache store
config.cache_store = :file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}")
Copy link
Member

Choose a reason for hiding this comment

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

In container context i've used memcached for cache_store.
See: https://github.com/zammad/zammad-docker-compose/blob/master/containers/zammad/docker-entrypoint.sh#L58

Could we use redis here too to have a single solution for all file based caches and sessions stores?

Copy link
Contributor

Choose a reason for hiding this comment

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

Redis is actually our preferred long term solution 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my point of view, yes, that would 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.

Would you mind to extend the pr for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure that belongs here because this is not about the cache store.

Also, you could probably just replace the :file_store with :redis_store in your docker image similar to how it is currently done with memcached. (Which is of course ugly and should be handled differently.)

Also, switching both cache and session store to Redis might bring a new class of problems, so we should probably also think about how to prevent those.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. We should limit the scope of this change to a minimum and instead iterate faster with smaller changes.

@djmaze
Copy link
Contributor Author

djmaze commented Mar 17, 2021

If we wanted to take this all the way to Redis, we could probably also improve responsiveness by using redis' blocking list commands instead of polling for updates. But that would be a larger refactoring I'd leave for later.

@mgruner mgruner self-assigned this Jun 18, 2021
@mgruner
Copy link
Collaborator

mgruner commented Jun 18, 2021

Hi @djmaze. The failing tests were caused by missing credentials, that should be fixed now in develop.
Would you be so kind to update your branch to the current state?

@mgruner
Copy link
Collaborator

mgruner commented Jun 23, 2021

@djmaze FYI, your changes are now in an internal branch and are playing well with the CI. We can take it from here, I believe. More updates soon.

@djmaze
Copy link
Contributor Author

djmaze commented Jun 23, 2021

@mgruner Sorry for not answering quicker. Thanks for taking care! Just tell me if you need help / testing.

@thorsteneckel
Copy link
Contributor

Fantastic work @djmaze - thanks a ton for your contribution and patience 💪 Will be part of Zammad 5

@mgruner
Copy link
Collaborator

mgruner commented Jun 30, 2021

@djmaze thanks again for this excellent contribution. I merged it more or less unchanged, with some changes to our CI to properly cover this.
This will be a very nice new feature for Zammad 5.0. Thanks again!

@thorsteneckel thorsteneckel added this to the 5.0 milestone Jun 30, 2021
@mgruner
Copy link
Collaborator

mgruner commented Jun 30, 2021

Oh and for the record - I agree that using Memcached for the Rails cache is probably the better tool for the purpose. I will make sure this will be configurable and documented in a nice way for Zammad 5.0 too.

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.

None yet

5 participants