Skip to content

Commit

Permalink
Merge 403ed52 into 7e1e497
Browse files Browse the repository at this point in the history
  • Loading branch information
ronniesworld committed Nov 21, 2018
2 parents 7e1e497 + 403ed52 commit 94867e0
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 19 deletions.
4 changes: 3 additions & 1 deletion crawler/crawling/distributed_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ def from_settings(cls, settings):
port=settings.get('REDIS_PORT'),
db=settings.get('REDIS_DB'),
password=settings.get('REDIS_PASSWORD'),
decode_responses=True)
decode_responses=True,
socket_timeout=settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=settings.get('REDIS_SOCKET_TIMEOUT'))
persist = settings.get('SCHEDULER_PERSIST', True)
up_int = settings.get('SCHEDULER_QUEUE_REFRESH', 10)
hits = settings.get('QUEUE_HITS', 10)
Expand Down
4 changes: 3 additions & 1 deletion crawler/crawling/log_retry_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def setup(self, settings):
port=self.settings.get('REDIS_PORT'),
db=settings.get('REDIS_DB'),
password=self.settings.get('REDIS_PASSWORD'),
decode_responses=True)
decode_responses=True,
socket_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT'))

try:
self.redis_conn.info()
Expand Down
10 changes: 6 additions & 4 deletions crawler/crawling/redis_stats_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ def setup(self, settings):

# set up redis
self.redis_conn = redis.Redis(host=settings.get('REDIS_HOST'),
port=settings.get('REDIS_PORT'),
db=settings.get('REDIS_DB'),
password=settings.get('REDIS_PASSWORD'),
decode_responses=True)
port=settings.get('REDIS_PORT'),
db=settings.get('REDIS_DB'),
password=settings.get('REDIS_PASSWORD'),
decode_responses=True,
socket_timeout=settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=settings.get('REDIS_SOCKET_TIMEOUT'))

try:
self.redis_conn.info()
Expand Down
1 change: 1 addition & 0 deletions crawler/crawling/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
REDIS_PORT = '6379'
REDIS_DB = 0
REDIS_PASSWORD = None
REDIS_SOCKET_TIMEOUT = 10

# Kafka server information
KAFKA_HOSTS = ['localhost:9092']
Expand Down
1 change: 1 addition & 0 deletions docker/crawler/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def str2bool(v):
REDIS_PORT = int(os.getenv('REDIS_PORT', 6379))
REDIS_DB = int(os.getenv('REDIS_DB', 0))
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', None)
REDIS_SOCKET_TIMEOUT = int(os.getenv('REDIS_SOCKET_TIMEOUT', 10))

# Kafka server information
KAFKA_HOSTS = [x.strip() for x in os.getenv('KAFKA_HOSTS', 'kafka:9092').split(',')]
Expand Down
1 change: 1 addition & 0 deletions docker/kafka-monitor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def str2bool(v):
REDIS_PORT = int(os.getenv('REDIS_PORT', 6379))
REDIS_DB = int(os.getenv('REDIS_DB', 0))
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', None)
REDIS_SOCKET_TIMEOUT = int(os.getenv('REDIS_SOCKET_TIMEOUT', 10))

# Kafka server information
KAFKA_HOSTS = [x.strip() for x in os.getenv('KAFKA_HOSTS', 'kafka:9092').split(',')]
Expand Down
1 change: 1 addition & 0 deletions docker/redis-monitor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def str2bool(v):
REDIS_PORT = int(os.getenv('REDIS_PORT', 6379))
REDIS_DB = int(os.getenv('REDIS_DB', 0))
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', None)
REDIS_SOCKET_TIMEOUT = int(os.getenv('REDIS_SOCKET_TIMEOUT', 10))

KAFKA_HOSTS = [x.strip() for x in os.getenv('KAFKA_HOSTS', 'kafka:9092').split(',')]
KAFKA_TOPIC_PREFIX = os.getenv('KAFKA_TOPIC_PREFIX', 'demo')
Expand Down
12 changes: 12 additions & 0 deletions docs/topics/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ Date: ??/??/????

- Minor documentation changes/updates

- Added REDIS_SOCKET_TIMEOUT setting to control socket_timeout and socket_connect_timeout

Kafka Monitor Changes
^^^^^^^^^^^^^^^^^^^^^
- Added REDIS_SOCKET_TIMEOUT setting

Redis Monitor Changes
^^^^^^^^^^^^^^^^^^^^^
- Added REDIS_SOCKET_TIMEOUT setting

Crawler
^^^^^^^
- Added REDIS_SOCKET_TIMEOUT setting

- Improved request to dictionary serialization support

Expand All @@ -36,6 +47,7 @@ Rest

Utils
^^^^^
- Added REDIS_SOCKET_TIMEOUT setting

- Fixed LogFactory callback with correct extras dictionary

Expand Down
6 changes: 6 additions & 0 deletions docs/topics/crawler/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Default: ``None``

The password to use when connecting to the ``REDIS_HOST``.

**REDIS_SOCKET_TIMEOUT**

Default: ``10``

The number of seconds to wait while establishing a TCP connection, or to wait for a response from an existing TCP connection before timing out.

Kafka
-----

Expand Down
6 changes: 6 additions & 0 deletions docs/topics/kafka-monitor/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Default: ``None``

The password to use when connecting to the ``REDIS_HOST``.

**REDIS_SOCKET_TIMEOUT**

