streamcast-watch
Alerts on rules over streamcast streams. It is a real-time subscriber: it replays a bounded stretch of each stream, follows it live into a bounded in-memory cache, evaluates its rules every 15 seconds, and sends one notice when a rule starts to hold and one when it clears. A rule it cannot evaluate is said to be UNKNOWN, never taken as clear.
pip install streamcast-watch==0.33.0
streamcast-watch alert --rules rules.yaml --broker ws://127.0.0.1:8765 --notifier log
The PyPI project is streamcast-watch, first published with 0.33.0;
install streamcast-watch[aws]==0.33.0 for SNS and CloudWatch. The release image is
ghcr.io/nhobin219/streamcast-watch:0.33.0 (linux/amd64 and linux/arm64), with the
AWS extra installed. It runs tini -- streamcast-watch as 10001:10001:
docker run --rm ghcr.io/nhobin219/streamcast-watch:0.33.0 --help
For deployment, pin the multi-arch manifest digest printed by the release's
Publish versioned multi-architecture watch image → Merge release digests step:
read pushing sha256:… to ghcr.io/nhobin219/streamcast-watch:X.Y.Z for the
index digest, not the copying lines. Cross-check the top-level Digest: from
docker buildx imagetools inspect ghcr.io/nhobin219/streamcast-watch:0.33.0,
and pin ghcr.io/nhobin219/streamcast-watch:0.33.0@sha256:….
See release preparation before the first tag.
Its other half is a publisher: streamcast-watch publish reads, from inside a
Kubernetes pod, whether each workload in a targets file is serving and how often its
containers restarted, and writes that to a metrics stream as OTel metric rows, the
alerter's input like any other service's. They are two processes from one image
(docker/watch.Dockerfile): the publisher needs the Kubernetes API and no cloud, the
alerter needs somewhere to deliver and no Kubernetes API, and a dead publisher is then
just another producer gone quiet, which a stale rule sees.
The stream is the only store. The watch keeps no database and writes nothing to
disk. Its cache is memory only and holds no rows: each rule keeps its own reduction of
the rows it matches (one number for stale; per series, a ring of period buckets of
min, max and last for threshold), bounded in time by the ring and in size by
max_series and max_buckets, and rebuilt from the stream on every start. A cache,
never a second copy.
Absence alerts. A stale rule ages its series from the later of its newest row
and the moment the alerter started. A broker that is down, a follower that cannot
connect, a publisher that stopped, and an alerter restarted with nothing to replay
all read as stale once the rule's period has passed. None of them reads as empty and
fine. The expectation comes from the rules file, not from anything the stream said.
It depends only on streamcast-client (the subscriber, with no storage dependencies)
and PyYAML. The aws extra (streamcast-watch[aws], boto3 1.34.41 or later) is for
the AWS notifier and liveness seams, which live in a module of their own.
Rules
One YAML file. Adding a watched series is a few lines here, and no code, whoever publishes it: a rule may match any metric name, the watch's own or a service's:
rules:
- name: SortieWatchSilent
kind: stale
stream: sortie-metrics
after: 3m
match: {name: watch.heartbeat, service: streamcast-watch-publisher}
says: The watch's publisher has not published for 3 minutes, or the broker is out.
- name: SortieBrokerNotServing
kind: threshold
stream: sortie-metrics
match: {name: watch.target.serving, attributes: {watch.target: sortie-broker}}
reduce: min
below: 1
period: 1m
points: 3
of: 5
- name: SortieBrokerRestarting
kind: threshold
stream: sortie-metrics
match: {name: k8s.container.restart.count, attributes: {watch.target: sortie-broker}}
reduce: increase
above: 0
period: 5m
points: 2
of: 6
Every rule has name (unique), kind, stream, and match. A match takes the metric
name, and optionally the row's service and attributes equalities. A rule may also
have says, the notice's text, and keep_firing_for, 5m by default. A stale rule's
keep_firing_for must be at least its after, so one longer than 5m sets it.
| Kind | Holds when |
|---|---|
stale (after) |
no matching row reached the broker in the last after, counting from the alerter's start until a row does. Until a row taken after the start arrives, its OK does not run a FIRING rule's clear timer (below) |
threshold (reduce, below or above, period, points, of) |
at least points of of period-long buckets breach. Buckets are aligned to period by when the value was observed (time_unix_nano), and each reduces to one number by min, max or increase. increase is per series and summed: the bucket's last value minus the series' last value in its newest earlier bucket (going back at most one bucket before the window), a fall counting as 0. A recreated pod is a new series by its k8s.pod.uid. A bucket with no row does not breach; absence is stale's job. It reads OK only on complete evidence, and is otherwise UNKNOWN (below) |
Durations are 30s, 3m, 1h. The file is checked as a whole at start. A rules file
with an unknown kind, a duplicate name, points above of or below 1, a duration
not above zero, a stale rule whose keep_firing_for is shorter than its after, a
key no kind reads, or a metric name that is not one makes alert exit with status 2.
The message names the rule and the field, or both fields, and never their values. A
stale rule reads OK for after past its newest row whether or not another arrives,
so a shorter clear delay would let one row, after an outage that resumes at once,
send an OK the next after contradicts.
A metric name is checked by its grammar, never against a list: OpenTelemetry's
instrument name syntax (streamcast_watch.otel.METRIC_NAME), an ASCII letter followed
by at most 254 letters, digits, _, ., - or /. streamcast_watch.names holds
the names this package publishes, as constants; it is not an allow-list, so a service
that publishes its own OTel metric rows needs rule entries only. A rule naming a metric
nobody publishes loads, and then its stale fires or its threshold never does:
which names a deployment publishes is the deployment's to check.
Three verdicts, and what the cache can know
A threshold is BREACH, OK or UNKNOWN at each evaluation. A stale rule is BREACH or
OK only: being unable to read is already its alarm.
Completeness is tracked on the observation clock, between two edges the window
derives from the broker's streamcast_ts, with max_skew (S, 15 s) counted twice,
once for a publisher's clock against the broker's and once for a broker clock step:
highis the greateststreamcast_tsdelivered since the seed, minus 2S. The follower delivers every row in offset order without a gap, so a row not yet delivered comes after the newest one delivered, so it was taken at most S before that greatest stamp (a larger step back is a clock fault) and observed at most S before it was taken: every row observed beforehighis here.lowcovers the rows below a seeded replay's first offset, which are never asked for: until the replay's first row, nothing is complete; then everything observed after that row's stamp plus 2S is. A replay fromEARLIESThas nolow.
S is checked on every row, not assumed. A row whose observation time is more than
S from its broker stamp, whose stamp is more than S ahead of this process's clock, or
whose stamp steps back more than S below the greatest one delivered, is a clock fault:
it is not counted, no bucket of the rules it matches (every rule on the stream, for a
step back) is complete for one ring span, and it is logged once per episode. Those
rules read OK on nothing for that span, and read UNKNOWN unless a bucket's held rows
already breach a subset-safe reduction (min below, max above): that breach still
fires during the fault, because fewer rows can only raise a minimum or lower a
maximum, and the faulty row, which is not counted, did not cause it. The one relation S
bounds that cannot be checked is a broker clock step among the rows below a seed,
which are never delivered.
A bucket is complete when it starts after low, ends by high, no series was
refused into it, it is still in the ring, and its rule has no live clock fault. Each
bucket is then:
- breach: it holds rows whose number breaches, and either the reduction is
subset-safe —
minwithbelow,maxwithabove, where fewer rows can only raise a minimum or lower a maximum — or the bucket is complete.increasealso needs every bucket from the baseline it read to this one complete; - ok: it is complete and does not breach;
- unknown: otherwise.
The rule reads two windows of of buckets: the one ending with the bucket that holds
now, so a subset-safe rule fires as soon as its rows arrive, and the one ending
with the last full bucket at or before min(now, high), which is fully settled. It
is BREACH when either has points breach buckets; OK when the settled one has
fewer than points breach and unknown buckets together and now − high is at most
max_lag (300 s); and UNKNOWN otherwise. UNKNOWN has four causes, each named in
its notice: the replay's seed, the series cap, a clock fault, and no row for longer
than max_lag. No other rule's traffic and no volume can cause one: each rule keeps
its own buckets, and nothing in them is evicted to make room.
What a reader sees: buckets are aligned to period, so a 3-of-5 one-minute rule
fires within one period of where a sliding window would; a subset-safe rule is as
fresh as its rows; and every other verdict settles 2S plus the publishing cadence
after its bucket ends.
A new kind is a Rule subclass registered under its kind: name:
from streamcast_watch import Finding, Rule, register
@register("absent_value")
class AbsentValue(Rule):
OPTIONS = frozenset({...}) # its own keys in a rules file
... # evidence(settings), options(raw), holds(window, now)
Notices
OK to FIRING sends one [ALARM] <rule>. FIRING to OK sends one [OK] <rule>, once
the rule has read OK for keep_firing_for without a break. UNKNOWN sends nothing,
keeps a FIRING rule firing, and restarts that clear timer: a rule that cannot be
evaluated is never taken to have cleared. Nothing is sent again while the state holds.
A stale rule's OK with no row since the alerter started restarts the clear timer
too: it says only that after has not passed since the start, so a rule restored
FIRING (below) stays firing through an outage that has not changed, until a row
arrives or after passes and it reads BREACH again, with no second ALARM.
After unknown_after (20, five minutes) UNKNOWN evaluations in a row, one
[UNKNOWN] <rule> names the causes: the replay's seed and until when, the series
cap, a clock fault and until when, or no row for how long. The next BREACH or OK
sends one [EVALUABLE] <rule>. They carry the rule's name, the causes, times and
counts, and series by their identifying attributes only, through the same notifier. A notice carries the rule's says, the values that decided it
(which intervals breached, which series rose, the newest row's time), and the
alerter's own view of the stream: connected or not and since when, and the last row's
time and offset. It carries metric names and numbers only, never a row's body. A series is named by its
metric and the attributes that say which target, Service, pod or container it belongs
to (names.IDENTITY); any other attribute belongs to the service that published the
metric and is never repeated. A rules file that cannot be built is refused naming the
rule and the field and the grammar it was checked against, never the value it held.
A notice that cannot be delivered stays pending, in order, and is retried with backoff. It is never dropped. A rule's notices waiting together collapse, each pair on its own, to at most four, so an ALARM, OK, ALARM sequence while delivery is down arrives as one ALARM, and UNKNOWN, EVALUABLE, UNKNOWN as one UNKNOWN.
Delivery is the Notifier seam: async send(notice), raising NotifyFailed.
LogNotifier writes notices to the log. An outside liveness check is the Liveness
seam: async beat(now), called at most once a minute, after a tick in which
every rule was evaluated and while no notice has waited more than two minutes.
The beat reads no verdict or broker state. A rule's blindness is reported by its
[UNKNOWN] notice; if that notice cannot be delivered, the pending-notice bound
stops the beat too. NoLiveness does nothing. Implementations for a cloud live
in a module of their own (aws, below), so the rest of the code does not change
between clouds.
How it follows a stream
For each stream its rules name, a Follower:
- Reads the stream's frontier from a live-only subscribe (the greeting's
end_offset) and closes it. - Subscribes at
max(EARLIEST, end_offset - replay_rows)(5,000 offsets by default), filtered on the broker to the metric names its rules read, withcontrol={"replay_end"}. That offset is its resume point from the moment it is chosen, before the subscribe is answered. The broker'sReplayEndmark says where the replay stopped. It arrives after every replayed row, and after it no row below itsend_offsetis unseen, so a resume never rescans what a filtered replay already passed. A broker older than the mark is followed the same way: its replay is over when a row at or past the greeting'send_offsetarrives. - Follows live. The resume point moves only when a row has been delivered, or when
the mark arrives. After a drop at any moment — before the greeting, before the
first row, mid-replay or live — it reconnects with backoff, 1 s doubling to 30 s,
at that point, so the cache sees each row once and skips none. It never probes the
frontier again after a drop: a new seed would start above rows the first would
have delivered. A refused resume (
ahead: the stream was recreated;too_old,evicted) starts the bounded replay again.
Each subscription accepted at a new seed starts a new epoch of the window's coverage,
so nothing is complete until the new seed's first row and its low have passed. A
resume after a drop continues the same gapless delivery and keeps the epoch. A stream
with no log has no offset to resume at, so every live-only subscription to it is a
new, seeded epoch.
A row that is not a metric data point (a broker or proxy not to trust) is dropped,
counted as delivered, and logged once by its offset. No log line and no notice holds
a row or a frame: a failure is named by its kind — the exception's type, a close
code, an errno, an HTTP status, a refusal's why — and never by an exception's text,
a close reason or a frame, any of which can quote what the peer sent.
It never uses catch_up and needs no object-storage credentials.
The Kubernetes publisher
streamcast-watch publish --targets targets.yaml --broker ws://HOST:PORT --stream NAME,
inside a pod. Every minute it lists each target's pods by label and each of its
Services' EndpointSlices, and publishes one batch to <broker>/<stream>:
targets:
- name: sortie-broker
namespace: sortie-system
pods: {app.kubernetes.io/name: streamcast, streamcast.io/broker: sortie-broker}
services: [sortie-broker, sortie-broker-pods]
Row (name) |
Type | Attributes | Value |
|---|---|---|---|
watch.target.serving |
gauge | watch.target, k8s.namespace.name |
1 when a pod matched and every listed Service has a ready endpoint, else 0 |
k8s.service.endpoint.count |
gauge | watch.target, k8s.service.name, k8s.service.endpoint.condition=ready |
the Service's ready endpoints, each pod once across its slices |
k8s.container.restart.count |
sum, cumulative, not monotonic | watch.target, k8s.pod.name, k8s.pod.uid, k8s.container.name |
restartCount, from initContainerStatuses (native sidecars) and containerStatuses |
watch.heartbeat |
gauge | service = streamcast-watch-publisher |
the targets read, only when every target was read |
Every row's service is streamcast-watch-publisher. A target is read whole or not
at all: one request that fails (an RBAC 403, a namespace that is gone) withholds that
target's rows and the heartbeat, so the stale rule on the heartbeat says the watch
is blind. A batch the broker does not take is dropped, never buffered, and the drop
is logged once while it fails the same way; a stream nobody declared (4404) is tried
again every iteration. Each iteration is cut at 45 s, so iterations never overlap.
A targets file is checked whole at start like a rules file: names, namespaces and Services by Kubernetes' own grammar, label keys and values likewise, at least one label (an empty selector lists every pod), unique names. An error names the target and the field, never the value.
What it may read. It reads the API with the service account's mounted token,
read again for every request because Kubernetes rotates it, and the mounted CA, which
it requires: it never sends the token to a server it cannot verify. It only ever
sends GET, and only to collections (pods by label selector, EndpointSlices by
Service), never to one named object. Its Role in each target's namespace needs list
on pods and list on discovery.k8s.io endpointslices, and nothing else: no Secret, no
ClusterRole, no write verb. A failure is logged as an HTTP status or a failure's kind,
never a response body. It holds no cloud credential.
What the alerter announced
A restarted alerter has nothing on disk, so it keeps what it has told a person on the
stream. After an ALARM or OK is delivered, it publishes watch.alert.announced
(gauge, 1 for ALARM, 0 for OK, attribute watch.rule, service
streamcast-watch-alerter) to the rule's stream, and publishes every rule's state again
every minute. On start the bounded replay brings it back. A stream is restored when
its follower's replay ends, and only then: every rule last announced FIRING, and not
announced since by this process, becomes FIRING. So a rule that still holds sends no
second ALARM, one that cleared sends its OK, and one that cannot be evaluated stays
FIRING. UNKNOWN and EVALUABLE are not recorded.
If the replay has not ended restore_within (60 s) after the start, the stream's rules
are evaluated anyway, in fallback, so an unreachable broker is still alerted on. That
is not a restore: nothing is published until the replay ends, so a new process never
overwrites a 1 it has not read, and when the replay does end, however late, its state
is reconciled. A rule announced FIRING that now reads OK sends its OK after
keep_firing_for. An ALARM this process queued and has not delivered is withdrawn,
since the person already has one; an ALARM it already delivered in fallback is the one
duplicate, and nothing more is sent for it. A replay that never ends is never restored,
and nothing is ever published. The record follows the delivery, so a crash between the
two sends a notice twice, never loses one; with no replay at all, a rule that holds
sends its ALARM again. Delivery is at least once.
One alerter per stream at a time is a prerequisite: one replica, replaced with
strategy: Recreate. Nothing coordinates two: each would restore before the other
announced, both would notify, and each would publish its own state over the other's.
The AWS seam
streamcast_watch.aws, behind the aws extra, is the whole of the AWS surface and the
only module that imports boto3. Credentials are boto3's default chain (Pod Identity on
EKS); nothing reads or holds a key.
SnsNotifier(--notifier sns --topic-arn ARN) publishes each notice to an existing topic: subject[ALARM] <rule>(printable ASCII, under 100 characters), the body as the message. It needssns:Publishon that topic. The region is the ARN's.CloudWatchLiveness(--liveness cloudwatch) putsAlive = 1in namespaceWatch/Alerter, dimensionAlerter = sortie, once a minute. It needscloudwatch:PutMetricData. The alerter beats only after an evaluation in which every rule was evaluated and while no notice is overdue. An outside alarm watching the metric'sSampleCountsays "not evaluating every rule, or not delivering". It never depends on the broker's connection. The region is the topic's when one is given.
A refusal leaves the seam as the error's class and HTTP status, never AWS's message, which can quote the topic's ARN; no log line holds the ARN. Every call is bounded: 5 s to connect, 10 s to read, three attempts.
Commands, environment and the image
streamcast-watch alert --rules PATH --broker URI [--notifier log|sns] [--topic-arn ARN]
[--liveness none|cloudwatch] [--health-port 8080]
streamcast-watch publish --targets PATH --broker URI --stream NAME [--health-port 8080]
streamcast-watch notify-test [--notifier log|sns] [--topic-arn ARN]
streamcast-watch spec --stream NAME
--notifier, --topic-arn and --liveness default to STREAMCAST_WATCH_NOTIFIER,
STREAMCAST_WATCH_TOPIC_ARN and STREAMCAST_WATCH_LIVENESS, so a pod that sets them
can run kubectl exec … -- streamcast-watch notify-test with no arguments and test the
very path its alerter delivers through. notify-test sends one [TEST] notice and
exits 0 once it is delivered, 1 if not. alert and publish serve GET /healthz on
--health-port (0 for none, at most 65535): 200 while the evaluation loop ticked
within 45 s, or an iteration finished within 150 s; neither asks the broker. Every
command checks its arguments and files before it connects to anything, and no error
repeats a refused value, --health-port's included.
docker/watch.Dockerfile builds one image with both commands and the aws extra, and
without the broker: Python 3.12, user 10001:10001, entry point streamcast-watch,
nothing written at run time, so it runs with a read-only root filesystem. Its Python
and uv images are pinned by the digest of their multi-platform index, with the tag
each was read from in a comment beside it.
The metrics schema
streamcast_watch.otel.METRICS_SCHEMA is OpenTelemetry's metric data point as a row,
one row per data point. It is the schema's one home. examples/otel/ publishes and
re-exports through it, and streamcast-watch spec --stream NAME prints the
declaration a broker's control API takes:
streamcast-watch spec --stream sortie-metrics
Bounds
| What | Time bound | Size bound |
|---|---|---|
A stale rule's evidence (memory) |
— | one number |
A threshold rule's evidence (memory) |
one ring per series: of + 3 + ⌈max_lag / period⌉ + ⌈2 max_skew / period⌉ buckets by time_unix_nano (14 and 11 for the approved rules), pruned by bucket index whatever order rows arrive in; a row whose bucket is already below the ring is dropped as it arrives |
max_series (64) series, each at most max_buckets (256) buckets of min, max and last: 4 MiB at most per rule. A new series past the cap is refused, logged once, and its bucket cannot be decided; a series retires when its buckets leave the ring. A rule whose ring needs more than max_buckets is refused at load |
| A stream's coverage (memory) | per epoch | four numbers |
| A clock fault | one ring span | — |
Rows no rule matches, rows without streamcast_ts, clock-fault rows (from threshold evidence), rows that are not metric data points |
dropped as they arrive | — |
| A replay | — | replay_rows (5,000) offsets, and never more than the broker's max_replay |
| Pending notices (memory) | until delivered | four per rule |
| Announced state (memory) | — | one number per rule, replayed and kept; rows for rules not in the file are dropped |
| The publisher (memory) | one iteration | one batch; nothing kept between iterations |
| A Kubernetes response | 10 s | 8 MiB, refused unread past it |
Metadata
Release files for streamcast-watch 0.33.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamcast_watch-0.33.0.tar.gz | 75.4 kB | With provenance | Details for streamcast_watch-0.33.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamcast_watch-0.33.0-py3-none-any.whl | Python 3 | none | any | Details for streamcast_watch-0.33.0-py3-none-any.whl |
Total release size: 152.5 kB
Release files / streamcast_watch-0.33.0.tar.gz
| Download URL | streamcast_watch-0.33.0.tar.gz |
|---|---|
| Size | 75.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bcdb16ed776c3d425d6575b9bc09bb59dd156cda492e5c4600a0bbc172f762d
|
|
BLAKE2b-256 checksum How to use checksums |
d6d5c22203aff13bed73d19585e655567facddadf65d60a0c0f9aab9ba4eb5f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logRelease files / streamcast_watch-0.33.0-py3-none-any.whl
| Download URL | streamcast_watch-0.33.0-py3-none-any.whl |
|---|---|
| Size | 77.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a912aef42101fbc34abfd8f43640f83f4d72a4bb5fcf93762f4c28d5667169f
|
|
BLAKE2b-256 checksum How to use checksums |
20a501bf7b45325c4feebed0f08f1c19e65191972ed60f90f198b59a939ad61d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logSecurity for streamcast-watch 0.33.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for streamcast_watch-0.33.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.