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

Adding some STATSD logging #2715

Merged
merged 1 commit into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
from dateutil import tz
from flask_appbuilder.security.manager import AUTH_DB

from superset.stats_logger import DummyStatsLogger

# Realtime stats logger, a StatsD implementation exists
STATS_LOGGER = DummyStatsLogger()

BASE_DIR = os.path.abspath(os.path.dirname(__file__))
DATA_DIR = os.path.join(os.path.expanduser('~'), '.superset')
if not os.path.exists(DATA_DIR):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
down_revision = '979c03af3341'



def upgrade():
op.add_column(
'query',
Expand Down
2 changes: 2 additions & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from urllib import parse # noqa

config = app.config
stats_logger = config.get('STATS_LOGGER')
metadata = Model.metadata # pylint: disable=no-member


Expand Down Expand Up @@ -751,6 +752,7 @@ def wrapper(*args, **kwargs):
params = json.dumps(d)
except:
pass
stats_logger.incr(f.__name__)
value = f(*args, **kwargs)

sesh = db.session()
Expand Down
57 changes: 57 additions & 0 deletions superset/stats_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

class BaseStatsLogger(object):
"""Base class for logging realtime events"""

def __init__(self, prefix='superset'):
self.prefix = prefix

def key(self, key):
if self.prefix:
return self.prefix + key
return key

def incr(self, key):
"""Increment a counter"""
raise NotImplementedError()

def decr(self, key):
"""Decrement a counter"""
raise NotImplementedError()

def gauge(self, key):
"""Setup a gauge"""
raise NotImplementedError()


class DummyStatsLogger(BaseStatsLogger):

def incr(self, key):
pass

def decr(self, key):
pass

def gauge(self, key):
pass


try:
from statsd import StatsClient

class StatsdStatsLogger(BaseStatsLogger):
def __init__(self, host, port, prefix='superset'):
self.client = StatsClient(
host=host,
port=port,
prefix=prefix)

def incr(self, key):
self.client.incr(key)

def decr(self, key):
self.client.decr(key)

def gauge(self, key):
self.client.gauge(key)
except Exception as e:
pass