Default: ``10``

The number of seconds to wait while establishing a TCP connection, or to wait for a response from an existing TCP connection before timing out.

Kafka
-----

Expand Down
6 changes: 6 additions & 0 deletions docs/topics/redis-monitor/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ Default: ``6``

The number of seconds a vacant worker lock will stay within Redis before becoming available to a new worker

**REDIS_SOCKET_TIMEOUT**

Default: ``10``

The number of seconds to wait while establishing a TCP connection, or to wait for a response from an existing TCP connection before timing out.

Kafka
-----

Expand Down
4 changes: 3 additions & 1 deletion kafka-monitor/kafka_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def _setup_stats(self):
port=self.settings['REDIS_PORT'],
db=self.settings.get('REDIS_DB'),
password=self.settings['REDIS_PASSWORD'],
decode_responses=True)
decode_responses=True,
socket_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT'))

try:
redis_conn.info()
Expand Down
4 changes: 3 additions & 1 deletion kafka-monitor/plugins/action_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def setup(self, settings):
port=settings['REDIS_PORT'],
db=settings.get('REDIS_DB'),
password=settings['REDIS_PASSWORD'],
decode_responses=True)
decode_responses=True,
socket_timeout=settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=settings.get('REDIS_SOCKET_TIMEOUT'))

try:
self.redis_conn.info()
Expand Down
4 changes: 3 additions & 1 deletion kafka-monitor/plugins/scraper_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def setup(self, settings):
port=settings['REDIS_PORT'],
db=settings.get('REDIS_DB'),
password=settings['REDIS_PASSWORD'],
decode_responses=True)
decode_responses=True,
socket_timeout=settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=settings.get('REDIS_SOCKET_TIMEOUT'))

try:
self.redis_conn.info()
Expand Down
4 changes: 3 additions & 1 deletion kafka-monitor/plugins/stats_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def setup(self, settings):
port=settings['REDIS_PORT'],
db=settings.get('REDIS_DB'),
password=settings['REDIS_PASSWORD'],
decode_responses=True)
decode_responses=True,
socket_timeout=settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=settings.get('REDIS_SOCKET_TIMEOUT'))

try:
self.redis_conn.info()
Expand Down
4 changes: 3 additions & 1 deletion kafka-monitor/plugins/zookeeper_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def setup(self, settings):
port=settings['REDIS_PORT'],
db=settings.get('REDIS_DB'),
password=settings['REDIS_PASSWORD'],
decode_responses=True)
decode_responses=True,
socket_timeout=settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=settings.get('REDIS_SOCKET_TIMEOUT'))

try:
self.redis_conn.info()
Expand Down
1 change: 1 addition & 0 deletions kafka-monitor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_PASSWORD = None
REDIS_SOCKET_TIMEOUT = 10

# Kafka server information
KAFKA_HOSTS = ['localhost:9092']
Expand Down
14 changes: 9 additions & 5 deletions redis-monitor/redis_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ def setup(self, level=None, log_file=None, json=None):
backups=self.settings['LOG_BACKUPS'])

self.redis_conn = redis.StrictRedis(host=self.settings['REDIS_HOST'],
port=self.settings['REDIS_PORT'],
db=self.settings['REDIS_DB'],
password=self.settings['REDIS_PASSWORD'],
decode_responses=True)
port=self.settings['REDIS_PORT'],
db=self.settings['REDIS_DB'],
password=self.settings['REDIS_PASSWORD'],
decode_responses=True,
socket_timeout = self.settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout = self.settings.get('REDIS_SOCKET_TIMEOUT'))
# redis_lock needs a redis connection without setting decode_responses
# to True
self.lock_redis_conn = redis.StrictRedis(host=self.settings['REDIS_HOST'],
port=self.settings['REDIS_PORT'],
db=self.settings['REDIS_DB'],
password=self.settings['REDIS_PASSWORD'])
password=self.settings['REDIS_PASSWORD'],
socket_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT'),
socket_connect_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT'))

try:
self.redis_conn.info()
Expand Down
1 change: 1 addition & 0 deletions redis-monitor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_PASSWORD = None
REDIS_SOCKET_TIMEOUT = 10

KAFKA_HOSTS = 'localhost:9092'
KAFKA_TOPIC_PREFIX = 'demo'
Expand Down
8 changes: 5 additions & 3 deletions utils/scutils/stats_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class StatsCollector(object):
SECONDS_7_DAY = SECONDS_1_DAY * 7
SECONDS_1_WEEK = SECONDS_7_DAY
SECONDS_30_DAY = SECONDS_1_DAY * 30
REDIS_SOCKET_TIMEOUT = 10

@classmethod
def get_time_window(self, redis_conn=None, host='localhost', port=6379,
Expand Down Expand Up @@ -220,10 +221,11 @@ def setup(self, redis_conn=None, host='localhost', port=6379, password=None):
if redis_conn is None:
if host is not None and port is not None:
self.redis_conn = redis.Redis(host=host, port=port, password=password,
decode_responses=True)
decode_responses=True,
socket_timeout=self.REDIS_SOCKET_TIMEOUT,
socket_connect_timeout=self.REDIS_SOCKET_TIMEOUT)
else:
raise Exception("Please specify some form of connection "
"to Redis")
raise Exception("Please specify some form of connection to Redis")
else:
self.redis_conn = redis_conn

Expand Down

0 comments on commit 94867e0

Please sign in to comment.