Skip to main content

openshift-python-scale-utilities

Pypi: openshift-python-scale-utilities

Utilities to assist in scaling openshift-python-wrapper resources

ocp_scale_utilities.threaded

Utilizes ThreadPoolExecutor to operate on many resources in parallel across multiple threads.

Usage

from ocp_resources.virtual_machine import VirtualMachine
from ocp_scale_utilities.threaded.utils import (
    threaded_deploy_resources,
    threaded_delete_resources,
    threaded_wait_deleted_resources,
)
from ocp_scale_utilities.threaded.scale import ThreadedScaleResources

# Create iterable of VirtualMachine python objects to deploy
# Be sure to use deepcopy() when passing dicts to objects to avoid collisions
vms = [VirtualMachine(..., body=deepcopy(body))]

# Option A:

def funcA():
    threaded_deploy_resources(resources=vms)
    yield vms
    threaded_delete_resources(resources=vms)
    threaded_wait_deleted_resources(resources=vms)

# Option B:

def funcB():
    with ThreadedScaleResources(resources=vms, wait_for_status=VirtualMachine.Status.RUNNING):
        yield vms

ocp_scale_utilities.monitoring

MonitorResourceAPIServerRequests provides a way to monitor a specific resource to determine if it is being actively used.
This allows the ability to wait for resources to settle after a major scale action, improving reliability, and increasing readability in prometheus data.

Usage

from ocp_resources.virtual_machine import VirtualMachine
from ocp_scale_utilities.monitoring import MonitorResourceAPIServerRequests
from ocp_scale_utilities.threaded.scale import ThreadedScaleResources
from ocp_utilities.monitoring import Prometheus

monitor_api_requests = MonitorResourceAPIServerRequests(
    prometheus=Prometheus(...),
    resource_class=VirtualMachine,
    idle_requests_value=float(...),  # Based on apiserver_request_total metric
)

monitor_api_requests.wait_for_idle()
with ThreadedScaleResources(resources=vms):
    monitor_api_requests.wait_for_idle()
    yield vms
monitor_api_requests.wait_for_idle()

ocp_scale_utilities.logger

Logging at scale requires utilizing logging.QueueHandlers to avoid logging to closed streams.

 root QueueHandler ┐                         ┌> StreamHandler
                   ├> Queue -> QueueListener ┤
basic QueueHandler ┘                         └> FileHandler

Usage

main.py

import logging
from ocp_scale_utilities.logger import setup_logging

from module import func

LOGGER = None

def main():
    LOGGER.warning("main logged warning message")
    func()

if __name__ == "__main__":
    log_listener = setup_logging(log_level=logging.WARNING, log_file="/tmp/example.log")
    LOGGER = logging.getLogger(__name__)
    main()
    log_listener.stop()

module.py

import logging
LOGGER = logging.getLogger(__name__)

def func():
    LOGGER.warning("func logged warning message")

Contributing

Please use pre-commit to check the code before commiting

pre-commit install

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openshift_python_scale_utilities-0.1.1.6.tar.gz (143.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file openshift_python_scale_utilities-0.1.1.6.tar.gz.

File metadata

File hashes

Hashes for openshift_python_scale_utilities-0.1.1.6.tar.gz
Algorithm Hash digest
SHA256 f87169cd29c19f0fb39b11043b527e93e1cc203d62ff0e537f061745dd532653
MD5 88ea92894724faeba82ec5380ca51ee8
BLAKE2b-256 12999c46346d089c75e4c019440f1a5c6bfdee7455f4f4b5888779cdb83754df

See more details on using hashes here.

File details

Details for the file openshift_python_scale_utilities-0.1.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for openshift_python_scale_utilities-0.1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a1809d57a652aa707928f8b5069e23d20a2040cfda99ed4a2b8de28615eafb94
MD5 10b647fe9d7b8774060e31437e89601b
BLAKE2b-256 e847e03c0ccbcbce6f024b5679ccd20cdf453213ec0d3b476017fea750646450

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page