Skip to content

Commit 08c6027

Browse files
author
Ravipudi Sai Rajendra Prasad
authored
Merge pull request #50 from Rajendra-R/basescript_metric
#49 modified basescript to remove stats code
2 parents ee8c6bd + 9821b22 commit 08c6027

5 files changed

Lines changed: 4 additions & 705 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ install:
66
# consider using tox. do we need to install
77
- "pip install unittest2"
88
script:
9-
- "unit2 discover tests"
9+
- echo "No tests"
1010
before_deploy:
1111
- "wget https://github.com/jgm/pandoc/releases/download/1.19.1/pandoc-1.19.1-1-amd64.deb -O $TRAVIS_BUILD_DIR/pandoc.deb"
1212
- "sudo dpkg -i $TRAVIS_BUILD_DIR/pandoc.deb"

basescript/basescript.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
from threading import Thread
1313

1414
from .log import LevelLoggerFactory, BoundLevelLogger, StdlibStructlogHandler, StderrConsoleRenderer, Stream
15-
from .stats import Stats
16-
from .utils import Dummy
15+
from .utils import Dummy # FIXME: delete this code and use deeputil.Dummy
1716

1817
class BaseScript(object):
1918
DESC = 'Base script abstraction'
@@ -22,12 +21,6 @@ class BaseScript(object):
2221
# stdlib to structlog handlers should be configured only once.
2322
_GLOBAL_LOG_CONFIGURED = False
2423

25-
# acquires and releases locks for every metric captured
26-
THREAD_SAFE_STATS = True
27-
28-
# periodic interval to dump stats
29-
DUMP_STATS_INTERVAL = timedelta(seconds=1)
30-
3124
def __init__(self, args=None):
3225
# argparse parser obj
3326
self.parser = argparse.ArgumentParser(description=self.DESC)
@@ -44,13 +37,12 @@ def __init__(self, args=None):
4437

4538
self.hostname = socket.gethostname()
4639
self.log = self.init_logger()
40+
self.stats = Dummy()
4741

4842
args = { n: getattr(self.args, n) for n in vars(self.args) }
4943
args['func'] = self.args.func.func_name
5044
self.log.debug("basescript init", **args)
5145

52-
self.stats = self.init_stats()
53-
5446
def start(self):
5547
'''
5648
Starts execution of the script
@@ -247,25 +239,6 @@ def init_logger(self):
247239
# TODO functionality to change even the level of global stdlib logger.
248240
return log
249241

250-
def define_metric_tags(self):
251-
"""
252-
the tags (dictionary {str: str}) returned by this function
253-
must be present in every metric that basescript emits.
254-
"""
255-
return { "host": self.hostname, "name": self.name }
256-
257-
def init_stats(self):
258-
basescript_tags = self.define_metric_tags()
259-
stats = Stats(self.log, thread_safe=self.THREAD_SAFE_STATS, **basescript_tags)
260-
261-
self.dump_stats_thread = Thread(
262-
target=stats.dump_stats_periodically,
263-
kwargs={ 'interval': self.DUMP_STATS_INTERVAL },
264-
)
265-
self.dump_stats_thread.daemon = True
266-
self.dump_stats_thread.start()
267-
return stats
268-
269242
def define_subcommands(self, subcommands):
270243
'''
271244
Define subcommands (as defined at https://docs.python.org/2/library/argparse.html#sub-commands)

0 commit comments

Comments
 (0)