-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from snelis/master
NEW elasticsearch backend
- Loading branch information
Showing
16 changed files
with
510 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
influxdb | ||
influxdb>=2.11 | ||
elasticsearch>=2.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from time_execution import time_execution | ||
|
||
|
||
@time_execution | ||
def go(*args, **kwargs): | ||
return True | ||
|
||
|
||
@time_execution | ||
def fqn_test(): | ||
pass | ||
|
||
|
||
@time_execution | ||
class Dummy(object): | ||
@time_execution | ||
def go(self, *args, **kwargs): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import unittest | ||
|
||
from time_execution.backends.base import BaseMetricsBackend | ||
|
||
|
||
class TestBaseBackend(unittest.TestCase): | ||
def test_write_method(self): | ||
backend = BaseMetricsBackend() | ||
with self.assertRaises(NotImplementedError): | ||
backend.write('test') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from tests.conftest import Dummy, go | ||
from tests.test_base_backend import TestBaseBackend | ||
from time_execution import configure | ||
from time_execution.backends.elasticsearch import ElasticsearchBackend | ||
|
||
|
||
class TestTimeExecution(TestBaseBackend): | ||
def setUp(self): | ||
super(TestTimeExecution, self).setUp() | ||
|
||
self.backend = ElasticsearchBackend( | ||
'elasticsearch', | ||
index='unittest', | ||
) | ||
|
||
self._clear() | ||
configure(backends=[self.backend]) | ||
|
||
def tearDown(self): | ||
self._clear() | ||
|
||
def _clear(self): | ||
self.backend.client.indices.delete(self.backend.index, ignore=404) | ||
self.backend.client.indices.delete("{}*".format(self.backend.index), ignore=404) | ||
|
||
def _query_backend(self, name): | ||
|
||
self.backend.client.indices.refresh(self.backend.get_index()) | ||
metrics = self.backend.client.search( | ||
index=self.backend.get_index(), | ||
body={ | ||
"query": { | ||
"term": {"name": name} | ||
}, | ||
} | ||
) | ||
return metrics | ||
|
||
def test_time_execution(self): | ||
|
||
count = 4 | ||
|
||
for i in range(count): | ||
go() | ||
|
||
metrics = self._query_backend(go.fqn) | ||
self.assertEqual(metrics['hits']['total'], count) | ||
|
||
for metric in metrics['hits']['hits']: | ||
self.assertTrue('value' in metric['_source']) | ||
|
||
def test_duration_field(self): | ||
|
||
configure(backends=[self.backend], duration_field='my_duration') | ||
|
||
go() | ||
|
||
for metric in self._query_backend(go.fqn)['hits']['hits']: | ||
self.assertTrue('my_duration' in metric['_source']) | ||
|
||
def test_with_arguments(self): | ||
go('hello', world='world') | ||
Dummy().go('hello', world='world') | ||
|
||
metrics = self._query_backend(go.fqn) | ||
self.assertEqual(metrics['hits']['total'], 1) | ||
|
||
metrics = self._query_backend(Dummy().go.fqn) | ||
self.assertEqual(metrics['hits']['total'], 1) | ||
|
||
def test_hook(self): | ||
|
||
def test_args(**kwargs): | ||
self.assertIn('response', kwargs) | ||
self.assertIn('exception', kwargs) | ||
self.assertIn('metric', kwargs) | ||
return dict() | ||
|
||
def test_metadata(*args, **kwargs): | ||
return dict(test_key='test value') | ||
|
||
configure(backends=[self.backend], hooks=[test_args, test_metadata]) | ||
|
||
go() | ||
|
||
for metric in self._query_backend(go.fqn)['hits']['hits']: | ||
self.assertEqual(metric['_source']['test_key'], 'test value') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import unittest | ||
|
||
from tests.conftest import Dummy, fqn_test | ||
|
||
|
||
class TestFQN(unittest.TestCase): | ||
|
||
def test_fqn(self): | ||
self.assertEqual(fqn_test.fqn, 'tests.conftest.fqn_test') | ||
self.assertEqual(Dummy.fqn, 'tests.conftest.Dummy') | ||
self.assertEqual(Dummy().go.fqn, 'tests.conftest.Dummy.go') |
Oops, something went wrong.