Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/issue209/prometheus consolidation #210

Merged
merged 11 commits into from
Nov 22, 2023
62 changes: 15 additions & 47 deletions powerapi/cli/common_cli_parsing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from powerapi.cli.parsing_manager import RootConfigParsingManager, SubgroupConfigParsingManager
from powerapi.cli.config_parser import store_true
from powerapi.cli.config_parser import MissingValueException
from powerapi.database.prometheus_db import DEFAULT_METRIC_DESCRIPTION, DEFAULT_MODEL_VALUE, DEFAULT_PUSHER_NAME, \

Check warning on line 35 in powerapi/cli/common_cli_parsing_manager.py

View check run for this annotation

Codecov / codecov/patch

powerapi/cli/common_cli_parsing_manager.py#L35

Added line #L35 was not covered by tests
DEFAULT_ADDRESS
from powerapi.exception import BadTypeException, BadContextException, UnknownArgException

POWERAPI_ENVIRONMENT_VARIABLE_PREFIX = 'POWERAPI_'
Expand Down Expand Up @@ -250,69 +252,35 @@
subgroup_parser=subparser_mongo_output
)

subparser_prom_output = SubgroupConfigParsingManager("prom")
subparser_prom_output.add_argument("t", "tags", help_text="specify report tags")
subparser_prom_output.add_argument("u", "uri", help_text="specify server uri")
subparser_prom_output.add_argument(
subparser_prometheus_output = SubgroupConfigParsingManager("prometheus")
subparser_prometheus_output.add_argument("t", "tags", help_text="specify report tags")
subparser_prometheus_output.add_argument("u", "uri", help_text="specify server uri",

Check warning on line 257 in powerapi/cli/common_cli_parsing_manager.py

View check run for this annotation

Codecov / codecov/patch

powerapi/cli/common_cli_parsing_manager.py#L255-L257

Added lines #L255 - L257 were not covered by tests
default_value=DEFAULT_ADDRESS)
subparser_prometheus_output.add_argument(

Check warning on line 259 in powerapi/cli/common_cli_parsing_manager.py

View check run for this annotation

Codecov / codecov/patch

powerapi/cli/common_cli_parsing_manager.py#L259

Added line #L259 was not covered by tests
"p", "port", help_text="specify server port", argument_type=int
)
subparser_prom_output.add_argument(
subparser_prometheus_output.add_argument(

Check warning on line 262 in powerapi/cli/common_cli_parsing_manager.py

View check run for this annotation

Codecov / codecov/patch

powerapi/cli/common_cli_parsing_manager.py#L262

Added line #L262 was not covered by tests
"M", "metric_name", help_text="specify metric name"
)
subparser_prom_output.add_argument(
subparser_prometheus_output.add_argument(

Check warning on line 265 in powerapi/cli/common_cli_parsing_manager.py

View check run for this annotation

Codecov / codecov/patch

powerapi/cli/common_cli_parsing_manager.py#L265

Added line #L265 was not covered by tests
"d",
"metric_description",
help_text="specify metric description",
default_value="energy consumption",
)
help_text = "specify number of second for the value must be aggregated before compute statistics on them"
subparser_prom_output.add_argument(
"A", "aggregation_period", help_text=help_text, default_value=15, argument_type=int
default_value=DEFAULT_METRIC_DESCRIPTION
)

subparser_prom_output.add_argument(
subparser_prometheus_output.add_argument(

Check warning on line 272 in powerapi/cli/common_cli_parsing_manager.py

View check run for this annotation

Codecov / codecov/patch

powerapi/cli/common_cli_parsing_manager.py#L272

Added line #L272 was not covered by tests
"m",
"model",
help_text="specify data type that will be stored in the database",
default_value="PowerReport",
)
subparser_prom_output.add_argument(
"n", "name", help_text="specify pusher name", default_value="pusher_prom"
)
self.add_subgroup_parser(
subgroup_name="output",
subgroup_parser=subparser_prom_output
)

subparser_direct_prom_output = SubgroupConfigParsingManager("direct_prom")
subparser_direct_prom_output.add_argument(
"t", "tags", help_text="specify report tags"
)
subparser_direct_prom_output.add_argument("a", "uri", help_text="specify server uri")
subparser_direct_prom_output.add_argument(
"p", "port", help_text="specify server port", argument_type=int
)
subparser_direct_prom_output.add_argument(
"M", "metric_name", help_text="specify metric name"
)
subparser_direct_prom_output.add_argument(
"d",
"metric_description",
help_text="specify metric description",
default_value="energy consumption",
)
subparser_direct_prom_output.add_argument(
"m",
"model",
help_text="specify data type that will be stored in the database",
default_value="PowerReport",
default_value=DEFAULT_MODEL_VALUE,
)
subparser_direct_prom_output.add_argument(
"n", "name", help_text="specify pusher name", default_value="pusher_prom"
subparser_prometheus_output.add_argument(

Check warning on line 278 in powerapi/cli/common_cli_parsing_manager.py

View check run for this annotation

Codecov / codecov/patch

powerapi/cli/common_cli_parsing_manager.py#L278

Added line #L278 was not covered by tests
"n", "name", help_text="specify pusher name", default_value=DEFAULT_PUSHER_NAME
)
self.add_subgroup_parser(
subgroup_name="output",
subgroup_parser=subparser_direct_prom_output
subgroup_parser=subparser_prometheus_output
)

subparser_csv_output = SubgroupConfigParsingManager("csv")
Expand Down
2 changes: 1 addition & 1 deletion powerapi/cli/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def validate(self, conf: dict) -> dict:
elif current_argument_name != 'type':
raise UnknownArgException(argument_name=current_argument_name)

return conf
return self.normalize_configuration(conf=conf)

def normalize_configuration(self, conf: dict) -> dict:
"""
Expand Down
20 changes: 8 additions & 12 deletions powerapi/cli/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
TIMEOUT_QUERY_DEFAULT_VALUE
from powerapi.processor.pre.libvirt.libvirt_pre_processor_actor import LibvirtPreProcessorActor
from powerapi.report import HWPCReport, PowerReport, ControlReport, ProcfsReport, Report, FormulaReport
from powerapi.database import MongoDB, CsvDB, InfluxDB, OpenTSDB, SocketDB, PrometheusDB, DirectPrometheusDB, \
from powerapi.database import MongoDB, CsvDB, InfluxDB, OpenTSDB, SocketDB, PrometheusDB, \
VirtioFSDB, FileDB
from powerapi.puller import PullerActor
from powerapi.pusher import PusherActor
Expand Down Expand Up @@ -181,7 +181,7 @@ def __init__(self, component_group_name: str):
self.db_factory = {
'mongodb': lambda db_config: MongoDB(report_type=db_config['model'], uri=db_config['uri'],
db_name=db_config['db'], collection_name=db_config['collection']),
'socket': lambda db_config: SocketDB(db_config['model'], db_config['port']),
'socket': lambda db_config: SocketDB(report_type=db_config['model'], port=db_config['port']),
'csv': lambda db_config: CsvDB(report_type=db_config['model'], tags=gen_tag_list(db_config),
current_path=os.getcwd() if 'directory' not in db_config else db_config[
'directory'],
Expand All @@ -196,16 +196,12 @@ def __init__(self, component_group_name: str):
port=None if 'port' not in db_config else db_config['port']),
'opentsdb': lambda db_config: OpenTSDB(report_type=db_config['model'], host=db_config['uri'],
port=db_config['port'], metric_name=db_config['metric_name']),
'prom': lambda db_config: PrometheusDB(report_type=db_config['model'], port=db_config['port'],
address=db_config['uri'], metric_name=db_config['metric_name'],
metric_description=db_config['metric_description'],
aggregation_periode=db_config['aggregation_period'],
tags=gen_tag_list(db_config)),
'direct_prom': lambda db_config: DirectPrometheusDB(report_type=db_config['model'], port=db_config['port'],
address=db_config['uri'],
metric_name=db_config['metric_name'],
metric_description=db_config['metric_description'],
tags=gen_tag_list(db_config)),
'prometheus': lambda db_config: PrometheusDB(report_type=db_config['model'],
port=db_config['port'],
address=db_config['uri'],
metric_name=db_config['metric_name'],
metric_description=db_config['metric_description'],
tags=gen_tag_list(db_config)),
'virtiofs': lambda db_config: VirtioFSDB(report_type=db_config['model'],
vm_name_regexp=db_config['vm_name_regexp'],
root_directory_name=db_config['root_directory_name'],
Expand Down
1 change: 0 additions & 1 deletion powerapi/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@
from powerapi.database.influxdb2 import InfluxDB2
from powerapi.database.prometheus_db import PrometheusDB
from powerapi.database.virtiofs_db import VirtioFSDB
from powerapi.database.direct_prometheus_db import DirectPrometheusDB
from powerapi.database.socket_db import SocketDB
from powerapi.database.file_db import FileDB
112 changes: 0 additions & 112 deletions powerapi/database/direct_prometheus_db.py

This file was deleted.

Loading