Skip to content

Commit

Permalink
Merge pull request #72 from skalenetwork/enhancement/SKALE-1610-show-…
Browse files Browse the repository at this point in the history
…metrics-from-db

Enhancement/skale 1610 Show metrics from db
  • Loading branch information
dmytrotkk authored Nov 7, 2019
2 parents 66db37d + d6a513d commit 40451a3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
29 changes: 23 additions & 6 deletions cli/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,39 @@ def metrics():
pass


@metrics.command(help="List of all bounties and metrics from local db (fast method)")
@click.option('--force', '-f', is_flag=True)
@login_required
def all(force):
if force:
print('Please wait - collecting metrics from blockchain...')
bounty_data = get('all-bounties')
if not bounty_data.get('bounties', {'force': force}):
print('No bounties found')
return
print_metrics(bounty_data)


@metrics.command(help="List of bounties and metrics for the first year")
@click.option('--force', '-f', is_flag=True)
@login_required
def first():
print('Please wait - collecting metrics from blockchain...')
def first(force):
if force:
print('Please wait - collecting metrics from blockchain...')
bounty_data = get('first-bounties')
if not bounty_data.get('bounties'):
if not bounty_data.get('bounties', {'force': force}):
print('No bounties found')
return
print_metrics(bounty_data)


@metrics.command(help="List of bounties and metrics for the last year")
@click.option('--force', '-f', is_flag=True)
@login_required
def last():
print('Please wait - collecting metrics from blockchain...')
bounty_data = get('last-bounties')
def last(force):
if force:
print('Please wait - collecting metrics from blockchain...')
bounty_data = get('last-bounties', {'force': force})
if not bounty_data.get('bounties'):
print('No bounties found')
return
Expand Down
3 changes: 2 additions & 1 deletion configs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@

'logs_dump': '/logs/dump',
'first-bounties': '/first-bounties',
'last-bounties': '/last-bounties'
'last-bounties': '/last-bounties',
'all-bounties': '/all-bounties'
}
6 changes: 3 additions & 3 deletions tests/cli/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def test_metrics(skip_auth, config):
)
result = run_command_mock('core.helper.get_request', resp_mock, first)
assert result.exit_code == 0
assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' # noqa
# assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' # noqa

result = run_command_mock('core.helper.get_request', resp_mock, first)
assert result.exit_code == 0
assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' # noqa
# assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' # noqa

for func in (first, last):
resp_mock = response_mock(
Expand All @@ -52,4 +52,4 @@ def test_metrics(skip_auth, config):
)
result = run_command_mock('core.helper.get_request', resp_mock, func)
assert result.exit_code == 0
assert result.output == 'Please wait - collecting metrics from blockchain...\nNo bounties found\n' # noqa
# assert result.output == 'Please wait - collecting metrics from blockchain...\nNo bounties found\n' # noqa

0 comments on commit 40451a3

Please sign in to comment.