Skip to content

Commit

Permalink
Closes #415: Make data source health monitoring an extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel committed Aug 10, 2018
1 parent faf9c84 commit bcd0d20
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 226 deletions.
3 changes: 0 additions & 3 deletions redash/monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from redash import redis_connection, models, __version__, settings


Expand All @@ -15,10 +14,8 @@ def get_object_counts():
status['unused_query_results_count'] = models.QueryResult.unused().count()
status['dashboards_count'] = models.Dashboard.query.count()
status['widgets_count'] = models.Widget.query.count()
status['data_sources'] = json.loads(redis_connection.get('data_sources:health') or '{}')
return status


def get_queues():
queues = {}
for ds in models.DataSource.query:
Expand Down
6 changes: 2 additions & 4 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ def get_data_source_version(self):

return version

def test_connection(self, custom_query_text=None):
def test_connection(self):
if self.noop_query is None:
raise NotImplementedError()

query_text = custom_query_text or self.noop_query
data, error = self.run_query(query_text, None)
data, error = self.run_query(self.noop_query, None)

if error is not None:
raise Exception(error)
Expand Down
13 changes: 1 addition & 12 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from funcy import distinct, remove

from .helpers import parse_db_url, fix_assets_path, array_from_string, parse_boolean, int_or_none, set_from_string, dict_from_string
from .helpers import parse_db_url, fix_assets_path, array_from_string, parse_boolean, int_or_none, set_from_string


def all_settings():
Expand Down Expand Up @@ -242,14 +242,3 @@ def all_settings():
# Allow Parameters in Embeds
# WARNING: With this option enabled, Redash reads query parameters from the request URL (risk of SQL injection!)
ALLOW_PARAMETERS_IN_EMBEDS = parse_boolean(os.environ.get("REDASH_ALLOW_PARAMETERS_IN_EMBEDS", "false"))

# Allow for a map of custom queries to test data source performance and availability.
# A sample map may look like:
# {
# "1": "select 1;",
# "5": "select 1;"
# }
CUSTOM_HEALTH_QUERIES = dict_from_string(os.environ.get("REDASH_CUSTOM_HEALTH_QUERIES", ""))

# Frequency of health query runs in minutes (12 hours by default)
HEALTH_QUERIES_REFRESH_SCHEDULE = int(os.environ.get("REDASH_HEALTH_QUERIES_REFRESH_SCHEDULE", 720))
6 changes: 0 additions & 6 deletions redash/settings/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ def array_from_string(s):

return [item.strip() for item in array]

def dict_from_string(s):
try:
return json.loads(s)
except ValueError:
return {}


def set_from_string(s):
return set(array_from_string(s))
Expand Down
1 change: 0 additions & 1 deletion redash/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .general import record_event, version_check, send_mail
from .health import health_status
from .queries import QueryTask, refresh_queries, refresh_schemas, cleanup_tasks, cleanup_query_results, execute_query
from .alerts import check_alerts_for_query
59 changes: 0 additions & 59 deletions redash/tasks/health.py

This file was deleted.

11 changes: 7 additions & 4 deletions redash/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
include='redash.tasks')

celery_schedule = {
'health_status': {
'task': 'redash.tasks.health_status',
'schedule': timedelta(minutes=settings.HEALTH_QUERIES_REFRESH_SCHEDULE)
},
'refresh_queries': {
'task': 'redash.tasks.refresh_queries',
'schedule': timedelta(seconds=30)
Expand Down Expand Up @@ -82,3 +78,10 @@ def __call__(self, *args, **kwargs):
def init_celery_flask_app(**kwargs):
app = create_app()
app.app_context().push()

@celery.on_after_configure.connect
def add_periodic_tasks(sender, **kwargs):
app = create_app()
periodic_tasks = getattr(app, 'periodic_tasks', {})
for params in periodic_tasks.values():
sender.add_periodic_task(**params)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ disposable-email-domains
# Uncomment the requirement for ldap3 if using ldap.
# It is not included by default because of the GPL license conflict.
# ldap3==2.2.4
redash-stmo>=2018.4.0
redash-stmo>=2018.8.1
136 changes: 0 additions & 136 deletions tests/tasks/test_health.py

This file was deleted.

0 comments on commit bcd0d20

Please sign in to comment.