A metric registered with learn_normal() gets, for every resource reporting it, a usual hold (the 90th percentile across past days of each hour's p95) and a usual peak for each slot: - an hour of the day once 5 days of history exist; - an hour of the week once history reaches back 3 weeks, so weekly jobs are learned too. Each slot takes in the hours either side, so a job that runs a little late stays normal. One SQL statement relearns everything hourly into metric_norms, from the rollup plus the raw window not rolled up yet; norms_at() reads the slot a moment falls in. Nothing is registered yet: Traefik (#5741) and hosts (#5742) opt in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
"""What each learned metric usually does in each time slot (#5739).
|
|
|
|
Revision ID: 0045_metric_norms
|
|
Revises: 0044_hourly_p95
|
|
Create Date: 2026-10-14
|
|
"""
|
|
from typing import Sequence, Union
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision: str = "0045_metric_norms"
|
|
down_revision: Union[str, None] = "0044_hourly_p95"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"metric_norms",
|
|
sa.Column("source_module", sa.String(64), primary_key=True),
|
|
sa.Column("resource_name", sa.String(255), primary_key=True),
|
|
sa.Column("metric_name", sa.String(128), primary_key=True),
|
|
sa.Column("slot", sa.SmallInteger, primary_key=True),
|
|
sa.Column("kind", sa.String(8), nullable=False),
|
|
sa.Column("usual_hold", sa.Float, nullable=False),
|
|
sa.Column("usual_peak", sa.Float, nullable=False),
|
|
sa.Column("days_seen", sa.Integer, nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("metric_norms")
|