From 87601b0bf722a613342fab8a56d4b37b75ebee19 Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Thu, 4 May 2023 15:48:09 +0000 Subject: [PATCH 1/2] Tools - Perf Plots: - Added initial version of tool used to extract data from Prometheus and automatically generate histogram plots. --- .../tools/perf_plots/Component_RPC_Methods.py | 123 ++++++++++++++++++ .../tools/perf_plots/Device_Driver_Details.py | 101 ++++++++++++++ .../tools/perf_plots/Device_Driver_Methods.py | 99 ++++++++++++++ src/tests/tools/perf_plots/README.md | 29 +++++ .../perf_plots/Service_Handler_Methods.py | 99 ++++++++++++++ src/tests/tools/perf_plots/__init__.py | 14 ++ .../tools/perf_plots/tools/FileSystem.py | 27 ++++ src/tests/tools/perf_plots/tools/Histogram.py | 88 +++++++++++++ .../tools/perf_plots/tools/HistogramData.py | 22 ++++ src/tests/tools/perf_plots/tools/Plotter.py | 59 +++++++++ .../tools/perf_plots/tools/Prometheus.py | 59 +++++++++ src/tests/tools/perf_plots/tools/__init__.py | 14 ++ 12 files changed, 734 insertions(+) create mode 100644 src/tests/tools/perf_plots/Component_RPC_Methods.py create mode 100644 src/tests/tools/perf_plots/Device_Driver_Details.py create mode 100644 src/tests/tools/perf_plots/Device_Driver_Methods.py create mode 100644 src/tests/tools/perf_plots/README.md create mode 100644 src/tests/tools/perf_plots/Service_Handler_Methods.py create mode 100644 src/tests/tools/perf_plots/__init__.py create mode 100644 src/tests/tools/perf_plots/tools/FileSystem.py create mode 100644 src/tests/tools/perf_plots/tools/Histogram.py create mode 100644 src/tests/tools/perf_plots/tools/HistogramData.py create mode 100644 src/tests/tools/perf_plots/tools/Plotter.py create mode 100644 src/tests/tools/perf_plots/tools/Prometheus.py create mode 100644 src/tests/tools/perf_plots/tools/__init__.py diff --git a/src/tests/tools/perf_plots/Component_RPC_Methods.py b/src/tests/tools/perf_plots/Component_RPC_Methods.py new file mode 100644 index 000000000..7aa3ed304 --- /dev/null +++ b/src/tests/tools/perf_plots/Component_RPC_Methods.py @@ -0,0 +1,123 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed 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. + +import datetime, re +from typing import Dict, List, Optional, Tuple +from .tools.FileSystem import create_folders +from .tools.HistogramData import HistogramData +from .tools.Plotter import plot_histogram +from .tools.Prometheus import get_prometheus_range, get_prometheus_series_names +from .tools.Histogram import results_to_histograms, save_histograms, unaccumulate_histograms + +##### EXPERIMENT SETTINGS ############################################################################################## + +EXPERIMENT_NAME = 'L2VPN with Emulated' +EXPERIMENT_ID = 'l2vpn-emu' +TIME_START = datetime.datetime(2023, 5, 4, 6, 45, 0, 0, tzinfo=datetime.timezone.utc) +TIME_END = datetime.datetime(2023, 5, 4, 10, 15, 0, 0, tzinfo=datetime.timezone.utc) +TIME_STEP = '1m' +LABEL_FILTERS = {} + +##### ENVIRONMENT SETTINGS ############################################################################################# + +PROM_ADDRESS = '127.0.0.1' +PROM_PORT = 9090 +OUT_FOLDER = 'data/perf/' + +##### PLOT-SPECIFIC CUSTOMIZATIONS ##################################################################################### + +EXPERIMENT_ID += '/component-rpcs' +SERIES_MATCH = 'tfs_.+_rpc_.+_histogram_duration_bucket' +RE_SERIES_NAME = re.compile(r'^tfs_(.+)_rpc_(.+)_histogram_duration_bucket$') +SERIES_LABELS = [] + +SUBSYSTEMS_MAPPING = { + 'context': { + 'context' : 'context', + 'topolog' : 'topology', + 'device' : 'device', + 'endpoint' : 'device', + 'link' : 'link', + 'service' : 'service', + 'slice' : 'slice', + 'policyrule': 'policyrule', + 'connection': 'connection', + } +} + +def get_subsystem(component : str, rpc_method : str) -> Optional[str]: + return next(iter([ + subsystem + for pattern,subsystem in SUBSYSTEMS_MAPPING.get(component, {}).items() + if pattern in rpc_method + ]), None) + +def update_keys(component : str, rpc_method : str) -> Tuple[Tuple, Tuple]: + subsystem = get_subsystem(component, rpc_method) + collection_keys = (component, subsystem) + histogram_keys = (rpc_method,) + return collection_keys, histogram_keys + +def get_plot_specs(folders : Dict[str, str], component : str, subsystem : Optional[str]) -> Tuple[str, str]: + if subsystem is None: + title = '{:s} - RPC Methods [{:s}]'.format(component.title(), EXPERIMENT_NAME) + filepath = '{:s}/{:s}.png'.format(folders['png'], component) + else: + title = '{:s} - RPC Methods - {:s} [{:s}]'.format(component.title(), subsystem.title(), EXPERIMENT_NAME) + filepath = '{:s}/{:s}-{:s}.png'.format(folders['png'], component, subsystem) + return title, filepath + +##### AUTOMATED CODE ################################################################################################### + +def get_series_names(folders : Dict[str, str]) -> List[str]: + series_names = get_prometheus_series_names( + PROM_ADDRESS, PROM_PORT, SERIES_MATCH, TIME_START, TIME_END, + raw_json_filepath='{:s}/_series.json'.format(folders['json']) + ) + return series_names + +def get_histogram_data(series_name : str, folders : Dict[str, str]) -> Dict[Tuple, HistogramData]: + m = RE_SERIES_NAME.match(series_name) + if m is None: + # pylint: disable=broad-exception-raised + raise Exception('Unparsable series name: {:s}'.format(str(series_name))) + extra_labels = m.groups() + results = get_prometheus_range( + PROM_ADDRESS, PROM_PORT, series_name, LABEL_FILTERS, TIME_START, TIME_END, TIME_STEP, + raw_json_filepath='{:s}/_raw_{:s}.json'.format(folders['json'], series_name) + ) + histograms = results_to_histograms(results, SERIES_LABELS, extra_labels=extra_labels) + unaccumulate_histograms(histograms, process_bins=True, process_timestamps=False) + save_histograms(histograms, folders['csv']) + return histograms + +def main() -> None: + histograms_collection : Dict[Tuple, Dict[Tuple, HistogramData]] = dict() + + folders = create_folders(OUT_FOLDER, EXPERIMENT_ID) + series_names = get_series_names(folders) + + for series_name in series_names: + histograms = get_histogram_data(series_name, folders) + for histogram_keys, histogram_data in histograms.items(): + collection_keys,histogram_keys = update_keys(*histogram_keys) + histograms = histograms_collection.setdefault(collection_keys, dict()) + histograms[histogram_keys] = histogram_data + + for histogram_keys,histograms in histograms_collection.items(): + title, filepath = get_plot_specs(folders, *histogram_keys) + plot_histogram(histograms, filepath, title=title) + +if __name__ == '__main__': + main() diff --git a/src/tests/tools/perf_plots/Device_Driver_Details.py b/src/tests/tools/perf_plots/Device_Driver_Details.py new file mode 100644 index 000000000..24b287cc8 --- /dev/null +++ b/src/tests/tools/perf_plots/Device_Driver_Details.py @@ -0,0 +1,101 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed 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. + +import datetime, re +from typing import Dict, List, Optional, Tuple +from .tools.FileSystem import create_folders +from .tools.HistogramData import HistogramData +from .tools.Plotter import plot_histogram +from .tools.Prometheus import get_prometheus_range, get_prometheus_series_names +from .tools.Histogram import results_to_histograms, save_histograms, unaccumulate_histograms + +##### EXPERIMENT SETTINGS ############################################################################################## + +EXPERIMENT_NAME = 'L2VPN with Emulated' +EXPERIMENT_ID = 'l2vpn-emu' +TIME_START = datetime.datetime(2023, 5, 4, 6, 45, 0, 0, tzinfo=datetime.timezone.utc) +TIME_END = datetime.datetime(2023, 5, 4, 10, 15, 0, 0, tzinfo=datetime.timezone.utc) +TIME_STEP = '1m' +LABEL_FILTERS = { + #'driver': 'emulated', + #'operation': 'configure_device', # add_device / configure_device + #'step': 'get_device', +} + +##### ENVIRONMENT SETTINGS ############################################################################################# + +PROM_ADDRESS = '127.0.0.1' +PROM_PORT = 9090 +OUT_FOLDER = 'data/perf/' + +##### PLOT-SPECIFIC CUSTOMIZATIONS ##################################################################################### + +EXPERIMENT_ID += '/dev-drv-details' +SERIES_MATCH = 'tfs_device_execution_details_histogram_duration_bucket' +RE_SERIES_NAME = re.compile(r'^tfs_device_execution_details_histogram_duration_bucket$') +SERIES_LABELS = ['driver', 'operation', 'step'] + +def update_keys(driver : str, operation : str, step : str) -> Tuple[Tuple, Tuple]: + collection_keys = (driver, operation) + histogram_keys = (step,) + return collection_keys, histogram_keys + +def get_plot_specs(folders : Dict[str, str], driver : str, operation : str) -> Tuple[str, str]: + title = 'Device Driver - {:s} - {:s}'.format(driver.title(), operation.replace('_', '').title()) + filepath = '{:s}/{:s}-{:s}.png'.format(folders['png'], driver, operation) + return title, filepath + +##### AUTOMATED CODE ################################################################################################### + +def get_series_names(folders : Dict[str, str]) -> List[str]: + series_names = get_prometheus_series_names( + PROM_ADDRESS, PROM_PORT, SERIES_MATCH, TIME_START, TIME_END, + raw_json_filepath='{:s}/_series.json'.format(folders['json']) + ) + return series_names + +def get_histogram_data(series_name : str, folders : Dict[str, str]) -> Dict[Tuple, HistogramData]: + m = RE_SERIES_NAME.match(series_name) + if m is None: + # pylint: disable=broad-exception-raised + raise Exception('Unparsable series name: {:s}'.format(str(series_name))) + extra_labels = m.groups() + results = get_prometheus_range( + PROM_ADDRESS, PROM_PORT, series_name, LABEL_FILTERS, TIME_START, TIME_END, TIME_STEP, + raw_json_filepath='{:s}/_raw_{:s}.json'.format(folders['json'], series_name) + ) + histograms = results_to_histograms(results, SERIES_LABELS, extra_labels=extra_labels) + unaccumulate_histograms(histograms, process_bins=True, process_timestamps=False) + save_histograms(histograms, folders['csv']) + return histograms + +def main() -> None: + histograms_collection : Dict[Tuple, Dict[Tuple, HistogramData]] = dict() + + folders = create_folders(OUT_FOLDER, EXPERIMENT_ID) + series_names = get_series_names(folders) + + for series_name in series_names: + histograms = get_histogram_data(series_name, folders) + for histogram_keys, histogram_data in histograms.items(): + collection_keys,histogram_keys = update_keys(*histogram_keys) + histograms = histograms_collection.setdefault(collection_keys, dict()) + histograms[histogram_keys] = histogram_data + + for histogram_keys,histograms in histograms_collection.items(): + title, filepath = get_plot_specs(folders, *histogram_keys) + plot_histogram(histograms, filepath, title=title) + +if __name__ == '__main__': + main() diff --git a/src/tests/tools/perf_plots/Device_Driver_Methods.py b/src/tests/tools/perf_plots/Device_Driver_Methods.py new file mode 100644 index 000000000..a92bd1374 --- /dev/null +++ b/src/tests/tools/perf_plots/Device_Driver_Methods.py @@ -0,0 +1,99 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed 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. + +import datetime, re +from typing import Dict, List, Tuple +from .tools.FileSystem import create_folders +from .tools.HistogramData import HistogramData +from .tools.Plotter import plot_histogram +from .tools.Prometheus import get_prometheus_range, get_prometheus_series_names +from .tools.Histogram import results_to_histograms, save_histograms, unaccumulate_histograms + +##### EXPERIMENT SETTINGS ############################################################################################## + +EXPERIMENT_NAME = 'L2VPN with Emulated' +EXPERIMENT_ID = 'l2vpn-emu' +TIME_START = datetime.datetime(2023, 5, 4, 6, 45, 0, 0, tzinfo=datetime.timezone.utc) +TIME_END = datetime.datetime(2023, 5, 4, 10, 15, 0, 0, tzinfo=datetime.timezone.utc) +TIME_STEP = '1m' +LABEL_FILTERS = { + #'driver': 'emulated', +} + +##### ENVIRONMENT SETTINGS ############################################################################################# + +PROM_ADDRESS = '127.0.0.1' +PROM_PORT = 9090 +OUT_FOLDER = 'data/perf/' + +##### PLOT-SPECIFIC CUSTOMIZATIONS ##################################################################################### + +EXPERIMENT_ID += '/dev-drv-methods' +SERIES_MATCH = 'tfs_device_driver_.+_histogram_duration_bucket' +RE_SERIES_NAME = re.compile(r'^tfs_device_driver_(.+)_histogram_duration_bucket$') +SERIES_LABELS = ['driver'] + +def update_keys(driver : str, method : str) -> Tuple[Tuple, Tuple]: + collection_keys = (driver,) + histogram_keys = (method,) + return collection_keys, histogram_keys + +def get_plot_specs(folders : Dict[str, str], driver : str) -> Tuple[str, str]: + title = 'Device Driver - {:s}'.format(driver.title()) + filepath = '{:s}/{:s}.png'.format(folders['png'], driver) + return title, filepath + +##### AUTOMATED CODE ################################################################################################### + +def get_series_names(folders : Dict[str, str]) -> List[str]: + series_names = get_prometheus_series_names( + PROM_ADDRESS, PROM_PORT, SERIES_MATCH, TIME_START, TIME_END, + raw_json_filepath='{:s}/_series.json'.format(folders['json']) + ) + return series_names + +def get_histogram_data(series_name : str, folders : Dict[str, str]) -> Dict[Tuple, HistogramData]: + m = RE_SERIES_NAME.match(series_name) + if m is None: + # pylint: disable=broad-exception-raised + raise Exception('Unparsable series name: {:s}'.format(str(series_name))) + extra_labels = m.groups() + results = get_prometheus_range( + PROM_ADDRESS, PROM_PORT, series_name, LABEL_FILTERS, TIME_START, TIME_END, TIME_STEP, + raw_json_filepath='{:s}/_raw_{:s}.json'.format(folders['json'], series_name) + ) + histograms = results_to_histograms(results, SERIES_LABELS, extra_labels=extra_labels) + unaccumulate_histograms(histograms, process_bins=True, process_timestamps=False) + save_histograms(histograms, folders['csv']) + return histograms + +def main() -> None: + histograms_collection : Dict[Tuple, Dict[Tuple, HistogramData]] = dict() + + folders = create_folders(OUT_FOLDER, EXPERIMENT_ID) + series_names = get_series_names(folders) + + for series_name in series_names: + histograms = get_histogram_data(series_name, folders) + for histogram_keys, histogram_data in histograms.items(): + collection_keys,histogram_keys = update_keys(*histogram_keys) + histograms = histograms_collection.setdefault(collection_keys, dict()) + histograms[histogram_keys] = histogram_data + + for histogram_keys,histograms in histograms_collection.items(): + title, filepath = get_plot_specs(folders, *histogram_keys) + plot_histogram(histograms, filepath, title=title) + +if __name__ == '__main__': + main() diff --git a/src/tests/tools/perf_plots/README.md b/src/tests/tools/perf_plots/README.md new file mode 100644 index 000000000..14dcb1c95 --- /dev/null +++ b/src/tests/tools/perf_plots/README.md @@ -0,0 +1,29 @@ +# Tool: Perf Plots Generator: + +Simple tool to gather performance data from Prometheus and produce histogram plots. + +## Example: + +- Ensure your MicroK8s includes the monitoring addon and your deployment specs the service monitors. + +- Deploy TeraFlowSDN controller with your specific settings: +```(bash) +cd ~/tfs-ctrl +source my_deploy.sh +./deploy.sh +``` + +- Execute the test you want to meter. + +- Select the appropriate script: + - Device_Driver_Methods : To report Device Driver Methods + - Device_Driver_Details : To report Device Add/Configure Details + - Service_Handler_Methods : To report Service Handler Methods + - Component_RPC_Methods : To report Component RPC Methods + +- Tune the experiment settings + +- Execute the report script: +```(bash) +PYTHONPATH=./src python -m tests.tools.perf_plots.