Skip to content
Closed
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
12 changes: 6 additions & 6 deletions esrally/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import tabulate

from esrally import client, config, exceptions, paths, time, version
from esrally import client, config, exceptions, paths, props, time, version
from esrally.utils import console, convert, io, versions


Expand Down Expand Up @@ -1595,13 +1595,13 @@ def store_race(self, race):
raise NotImplementedError("abstract method")

def _max_results(self):
return int(self.cfg.opts("system", "list.max_results"))
return int(self.cfg.opts(*props.SYSTEM.LIST.MAX_RESULTS))

def _track(self):
return self.cfg.opts("system", "admin.track", mandatory=False)
return self.cfg.opts(*props.SYSTEM.ADMIN.TRACK, mandatory=False)

def _benchmark_name(self):
return self.cfg.opts("system", "list.races.benchmark_name", mandatory=False)
return self.cfg.opts(*props.SYSTEM.LIST.RACES.BENCHMARK_NAME, mandatory=False)

def _race_timestamp(self):
return self.cfg.opts("system", "add.race_timestamp")
Expand All @@ -1616,10 +1616,10 @@ def _chart_name(self):
return self.cfg.opts("system", "add.chart_name", mandatory=False)

def _from_date(self):
return self.cfg.opts("system", "list.from_date", mandatory=False)
return self.cfg.opts(*props.SYSTEM.LIST.FROM_DATE, mandatory=False)

def _to_date(self):
return self.cfg.opts("system", "list.to_date", mandatory=False)
return self.cfg.opts(*props.SYSTEM.LIST.TO_DATE, mandatory=False)

def _dry_run(self):
return self.cfg.opts("system", "admin.dry_run", mandatory=False)
Expand Down
124 changes: 124 additions & 0 deletions esrally/props.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from enum import Enum, auto

# TODO remove ImportError fallback when we drop support for Python 3.10
try:
from enum import EnumType, member
except ImportError:
from enum import EnumMeta as EnumType

def member(enum):
return enum


class PropEnumType(EnumType):
__iter__ = None # Disallows erroneous unpack by star expansion


class PropEnum(str, Enum, metaclass=PropEnumType):
"""StrEnum-like Enum but supports multi-level nesting"""

def __new__(cls, value):
if isinstance(value, PropEnumType):
return value # Nested Enum should stay original
elif isinstance(value, str):
# String member A.B.C.D value is prefixed to obtain "a.b.c.d" instead of "d"
value = f"{cls.__qualname__.lower()}.{value}"
member = str.__new__(cls, value)
member._value_ = value
return member
else:
raise TypeError(f"{value!r} is not a string or enum")

@staticmethod
def _generate_next_value_(name, *_):
return name.lower()


class Property(PropEnum):
def __sections(self):
"""Yields section names from the top level to the bottom"""
node = globals()
for name in type(self).__qualname__.split("."):
node = node[name]
if issubclass(node, Section):
yield name
else:
break

@property
def __section(self):
return ".".join(map(str.lower, self.__sections()))

@property
def __key(self):
return self.value.replace(f"{self.__section}.", "", 1)

def __iter__(self):
"""Allows to unpack pair of section and key names by star expansion"""
return iter(
(
self.__section,
self.__key,
)
)

def __repr__(self):
return f"<{type(self).__qualname__}.{self.name}: {self.value}>"


class Section(Property):
pass


class Key(Property):
pass


def desc(*_):
"""Just a blank function to write a description for each key as a string

The usage of this function is open-ended for future enhancements. By main-
taining descriptions as (list of) str in the source code, it may be
possible to reuse them as e.g. help texts for users in the future.

Returns `enum.auto()` to let Enum populate an appropriate value to the
member.
"""
return auto()


class SYSTEM(Section):
@member
class ADMIN(Key):
TRACK = desc()

@member
class LIST(Key):
FROM_DATE = desc("list records only from this date")
MAX_RESULTS = desc("the limit of the number of records to return")
TO_DATE = desc("list records only to this date")

@member
class CONFIG(Key):
OPTION = desc()

@member
class RACES(Key):
BENCHMARK_NAME = desc()
13 changes: 7 additions & 6 deletions esrally/rally.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
log,
metrics,
paths,
props,
racecontrol,
reporter,
telemetry,
Expand Down Expand Up @@ -1086,12 +1087,12 @@ def dispatch_sub_command(arg_parser, args, cfg):
configure_reporting_params(args, cfg)
reporter.compare(cfg, args.baseline, args.contender)
elif sub_command == "list":
cfg.add(config.Scope.applicationOverride, "system", "list.config.option", args.configuration)
cfg.add(config.Scope.applicationOverride, "system", "list.max_results", args.limit)
cfg.add(config.Scope.applicationOverride, "system", "admin.track", args.track)
cfg.add(config.Scope.applicationOverride, "system", "list.races.benchmark_name", args.benchmark_name)
cfg.add(config.Scope.applicationOverride, "system", "list.from_date", args.from_date)
cfg.add(config.Scope.applicationOverride, "system", "list.to_date", args.to_date)
cfg.add(config.Scope.applicationOverride, *props.SYSTEM.LIST.CONFIG.OPTION, args.configuration)
cfg.add(config.Scope.applicationOverride, *props.SYSTEM.LIST.MAX_RESULTS, args.limit)
cfg.add(config.Scope.applicationOverride, *props.SYSTEM.ADMIN.TRACK, args.track)
cfg.add(config.Scope.applicationOverride, *props.SYSTEM.LIST.RACES.BENCHMARK_NAME, args.benchmark_name)
cfg.add(config.Scope.applicationOverride, *props.SYSTEM.LIST.FROM_DATE, args.from_date)
cfg.add(config.Scope.applicationOverride, *props.SYSTEM.LIST.TO_DATE, args.to_date)
configure_mechanic_params(args, cfg, command_requires_car=False)
configure_track_params(arg_parser, args, cfg, command_requires_track=False)
dispatch_list(cfg)
Expand Down