Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
c46e6eff
Commit
c46e6eff
authored
Mar 09, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse config/resque.yml in one place only
parent
500337c4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
39 deletions
+46
-39
config/application.rb
config/application.rb
+2
-16
config/initializers/session_store.rb
config/initializers/session_store.rb
+4
-1
config/initializers/sidekiq.rb
config/initializers/sidekiq.rb
+5
-12
config/mail_room.yml
config/mail_room.yml
+2
-7
lib/gitlab/redis_config.rb
lib/gitlab/redis_config.rb
+30
-0
lib/tasks/cache.rake
lib/tasks/cache.rake
+3
-3
No files found.
config/application.rb
View file @
c46e6eff
...
@@ -4,6 +4,7 @@ require 'rails/all'
...
@@ -4,6 +4,7 @@ require 'rails/all'
require
'devise'
require
'devise'
I18n
.
config
.
enforce_available_locales
=
false
I18n
.
config
.
enforce_available_locales
=
false
Bundler
.
require
(
:default
,
Rails
.
env
)
Bundler
.
require
(
:default
,
Rails
.
env
)
require_relative
'../lib/gitlab/redis_config'
module
Gitlab
module
Gitlab
REDIS_CACHE_NAMESPACE
=
'cache:gitlab'
REDIS_CACHE_NAMESPACE
=
'cache:gitlab'
...
@@ -67,22 +68,7 @@ module Gitlab
...
@@ -67,22 +68,7 @@ module Gitlab
end
end
end
end
# Use Redis caching across all environments
redis_config_hash
=
Gitlab
::
RedisConfig
.
redis_store_options
redis_config_file
=
Rails
.
root
.
join
(
'config'
,
'resque.yml'
)
redis_url_string
=
if
File
.
exists?
(
redis_config_file
)
YAML
.
load_file
(
redis_config_file
)[
Rails
.
env
]
else
"redis://localhost:6379"
end
# Redis::Store does not handle Unix sockets well, so let's do it for them
redis_config_hash
=
Redis
::
Store
::
Factory
.
extract_host_options_from_uri
(
redis_url_string
)
redis_uri
=
URI
.
parse
(
redis_url_string
)
if
redis_uri
.
scheme
==
'unix'
redis_config_hash
[
:path
]
=
redis_uri
.
path
end
redis_config_hash
[
:namespace
]
=
REDIS_CACHE_NAMESPACE
redis_config_hash
[
:namespace
]
=
REDIS_CACHE_NAMESPACE
redis_config_hash
[
:expires_in
]
=
2
.
weeks
# Cache should not grow forever
redis_config_hash
[
:expires_in
]
=
2
.
weeks
# Cache should not grow forever
config
.
cache_store
=
:redis_store
,
redis_config_hash
config
.
cache_store
=
:redis_store
,
redis_config_hash
...
...
config/initializers/session_store.rb
View file @
c46e6eff
...
@@ -13,9 +13,12 @@ end
...
@@ -13,9 +13,12 @@ end
if
Rails
.
env
.
test?
if
Rails
.
env
.
test?
Gitlab
::
Application
.
config
.
session_store
:cookie_store
,
key:
"_gitlab_session"
Gitlab
::
Application
.
config
.
session_store
:cookie_store
,
key:
"_gitlab_session"
else
else
redis_config
=
Gitlab
::
RedisConfig
.
redis_store_options
redis_config
[
:namespace
]
=
'session:gitlab'
Gitlab
::
Application
.
config
.
session_store
(
Gitlab
::
Application
.
config
.
session_store
(
:redis_store
,
# Using the cookie_store would enable session replay attacks.
:redis_store
,
# Using the cookie_store would enable session replay attacks.
servers:
Rails
.
application
.
config
.
cache_store
[
1
].
merge
(
namespace:
'session:gitlab'
),
# re-use the Redis config from the Rails cache store
servers:
redis_config
,
key:
'_gitlab_session'
,
key:
'_gitlab_session'
,
secure:
Gitlab
.
config
.
gitlab
.
https
,
secure:
Gitlab
.
config
.
gitlab
.
https
,
httponly:
true
,
httponly:
true
,
...
...
config/initializers/sidekiq.rb
View file @
c46e6eff
# Custom Redis configuration
SIDEKIQ_REDIS_NAMESPACE
=
'resque:gitlab'
config_file
=
Rails
.
root
.
join
(
'config'
,
'resque.yml'
)
resque_url
=
if
File
.
exists?
(
config_file
)
YAML
.
load_file
(
config_file
)[
Rails
.
env
]
else
"redis://localhost:6379"
end
Sidekiq
.
configure_server
do
|
config
|
Sidekiq
.
configure_server
do
|
config
|
config
.
redis
=
{
config
.
redis
=
{
url:
resque_
url
,
url:
Gitlab
::
RedisConfig
.
url
,
namespace:
'resque:gitlab'
namespace:
SIDEKIQ_REDIS_NAMESPACE
}
}
config
.
server_middleware
do
|
chain
|
config
.
server_middleware
do
|
chain
|
...
@@ -36,7 +29,7 @@ end
...
@@ -36,7 +29,7 @@ end
Sidekiq
.
configure_client
do
|
config
|
Sidekiq
.
configure_client
do
|
config
|
config
.
redis
=
{
config
.
redis
=
{
url:
resque_
url
,
url:
Gitlab
::
RedisConfig
.
url
,
namespace:
'resque:gitlab'
namespace:
SIDEKIQ_REDIS_NAMESPACE
}
}
end
end
config/mail_room.yml
View file @
c46e6eff
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
<%
<%
require "yaml"
require "yaml"
require "json"
require "json"
require_relative "lib/gitlab/redis_config"
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
...
@@ -17,13 +18,7 @@ if File.exists?(config_file)
...
@@ -17,13 +18,7 @@ if File.exists?(config_file)
config['mailbox'] = "inbox" if config['mailbox'].nil?
config['mailbox'] = "inbox" if config['mailbox'].nil?
if config['enabled'] && config['address'] && config['address'].include?('%{key}')
if config['enabled'] && config['address'] && config['address'].include?('%{key}')
redis_config_file = "config/resque.yml"
redis_url = Gitlab::RedisConfig.new(rails_env).url
redis_url =
if File.exists?(redis_config_file)
YAML.load_file(redis_config_file)[rails_env]
else
"redis://localhost:6379"
end
%>
%>
-
-
:host: <%= config['host'].to_json %>
:host: <%= config['host'].to_json %>
...
...
lib/gitlab/redis_config.rb
0 → 100644
View file @
c46e6eff
module
Gitlab
class
RedisConfig
attr_reader
:url
def
self
.
url
new
.
url
end
def
self
.
redis_store_options
url
=
new
.
url
redis_config_hash
=
Redis
::
Store
::
Factory
.
extract_host_options_from_uri
(
url
)
# Redis::Store does not handle Unix sockets well, so let's do it for them
redis_uri
=
URI
.
parse
(
url
)
if
redis_uri
.
scheme
==
'unix'
redis_config_hash
[
:path
]
=
redis_uri
.
path
end
redis_config_hash
end
def
initialize
(
rails_env
=
nil
)
rails_env
||=
Rails
.
env
config_file
=
File
.
expand_path
(
'../../../config/resque.yml'
,
__FILE__
)
@url
=
"redis://localhost:6379"
if
File
.
exists?
(
config_file
)
@url
=
YAML
.
load_file
(
config_file
)[
rails_env
]
end
end
end
end
\ No newline at end of file
lib/tasks/cache.rake
View file @
c46e6eff
...
@@ -4,16 +4,16 @@ namespace :cache do
...
@@ -4,16 +4,16 @@ namespace :cache do
desc
"GitLab | Clear redis cache"
desc
"GitLab | Clear redis cache"
task
:clear
=>
:environment
do
task
:clear
=>
:environment
do
redis
_store
=
Rails
.
cache
.
instance_variable_get
(
:@data
)
redis
=
Redis
.
new
(
url:
Gitlab
::
RedisConfig
.
url
)
cursor
=
REDIS_SCAN_START_STOP
cursor
=
REDIS_SCAN_START_STOP
loop
do
loop
do
cursor
,
keys
=
redis
_store
.
scan
(
cursor
,
keys
=
redis
.
scan
(
cursor
,
cursor
,
match:
"
#{
Gitlab
::
REDIS_CACHE_NAMESPACE
}
*"
,
match:
"
#{
Gitlab
::
REDIS_CACHE_NAMESPACE
}
*"
,
count:
CLEAR_BATCH_SIZE
count:
CLEAR_BATCH_SIZE
)
)
redis
_store
.
del
(
*
keys
)
if
keys
.
any?
redis
.
del
(
*
keys
)
if
keys
.
any?
break
if
cursor
==
REDIS_SCAN_START_STOP
break
if
cursor
==
REDIS_SCAN_START_STOP
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment