def measurement() -> servo.Measurement: return servo.Measurement(readings=[ servo.DataPoint( value=31337, time=datetime.datetime.now(), metric=servo.Metric( name="Some Metric", unit=servo.Unit.requests_per_minute, ), ) ])
async def test_state_machine_lifecyle(measurement: servo.Measurement) -> None: static_optimizer = tests.fake.StaticOptimizer( id="dev.opsani.com/big-in-japan", token="31337") await static_optimizer.say_hello() await static_optimizer.request_description() await static_optimizer.submit_description(_random_description()) metric = servo.Metric( name="Some Metric", unit=servo.Unit.requests_per_minute, ) await static_optimizer.request_measurement(metrics=[metric], control=servo.Control()) await static_optimizer.submit_measurement(measurement) adjustment = servo.Adjustment(component_name="web", setting_name="cpu", value=1.25) await static_optimizer.recommend_adjustments([adjustment]) await static_optimizer.complete_adjustments(_random_description()) await static_optimizer.say_goodbye()
def test_name_to_metric(): assert _name_to_metric("tuning_cpu_usage") == servo.Metric( name="tuning_cpu_usage", unit=servo.Unit.float)
elif ev.event == servo.api.Events.adjust: return await api.optimizer.complete_adjustments(ev.param) else: raise ValueError(f"unknown event: {ev.event}") @pytest.fixture def fastapi_app() -> fastapi.FastAPI: return api ## # Utilities METRICS = [ servo.Metric("throughput", servo.Unit.requests_per_minute), servo.Metric("error_rate", servo.Unit.percentage), ] COMPONENTS = [ servo.Component( "fake-app", settings=[ servo.CPU(min=1, max=5), servo.Memory(min=0.25, max=8.0, step=0.125), servo.Replicas(min=1, max=10), ], ) ]
import datetime import enum import io import json import pathlib import re from typing import Any, Dict, List, Optional, Tuple, Union import devtools import jsonschema import pydantic import servo METRICS = [ servo.Metric("throughput", servo.Unit.requests_per_minute), servo.Metric("error_rate", servo.Unit.percentage), servo.Metric("latency_total", servo.Unit.milliseconds), servo.Metric("latency_mean", servo.Unit.milliseconds), servo.Metric("latency_50th", servo.Unit.milliseconds), servo.Metric("latency_90th", servo.Unit.milliseconds), servo.Metric("latency_95th", servo.Unit.milliseconds), servo.Metric("latency_99th", servo.Unit.milliseconds), servo.Metric("latency_max", servo.Unit.milliseconds), servo.Metric("latency_min", servo.Unit.milliseconds), ] class TargetFormat(str, enum.Enum): http = "http" json = "json"