Merge "benchmark: add get metric"
This commit is contained in:
commit
3d05d61b7d
|
@ -15,6 +15,7 @@ import argparse
|
|||
import logging
|
||||
import time
|
||||
|
||||
from cliff import command
|
||||
import futurist
|
||||
from oslo_utils import timeutils
|
||||
import six.moves
|
||||
|
@ -97,7 +98,40 @@ class BenchmarkPool(futurist.ThreadPoolExecutor):
|
|||
}
|
||||
|
||||
|
||||
class CliBenchmarkMetricCreate(metric_cli.CliMetricCreateBase):
|
||||
class CliBenchmarkBase(command.Command):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CliBenchmarkBase, self).get_parser(prog_name)
|
||||
parser.add_argument("--workers", "-w",
|
||||
default=None,
|
||||
type=_positive_non_zero_int,
|
||||
help="Number of workers to use")
|
||||
return parser
|
||||
|
||||
|
||||
class CliBenchmarkMetricShow(CliBenchmarkBase,
|
||||
metric_cli.CliMetricShowBase):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CliBenchmarkMetricShow, self).get_parser(prog_name)
|
||||
parser.add_argument("metric", nargs='+',
|
||||
help="ID or name of the metrics")
|
||||
parser.add_argument("--count", "-n",
|
||||
required=True,
|
||||
type=_positive_non_zero_int,
|
||||
help="Number of metrics to get")
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
pool = BenchmarkPool(parsed_args.workers)
|
||||
LOG.info("Getting metrics")
|
||||
futures = pool.map_job(self.app.client.metric.get,
|
||||
parsed_args.metric * parsed_args.count,
|
||||
resource_id=parsed_args.resource_id)
|
||||
result, stats = pool.wait_job("show", futures)
|
||||
return self.dict2columns(stats)
|
||||
|
||||
|
||||
class CliBenchmarkMetricCreate(CliBenchmarkBase,
|
||||
metric_cli.CliMetricCreateBase):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CliBenchmarkMetricCreate, self).get_parser(prog_name)
|
||||
parser.add_argument("--count", "-n",
|
||||
|
@ -107,10 +141,6 @@ class CliBenchmarkMetricCreate(metric_cli.CliMetricCreateBase):
|
|||
parser.add_argument("--keep", "-k",
|
||||
action='store_true',
|
||||
help="Keep created metrics")
|
||||
parser.add_argument("--workers", "-w",
|
||||
default=None,
|
||||
type=_positive_non_zero_int,
|
||||
help="Number of workers to use")
|
||||
return parser
|
||||
|
||||
def _take_action(self, metric, parsed_args):
|
||||
|
|
|
@ -63,6 +63,7 @@ class GnocchiCommandManager(commandmanager.CommandManager):
|
|||
"measures aggregation": metric_cli.CliMeasuresAggregation,
|
||||
"capabilities list": capabilities_cli.CliCapabilitiesList,
|
||||
"benchmark metric create": benchmark.CliBenchmarkMetricCreate,
|
||||
"benchmark metric show": benchmark.CliBenchmarkMetricShow,
|
||||
}
|
||||
|
||||
def load_commands(self, namespace):
|
||||
|
|
|
@ -41,3 +41,19 @@ class BenchmarkMetricTest(base.ClientTestBase):
|
|||
self.assertEqual(10, int(result['create executed']))
|
||||
self.assertLessEqual(int(result['create failures']), 10)
|
||||
self.assertNotIn('delete executed', result)
|
||||
|
||||
def test_benchmark_metric_get(self):
|
||||
apname = str(uuid.uuid4())
|
||||
# PREPARE AN ACHIVE POLICY
|
||||
self.gnocchi("archive-policy", params="create %s "
|
||||
"--back-window 0 -d granularity:1s,points:86400" % apname)
|
||||
|
||||
result = self.gnocchi(
|
||||
u'metric', params=u"create -a %s" % apname)
|
||||
metric = self.details_multiple(result)[0]
|
||||
|
||||
result = self.gnocchi(
|
||||
u'benchmark', params=u"metric show -n 10 %s" % metric['id'])
|
||||
result = self.details_multiple(result)[0]
|
||||
self.assertEqual(10, int(result['show executed']))
|
||||
self.assertLessEqual(int(result['show failures']), 10)
|
||||
|
|
|
@ -167,7 +167,8 @@ class MetricClientTest(base.ClientTestBase):
|
|||
self.assertIn("metric-test", metric["archive_policy/name"])
|
||||
|
||||
# GET
|
||||
result = self.gnocchi('metric', params="show metric-name metric-res")
|
||||
result = self.gnocchi('metric',
|
||||
params="show -r metric-res metric-name")
|
||||
metric_get = self.details_multiple(result)[0]
|
||||
self.assertEqual(metric, metric_get)
|
||||
|
||||
|
@ -226,7 +227,8 @@ class MetricClientTest(base.ClientTestBase):
|
|||
self.assertEqual("", result)
|
||||
|
||||
# GET FAIL
|
||||
result = self.gnocchi('metric', params="show metric-name metric-res",
|
||||
result = self.gnocchi('metric',
|
||||
params="show -r metric-res metric-name",
|
||||
fail_ok=True, merge_stderr=True)
|
||||
self.assertFirstLineStartsWith(result.split('\n'),
|
||||
"Not Found (HTTP 404)")
|
||||
|
|
|
@ -29,13 +29,19 @@ class CliMetricList(lister.Lister):
|
|||
return utils.list2cols(self.COLS, metrics)
|
||||
|
||||
|
||||
class CliMetricShow(show.ShowOne):
|
||||
class CliMetricShowBase(show.ShowOne):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CliMetricShowBase, self).get_parser(prog_name)
|
||||
parser.add_argument("--resource-id", "-r",
|
||||
help="ID of the resource")
|
||||
return parser
|
||||
|
||||
|
||||
class CliMetricShow(CliMetricShowBase):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CliMetricShow, self).get_parser(prog_name)
|
||||
parser.add_argument("metric",
|
||||
help="ID or name of the metric")
|
||||
parser.add_argument("resource_id", nargs='?',
|
||||
help="ID of the resource")
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
|
Loading…
Reference in New Issue