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

feature(redis) support redis sentinel #11155

Merged
merged 1 commit into from
Jul 19, 2020

Conversation

bitsf
Copy link
Contributor

@bitsf bitsf commented Mar 20, 2020

fix #10365
fix #6828

Add redis sentinel support

change the redis conf, remove port field, add schema field, change host field format to

  1. for schema redis
    hostname:post
  2. for schema redis+sentinel
    hostname1:port,hostname2:port,hostname3:port/monitor_name

the full raw url is
redis://<hostname>:<post>/<dbnum>
redis+sentinel://<hostname1>:<port>,<hostname2>:<port>,<hostname2>:<port>/<monitor_name>/<dbnum>

Signed-off-by: Ziming Zhang zziming@vmware.com
Change-Id: Icbcbb5ebe842c4866657e32d5a253f293e643854

@codecov
Copy link

codecov bot commented Mar 20, 2020

Codecov Report

Merging #11155 into master will decrease coverage by 0.24%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11155      +/-   ##
==========================================
- Coverage   63.64%   63.40%   -0.25%     
==========================================
  Files         878      880       +2     
  Lines       54133    54289     +156     
  Branches     1836     1836              
==========================================
- Hits        34455    34422      -33     
- Misses      16100    16286     +186     
- Partials     3578     3581       +3     
Flag Coverage Δ
#unittests 63.40% <ø> (-0.25%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ithub.com/goharbor/harbor/src/chartserver/cache.go 55.68% <0.00%> (-9.66%) ⬇️
...ithub.com/goharbor/harbor/src/chartserver/utils.go 75.94% <0.00%> (-8.80%) ⬇️
...com/goharbor/harbor/src/jobservice/runner/redis.go 63.63% <0.00%> (-4.05%) ⬇️
...harbor/harbor/src/jobservice/common/utils/utils.go 54.38% <0.00%> (-2.95%) ⬇️
...om/goharbor/harbor/src/jobservice/config/config.go 51.75% <0.00%> (-2.56%) ⬇️
...oharbor/harbor/src/jobservice/runtime/bootstrap.go 59.05% <0.00%> (-2.14%) ⬇️
...or/harbor/src/server/middleware/repoproxy/proxy.go 7.14% <0.00%> (-0.23%) ⬇️
.../goharbor/harbor/src/controller/blob/controller.go 74.82% <0.00%> (ø)
...m/goharbor/harbor/src/common/utils/redis/helper.go
.../goharbor/harbor/src/chartserver/redis_sentinel.go 1.57% <0.00%> (ø)
... and 6 more

@bitsf bitsf force-pushed the support_redis_sentinel branch 3 times, most recently from 1f51deb to 9b94732 Compare March 20, 2020 10:30
@bitsf bitsf force-pushed the support_redis_sentinel branch 12 times, most recently from a2b29c2 to 3890b87 Compare March 21, 2020 07:57
src/core/main.go Outdated Show resolved Hide resolved
@reasonerjt
Copy link
Contributor

This is a valuable PR thanks @bitsf !

But I have some comment in regards to how we set the redis/redis+sentinel settings into core.
Instead of adding magics we may better introduce a more structural way to set these settings.

Copy link
Contributor

@steven-zou steven-zou left a comment

Choose a reason for hiding this comment

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

comments left

make/photon/prepare/utils/configs.py Outdated Show resolved Hide resolved
src/core/api/health.go Outdated Show resolved Hide resolved
src/core/api/health.go Outdated Show resolved Hide resolved
src/core/main.go Outdated Show resolved Hide resolved
src/internal/cache/redisclient.go Outdated Show resolved Hide resolved
src/internal/cache/redisclient.go Outdated Show resolved Hide resolved
Copy link
Contributor

@heww heww left a comment

Choose a reason for hiding this comment

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

Please rename internal/cache to lib/redis because there is no internal in the harbor now and cache it does not match the function of this pkg.

Comment on lines +195 to +311
PoolMaxIdle: 0,
PoolMaxActive: 1,
PoolIdleTimeout: 60 * time.Second,
DialConnectionTimeout: dialConnectionTimeout,
DialReadTimeout: dialReadTimeout,
DialWriteTimeout: dialWriteTimeout,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we unify the Redis param in harbor core?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is focus on support redis sentinel, so I don't want to optimize the param too much for each components, as this might introduce new issues.

@bitsf bitsf force-pushed the support_redis_sentinel branch 4 times, most recently from 07a678b to 57755bc Compare July 16, 2020 07:04
from g import templates_dir, config_dir, data_dir, DEFAULT_UID, DEFAULT_GID
from urllib.parse import urlsplit
Copy link
Member

Choose a reason for hiding this comment

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

standard lib should be placed in the first import group

elif u.scheme == 'redis+sentinel':
return {
'cache_store': 'redis_sentinel',
'cache_redis_mastername': u.path.split('/')[1],
Copy link
Member

Choose a reason for hiding this comment

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

master isn't political right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

redis itself is using words master/slave

# password:
# # sentinel_master_set must be set to support redis+sentinel
# #sentinel_master_set:
Copy link
Member

Choose a reason for hiding this comment

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

master should changed to main or something else

from g import versions_file_path, host_root_dir, DEFAULT_UID, INTERNAL_NO_PROXY_DN
from models import InternalTLS
from urllib.parse import urlencode
Copy link
Member

Choose a reason for hiding this comment

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

urllib shuold placed in system library import group

'password': '',
}
kwargs.update(redis or {})
kwargs['db'] = db
kwargs['scheme'] = kwargs.get('sentinel_master_set', None) and 'redis+sentinel' or 'redis'
Copy link
Member

Choose a reason for hiding this comment

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

word 'master' should change.

'None' seems useless here.

if kwargs['password']:
return "redis://anonymous:{password}@{host}:{port}/{db}".format(**kwargs)
return "redis://{host}:{port}/{db}".format(**kwargs)
return "{scheme}://{password_part}{host}{sentinel_part}{db_part}".format(**kwargs) + get_redis_url_param(kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

recommend only store content in variables like 'db_part', 'sentinel_part', 'password_part'. And the delimiter like/ ,@ can rendered in format string.


def get_redis_url_param(redis=None):
s = {}
if 'idle_timeout_seconds' in redis:
Copy link
Member

Choose a reason for hiding this comment

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

This command will raise an Exception instead of go to the false branch if redis is None



def get_redis_url_param(redis=None):
s = {}
Copy link
Member

Choose a reason for hiding this comment

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

it's better use a meaningful variable name

from g import DEFAULT_UID, DEFAULT_GID, host_root_dir
from pathlib import Path
Copy link
Member

Choose a reason for hiding this comment

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

move pathlib to system lib import group

@bitsf bitsf force-pushed the support_redis_sentinel branch 3 times, most recently from 04b35d9 to 1aec7f7 Compare July 17, 2020 16:37
Signed-off-by: Ziming Zhang <zziming@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support redis sentinel mode make the affection of failover of redis less
8 participants