From 4ea2066933748563383537db60ac8de56ecd02e3 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 12 Jan 2024 11:02:17 +0100 Subject: [PATCH 1/2] refactor: Remove influxdb 1.8 as source, its dependencies and tests --- src/powerapi/cli/generator.py | 5 +- src/powerapi/database/__init__.py | 1 - src/powerapi/database/influxdb.py | 128 ----------- tests/acceptation/test_simple_architecture.py | 38 +--- tests/integration/cli/test_generate_pusher.py | 100 --------- tests/integration/database/test_influxdb.py | 202 ------------------ tests/integration/database/test_influxdb2.py | 10 +- tests/unit/cli/test_generator.py | 19 +- tests/utils/acceptation.py | 17 -- ...uts_stream_mode_enabled_configuration.json | 7 - tests/utils/db/influx.py | 71 ------ tests/utils/db/influx2.py | 2 +- 12 files changed, 9 insertions(+), 591 deletions(-) delete mode 100644 src/powerapi/database/influxdb.py delete mode 100644 tests/integration/cli/test_generate_pusher.py delete mode 100644 tests/integration/database/test_influxdb.py delete mode 100644 tests/utils/db/influx.py diff --git a/src/powerapi/cli/generator.py b/src/powerapi/cli/generator.py index 3fd3e4c7..ecb115c5 100644 --- a/src/powerapi/cli/generator.py +++ b/src/powerapi/cli/generator.py @@ -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, \ +from powerapi.database import MongoDB, CsvDB, OpenTSDB, SocketDB, PrometheusDB, \ VirtioFSDB, FileDB from powerapi.puller import PullerActor from powerapi.pusher import PusherActor @@ -186,9 +186,6 @@ def __init__(self, component_group_name: str): current_path=os.getcwd() if 'directory' not in db_config else db_config[ 'directory'], files=[] if 'files' not in db_config else db_config['files']), - 'influxdb': lambda db_config: InfluxDB(report_type=db_config['model'], uri=db_config['uri'], - port=db_config['port'], db_name=db_config['db'], - tags=gen_tag_list(db_config)), 'influxdb2': lambda db_config: InfluxDB2(report_type=db_config['model'], url=db_config['uri'], org=db_config['org'], bucket_name=db_config['db'], token=db_config['token'], diff --git a/src/powerapi/database/__init__.py b/src/powerapi/database/__init__.py index 3fe2aefd..2403225e 100644 --- a/src/powerapi/database/__init__.py +++ b/src/powerapi/database/__init__.py @@ -31,7 +31,6 @@ from powerapi.database.csvdb import CsvBadCommonKeysError, HeaderAreNotTheSameError from powerapi.database.mongodb import MongoDB, MongoBadDBError from powerapi.database.opentsdb import OpenTSDB, CantConnectToOpenTSDBException -from powerapi.database.influxdb import InfluxDB, CantConnectToInfluxDBException from powerapi.database.influxdb2 import InfluxDB2 from powerapi.database.prometheus_db import PrometheusDB from powerapi.database.virtiofs_db import VirtioFSDB diff --git a/src/powerapi/database/influxdb.py b/src/powerapi/database/influxdb.py deleted file mode 100644 index def94808..00000000 --- a/src/powerapi/database/influxdb.py +++ /dev/null @@ -1,128 +0,0 @@ -# Copyright (c) 2021, INRIA -# Copyright (c) 2021, University of Lille -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import logging -from typing import List, Type -try: - from influxdb import InfluxDBClient - from requests.exceptions import ConnectionError as InfluxConnectionError -except ImportError: - logging.getLogger().info("influx-client is not installed.") - -from powerapi.report import Report -from .base_db import BaseDB, DBError - - -class CantConnectToInfluxDBException(DBError): - """ - Exception raised to notify that connection to the influx database is impossible - """ - - -class InfluxDB(BaseDB): - """ - MongoDB class herited from BaseDB - - Allow to handle a InfluxDB database in reading or writing. - """ - - def __init__(self, report_type: Type[Report], uri: str, port, db_name: str, tags: List[str]): - """ - :param url: URL of the InfluxDB server - :param port: port of the InfluxDB server - - :param db_name: database name in the influxdb - (ex: "powerapi") - - :param report_type: Type of the report handled by this database - :param tags: metadata used to tag metric - - """ - BaseDB.__init__(self, report_type) - self.uri = uri - self.port = port - self.db_name = db_name - self.tags = tags - - self.client = None - - def __iter__(self): - raise NotImplementedError() - - def _ping_client(self): - if hasattr(self.client, 'ping'): - self.client.ping() - else: - self.client.request(url="ping", method='GET', expected_response_code=204) - - def connect(self): - """ - Override from BaseDB. - - Create the connection to the influxdb database with the current - configuration (hostname/port/db_name), then check if the connection has - been created without failure. - - """ - # close connection if reload - if self.client is not None: - self.client.close() - - self.client = InfluxDBClient(host=self.uri, port=self.port, database=self.db_name) - try: - self._ping_client() - except InfluxConnectionError as exn: - raise CantConnectToInfluxDBException('connexion error') from exn - - for db in self.client.get_list_database(): - if db['name'] == self.db_name: - return - - self.client.create_database(self.db_name) - - def save(self, report: Report): - """ - Override from BaseDB - - :param report: Report to save - """ - data = self.report_type.to_influxdb(report, self.tags) - for tag in data['tags']: - data['tags'][tag] = str(data['tags'][tag]) - self.client.write_points([data]) - - def save_many(self, reports: List[Report]): - """ - Save a batch of data - - :param reports: Batch of data. - """ - - data_list = list(map(lambda r: self.report_type.to_influxdb(r, self.tags), reports)) - self.client.write_points(data_list) diff --git a/tests/acceptation/test_simple_architecture.py b/tests/acceptation/test_simple_architecture.py index 5281ea06..2f31f5ce 100644 --- a/tests/acceptation/test_simple_architecture.py +++ b/tests/acceptation/test_simple_architecture.py @@ -58,14 +58,12 @@ from tests.utils.formula.dummy import DummyFormulaActor from tests.utils.acceptation import launch_simple_architecture, BASIC_CONFIG, SOCKET_DEPTH_LEVEL, \ - INFLUX_OUTPUT_CONFIG, CSV_INPUT_OUTPUT_CONFIG + CSV_INPUT_OUTPUT_CONFIG from tests.utils.report.hwpc import extract_rapl_reports_with_2_sockets # noinspection PyUnresolvedReferences from tests.utils.db.mongo import MONGO_URI, MONGO_INPUT_COLLECTION_NAME, MONGO_OUTPUT_COLLECTION_NAME, \ MONGO_DATABASE_NAME, mongo_database # noinspection PyUnresolvedReferences -from tests.utils.db.influx import INFLUX_DBNAME, INFLUX_URI, get_all_reports, influx_database -# noinspection PyUnresolvedReferences from tests.utils.db.csv import ROOT_PATH, OUTPUT_PATH, files from tests.utils.db.socket import ClientThread, ClientThreadDelay @@ -124,40 +122,6 @@ def influxdb_content(): return [] -def check_influx_db(influx_client): - """ - Verify that output DB has the correct information - """ - mongo = pymongo.MongoClient(INFLUX_URI) - c_input = mongo[MONGO_DATABASE_NAME][MONGO_INPUT_COLLECTION_NAME] - c_output = get_all_reports(influx_client, INFLUX_DBNAME) - - assert len(c_output) == c_input.count_documents({}) - - for report in c_input.find(): - influx_client.switch_database(INFLUX_DBNAME) - - query_result = list(influx_client.query( - 'SELECT * FROM "power_consumption" WHERE "time" = \'' + report['timestamp'] + 'Z\'').get_points()) - assert len(query_result) == 1 - - -def test_run_mongo_to_influx(mongo_database, influx_database, shutdown_system): - """ - Check that report are correctly stored into an output influx database. - The input source is a mongo database. - """ - supervisor = Supervisor() - launch_simple_architecture(config=INFLUX_OUTPUT_CONFIG, supervisor=supervisor, hwpc_depth_level=SOCKET_DEPTH_LEVEL, - formula_class=DummyFormulaActor) - - time.sleep(4) - - check_influx_db(influx_database) - - supervisor.kill_actors() - - ############## # CSV to CSV # ############## diff --git a/tests/integration/cli/test_generate_pusher.py b/tests/integration/cli/test_generate_pusher.py deleted file mode 100644 index adbc5b45..00000000 --- a/tests/integration/cli/test_generate_pusher.py +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright (c) 2021, Inria -# Copyright (c) 2021, University of Lille -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import time -import pytest - -from powerapi.message import StartMessage, PoisonPillMessage -from powerapi.report import PowerReport -from powerapi.cli.generator import PusherGenerator -from powerapi.utils import timestamp_to_datetime -# noinspection PyUnresolvedReferences -from tests.utils.db.influx import INFLUX_URI, INFLUX_PORT, INFLUX_DBNAME, influx_database - -SENSOR_NAME = 'sensor_test' -TARGET_NAME = 'system' -REPORTS_TO_SEND = 51 - - -@pytest.fixture -def power_report(): - return PowerReport(timestamp_to_datetime(1), SENSOR_NAME, TARGET_NAME, 0.11, - {'socket': 1, 'metadata1': 'azerty', 'metadata2': 'qwerty'}) - - -@pytest.fixture -def influxdb_content(): - return [] - - -def test_generate_pusher_with_socket_tags_and_send_it_a_powerReport_must_store_PowerReport_with_right_tag( - influx_database, power_report, shutdown_system): - """ - Create a PusherGenerator that generate pusher with a PowerReportModel that keep formula_name metadata in PowerReport - Generate a pusher connected to an influxDB - send a powerReport with formula_name metadata to the pusher - test if stored data have tag with formula_name - """ - - config = {'verbose': True, - 'stream': False, - 'output': {'test_pusher': {'type': 'influxdb', - 'tags': 'socket', - 'model': 'PowerReport', - 'name': 'test_pusher', - 'uri': INFLUX_URI, - 'port': INFLUX_PORT, - 'db': INFLUX_DBNAME}} - } - - generator = PusherGenerator() - generator.remove_report_class('PowerReport') - generator.add_report_class('PowerReport', PowerReport) - - actors = generator.generate(config) - pusher = actors['test_pusher'] - - pusher.start() - pusher.connect_control() - pusher.connect_data() - pusher.send_control(StartMessage(TARGET_NAME)) - _ = pusher.receive_control(2000) - - messages_sent = 0 - while messages_sent < REPORTS_TO_SEND: - pusher.send_data(power_report) - messages_sent += 1 - power_report.timestamp = timestamp_to_datetime(messages_sent + 1) - - time.sleep(0.3) - pusher.send_control(PoisonPillMessage(sender_name='system-test-generate-pusher')) - - influx_database.switch_database(INFLUX_DBNAME) - reports = list(influx_database.query('SELECT * FROM "power_consumption"').get_points(tags={'socket': '1'})) - assert len(reports) == 51 diff --git a/tests/integration/database/test_influxdb.py b/tests/integration/database/test_influxdb.py deleted file mode 100644 index ea23f023..00000000 --- a/tests/integration/database/test_influxdb.py +++ /dev/null @@ -1,202 +0,0 @@ -# Copyright (c) 2021, Inria -# Copyright (c) 2021, University of Lille -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import datetime -import pytest - -from powerapi.database import InfluxDB, CantConnectToInfluxDBException -from powerapi.report import PowerReport -# noinspection PyUnresolvedReferences -from tests.utils.db.influx import influx_database, get_all_reports, INFLUX_DBNAME, INFLUX_URI, INFLUX_PORT -from tests.utils.report.power import SENSOR_NAME, TARGET_NAME, gen_json_power_report - -POWER_REPORT_0 = PowerReport(datetime.datetime.fromtimestamp(0), SENSOR_NAME, - TARGET_NAME, 100, {'socket': 0}) -POWER_REPORT_1 = PowerReport(datetime.datetime.fromtimestamp(1), SENSOR_NAME, - TARGET_NAME, 100, {'socket': 0}) -POWER_REPORT_2 = PowerReport(datetime.datetime.fromtimestamp(2), SENSOR_NAME, - TARGET_NAME, 100, {'socket': 0}) - - -def define_influxdb_content(content): - def wrap(func): - setattr(func, '_influxdb_content', content) - return func - - return wrap - - -def pytest_generate_tests(metafunc): - """ - Function called by pytest when collecting a test_XXX function - - define the influxdb_content fixtures in test environement with collected the - value _influxdb_content if it exist or with an empty list - - :param metafunc: the test context given by pytest - """ - if 'influxdb_content' in metafunc.fixturenames: - content = getattr(metafunc.function, '_influxdb_content', None) - if isinstance(content, list): - metafunc.parametrize('influxdb_content', [content]) - else: - metafunc.parametrize('influxdb_content', [[]]) - - -@pytest.fixture() -def database(): - db = InfluxDB(PowerReport, INFLUX_URI, INFLUX_PORT, INFLUX_DBNAME, ['socket']) - yield db - db.client.close() - - -#################### -# CONNECTION TESTS # -#################### -def test_correct_connection(influx_database, database): - """ - Connect the InfluxDB instance to an influxdb database - - Test if no exception was raised - """ - database.connect() - assert True - - -def test_invalid_uri_connection(): - """ - Try to connect the InfluxDB instance to an influxdb database with an invalid - uri - - Test if an CantConnectToInfluxDBException is raise - """ - db = InfluxDB(PowerReport, 'tqldjslqskjd', INFLUX_PORT, INFLUX_DBNAME, ['socket']) - with pytest.raises(CantConnectToInfluxDBException): - db.connect() - - -def test_invalid_port_connection(): - """ - Try to connect the InfluxDB instance to an influxdb database with an invalid - port - - Test if an CantConnectToInfluxDBException is raise - """ - db = InfluxDB(PowerReport, INFLUX_URI, 1234, INFLUX_DBNAME, ['socket']) - - with pytest.raises(CantConnectToInfluxDBException): - db.connect() - - -def test_database_initialisation(influx_database, database): - """ - Connect an InfluxDB instance to an empty influxdb database - - test if the database specified to the InfluxDB instance was created - """ - database.connect() - - assert_result = False - - for db in influx_database.get_list_database(): - if db['name'] == INFLUX_DBNAME: - assert_result = True - assert assert_result - - -########################### -# REPORT WRITING EMPTY DB # -########################### -def check_db_reports(client, input_reports): - output_reports = get_all_reports(client, INFLUX_DBNAME) - - assert len(output_reports) == len(input_reports) - - output_reports.sort(key=lambda r: r['time']) - input_reports.sort(key=lambda r: r.timestamp) - - for input_r, output_r in zip(input_reports, output_reports): - assert input_r.sensor == output_r['sensor'] - assert input_r.target == output_r['target'] - assert input_r.timestamp == datetime.datetime.strptime(output_r['time'], '%Y-%m-%dT%H:%M:%SZ') - assert input_r.power == output_r['power'] - - -def test_write_one_report_in_empty_db(influx_database, database): - """ - call the save method with One PowerReport - - test if the report was writen in the database - """ - database.connect() - database.save(POWER_REPORT_1) - - check_db_reports(influx_database, [POWER_REPORT_1]) - - -def test_write_many_report_in_empty_db(influx_database, database): - """ - call the save_many method with One PowerReport - - test if the report was writen in the database - """ - database.connect() - database.save_many([POWER_REPORT_1, POWER_REPORT_2]) - - check_db_reports(influx_database, [POWER_REPORT_1, POWER_REPORT_2]) - - -############################### -# REPORT WRITING NON EMPTY DB # -############################### -@define_influxdb_content(gen_json_power_report(1)) -def test_write_one_report_in_non_empty_db(influx_database, database): - """ - call the save method with One PowerReport - - test if the report was writen in the database - """ - database.connect() - database.save(POWER_REPORT_0) - database.save(POWER_REPORT_1) - check_db_reports(influx_database, [POWER_REPORT_0, POWER_REPORT_1]) - - -@define_influxdb_content(gen_json_power_report(1)) -def test_write_many_report_in_non_empty_db(influx_database, database): - """ - call the save_many method with One PowerReport - - test if the report was writen in the database - """ - database.connect() - database.save(POWER_REPORT_0) - database.save_many([POWER_REPORT_1, POWER_REPORT_2]) - - check_db_reports(influx_database, [POWER_REPORT_0, POWER_REPORT_1, POWER_REPORT_2]) diff --git a/tests/integration/database/test_influxdb2.py b/tests/integration/database/test_influxdb2.py index 1814f12f..fd3c4b60 100644 --- a/tests/integration/database/test_influxdb2.py +++ b/tests/integration/database/test_influxdb2.py @@ -34,7 +34,7 @@ from powerapi.report import PowerReport # noinspection PyUnresolvedReferences from tests.utils.db.influx2 import INFLUX2_ORG, INFLUX2_TOKEN, INFLUX2_URL, INFLUX2_BUCKET_NAME, \ - influx_database, get_all_the_reports, INFLUX2_MEASUREMENT_NAME, INFLUX2_DEFAULT_START_DATE, INFLUX2_PORT, \ + influx2_database, get_all_the_reports, INFLUX2_MEASUREMENT_NAME, INFLUX2_DEFAULT_START_DATE, INFLUX2_PORT, \ INFLUX2_URL_WITHOUT_PORT from tests.utils.report.power import SENSOR_NAME, TARGET_NAME @@ -159,7 +159,7 @@ def check_db_reports(client: InfluxDB2, input_reports): assert output_r['_value'] == input_r.power -def test_write_one_report_in_empty_db(influx_database, database): +def test_write_one_report_in_empty_db(influx2_database, database): """ call the save method with One PowerReport @@ -171,7 +171,7 @@ def test_write_one_report_in_empty_db(influx_database, database): check_db_reports(database, [POWER_REPORT_1]) -def test_write_many_report_in_empty_db(influx_database, database): +def test_write_many_report_in_empty_db(influx2_database, database): """ call the save_many method with One PowerReport @@ -187,7 +187,7 @@ def test_write_many_report_in_empty_db(influx_database, database): # # REPORT WRITING NON EMPTY DB # # ############################### -def test_write_one_report_in_non_empty_db(influx_database, database): +def test_write_one_report_in_non_empty_db(influx2_database, database): """ call the save method with One PowerReport @@ -199,7 +199,7 @@ def test_write_one_report_in_non_empty_db(influx_database, database): check_db_reports(database, [POWER_REPORT_0, POWER_REPORT_1]) -def test_write_many_report_in_non_empty_db(influx_database, database): +def test_write_many_report_in_non_empty_db(influx2_database, database): """ call the save_many method with One PowerReport diff --git a/tests/unit/cli/test_generator.py b/tests/unit/cli/test_generator.py index c1867366..c02eb198 100644 --- a/tests/unit/cli/test_generator.py +++ b/tests/unit/cli/test_generator.py @@ -41,7 +41,7 @@ from powerapi.processor.pre.libvirt.libvirt_pre_processor_actor import LibvirtPreProcessorActor from powerapi.puller import PullerActor from powerapi.pusher import PusherActor -from powerapi.database import MongoDB, CsvDB, SocketDB, InfluxDB, PrometheusDB, InfluxDB2 +from powerapi.database import MongoDB, CsvDB, SocketDB, PrometheusDB, InfluxDB2 from powerapi.exception import PowerAPIException @@ -262,12 +262,6 @@ def test_generate_several_pushers_from_config(several_inputs_outputs_stream_conf assert db.db_name == current_pusher_infos['db'] assert db.collection_name == current_pusher_infos['collection'] - elif pusher_type == 'influxdb': - assert isinstance(db, InfluxDB) - assert db.uri == current_pusher_infos['uri'] - assert db.db_name == current_pusher_infos['db'] - assert db.port == current_pusher_infos['port'] - elif pusher_type == 'prometheus': assert isinstance(db, PrometheusDB) assert db.address == current_pusher_infos['uri'] @@ -314,17 +308,6 @@ def test_generate_pusher_raise_exception_when_missing_arguments_in_mongo_output( generator.generate(several_inputs_outputs_stream_mongo_without_some_arguments_config) -def test_generate_pusher_raise_exception_when_missing_arguments_in_influx_output( - several_inputs_outputs_stream_influx_without_some_arguments_config): - """ - Test that PusherGenerator raises a PowerAPIException when some arguments are missing for influx output - """ - generator = PusherGenerator() - - with pytest.raises(PowerAPIException): - generator.generate(several_inputs_outputs_stream_influx_without_some_arguments_config) - - def test_generate_pusher_raise_exception_when_missing_arguments_in_prometheus_output( several_inputs_outputs_stream_prometheus_without_some_arguments_config): """ diff --git a/tests/utils/acceptation.py b/tests/utils/acceptation.py index 5155fef6..2521fc97 100644 --- a/tests/utils/acceptation.py +++ b/tests/utils/acceptation.py @@ -42,7 +42,6 @@ from powerapi.filter import Filter from powerapi.report import HWPCReport from tests.utils.db.csv import OUTPUT_PATH, FILES -from tests.utils.db.influx import INFLUX_URI, INFLUX_PORT, INFLUX_DBNAME from tests.utils.db.mongo import MONGO_URI, MONGO_DATABASE_NAME, MONGO_OUTPUT_COLLECTION_NAME, \ MONGO_INPUT_COLLECTION_NAME from tests.utils.libvirt import REGEXP @@ -74,22 +73,6 @@ def filter_rule(_): 'collection': MONGO_INPUT_COLLECTION_NAME}} } -INFLUX_OUTPUT_CONFIG = {'verbose': True, - 'stream': False, - 'output': {'test_pusher': {'type': 'influxdb', - 'tags': 'socket', - 'model': 'PowerReport', - 'max_buffer_size': 0, - 'uri': INFLUX_URI, - 'port': INFLUX_PORT, - 'db': INFLUX_DBNAME}}, - 'input': {'test_puller': {'type': 'mongodb', - 'model': 'HWPCReport', - 'uri': MONGO_URI, - 'db': MONGO_DATABASE_NAME, - 'collection': MONGO_INPUT_COLLECTION_NAME}} - } - CSV_INPUT_OUTPUT_CONFIG = {'verbose': True, 'stream': False, 'output': {'test_pusher': {'type': 'csv', diff --git a/tests/utils/cli/several_inputs_outputs_stream_mode_enabled_configuration.json b/tests/utils/cli/several_inputs_outputs_stream_mode_enabled_configuration.json index ae596c0a..d79f7de6 100644 --- a/tests/utils/cli/several_inputs_outputs_stream_mode_enabled_configuration.json +++ b/tests/utils/cli/several_inputs_outputs_stream_mode_enabled_configuration.json @@ -31,13 +31,6 @@ "db": "my_db_result", "collection": "my_collection_result" }, - "second_pusher": { - "type": "influxdb", - "model": "PowerReport", - "uri": "127.0.0.1", - "port": 1111, - "db": "my_db_result_2" - }, "third_pusher": { "type": "prometheus", "model": "PowerReport", diff --git a/tests/utils/db/influx.py b/tests/utils/db/influx.py deleted file mode 100644 index eee4293a..00000000 --- a/tests/utils/db/influx.py +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2021, INRIA -# Copyright (c) 2021, University of Lille -# All rights reserved. - -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: - -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. - -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. - -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. - -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import pytest - -from influxdb import InfluxDBClient - - -INFLUX_URI = '127.0.0.1' -INFLUX_PORT = 8086 -INFLUX_DBNAME = 'acceptation_test' - - -@pytest.fixture() -def influx_database(influxdb_content): - """ - connect to a local influx database (localhost:8086) and store data contained in the list influxdb_content - after test end, delete the data - """ - client = InfluxDBClient(host=INFLUX_URI, port=INFLUX_PORT) - _delete_db(client, INFLUX_DBNAME) - _init_db(client, influxdb_content) - yield client - _delete_db(client, INFLUX_DBNAME) - - -def _init_db(client, content): - - if content != []: - client.create_database(INFLUX_DBNAME) - client.switch_database(INFLUX_DBNAME) - client.write_points(content) - - -def _delete_db(client, db_name): - client.drop_database(db_name) - client.close() - - -def get_all_reports(client, db_name): - """ - get all points stored in the database during test execution - """ - client.switch_database(db_name) - result = client.query('SELECT * FROM "power_consumption"') - return list(result.get_points()) diff --git a/tests/utils/db/influx2.py b/tests/utils/db/influx2.py index cda03398..d3dd5ed2 100644 --- a/tests/utils/db/influx2.py +++ b/tests/utils/db/influx2.py @@ -64,7 +64,7 @@ @pytest.fixture() -def influx_database(): +def influx2_database(): """ connect to a local influx database (localhost:8086) and store data contained in the list influxdb_content after test end, delete the data From 43fec0be0340f6c4f1272173fc0c818b258bdd6f Mon Sep 17 00:00:00 2001 From: Guillaume Fieni Date: Fri, 12 Jan 2024 11:30:56 +0100 Subject: [PATCH 2/2] build(pyproject): Remove unmaintained influxdb client dependency --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6724c813..a423aaf1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ lint = [ # Databases: mongodb = ["pymongo >= 3.7.2"] -influxdb = ["influxdb-client >= 1.30.0", "influxdb >= 2.12"] +influxdb = ["influxdb-client >= 1.30.0"] opentsdb = ["opentsdb-py >= 0.6.0"] prometheus = ["prometheus-client >= 0.9.0"]