Skip to content
Draft
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
220 changes: 220 additions & 0 deletions OpenStack-Rally-Tester/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
*.lcov
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/

# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi/*
!.pixi/config.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule*
celerybeat.pid

# Redis
*.rdb
*.aof
*.pid

# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/

# ActiveMQ
activemq-data/

# SageMath parsed files
*.sage.py

# Environments
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/

# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Temporary file for partial code execution
tempCodeRunnerFile.py

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/

# Streamlit
.streamlit/secrets.toml
25 changes: 25 additions & 0 deletions OpenStack-Rally-Tester/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Rally Tester Script

This script scrapes outputted task reports of rally metrics and feeds them to influxdb

## Prerequisites
- An InfluxDB server running HTTPs (using self-signed certs)
- A Rally VM that is generating reports - that we will deploy this script onto

## Installation

setup a python3 virtual environment
```commandline
dnf install python3.12
python3.12 -m venv opt/extract-rally-venv
```

## Developer Notes - WIP

several bash scripts exist in aquilon that would be better served to be moved here
as those bash scripts reference this python script. Changing the python script here,
will require changing the bash scripts - it would be much easier if they were all managed from a central source

if placed here, we can run CI/CD jobs against them

TODO: tests
7 changes: 7 additions & 0 deletions OpenStack-Rally-Tester/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "openstack-rally-tester"
version = "1.0.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = ["influxdb"]
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[auth]
password=
username=

[cloud]
instance=

[db]
database=
host=
port=
101 changes: 101 additions & 0 deletions OpenStack-Rally-Tester/rally_extract_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import sys
from typing import Union, Dict, List
from influxdb import InfluxDBClient
from influxdb.exceptions import InfluxDBClientError, InfluxDBServerError

from utils import load_data, load_config, create_metric, add_tags, is_workhour

TIMEOUT = 30 # how long to wait to connect to influxdb before timing out (in seconds)


def create_metrics(data: Union[Dict, List[Dict]]) -> List[Dict]:
"""Convert rally data into a list of metrics."""

# if only one rally metric is found
if isinstance(data, dict):
return [
create_metric(
measurement=key,
fields={"success": 0},
)
for key in data
]

# if a list of rally metrics are found
metrics = []
for test in data:
measurement = test["key"]["name"]

for result in test["result"]:
fields = {
"success": int(all(sla["success"] for sla in test["sla"])),
"duration": result["duration"],
**result["atomic_actions"],
"timestamp": result["timestamp"],
}

if measurement == "VMTasks.boot_runcommand_delete":
fields.update({
"image": f'"{test["key"]["kw"]["args"]["image"]["name"]}"',
"network": f'"{test["key"]["kw"]["args"]["fixednetwork"]}"',
})

metrics.append(
create_metric(
measurement=measurement,
fields=fields,
)
)
return metrics


def metrics_to_string(metrics: Dict) -> str:
"""Convert metrics to the required output format."""
lines = []

for metric in metrics:
measurement = metric["measurement"].replace(".", "-")
instance = metric["tags"]["instance"]

for field, value in metric["fields"].items():
field = field.replace(".", "-")

lines.append(
f"{measurement},"
f"instance={instance},"
f"workhours={is_workhour()} "
f"{field}={value}"
)

return "\n".join(lines) + "\n"


def main():
config = load_config("config.ini")

influx_client = InfluxDBClient(
host=config["host"],
port=config["port"],
username=config["username"],
password=config["password"],
database=config["database"],
ssl=True,
verify_ssl=False,
timeout=TIMEOUT,
)

data = load_data(sys.argv[1])

metrics = create_metrics(data)
metrics = add_tags(metrics, config["instance"])

data_string = metrics_to_string(metrics)
lines = [line for line in data_string.splitlines() if line.strip()]

if not lines:
return

try:
influx_client.write_points(data_string)
except (InfluxDBClientError, InfluxDBServerError) as exc:
raise RuntimeError(f"Failed to write to InfluxDB: {exc}") from exc
1 change: 0 additions & 1 deletion OpenStack-Rally-Tester/requirements.txt

This file was deleted.

Empty file.
Loading
Loading