- Go 90.1%
- Go Template 4.5%
- Shell 3.2%
- JavaScript 1.5%
- CSS 0.5%
- Other 0.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
Release / chart-1 (push) Successful in 4s
Release / changelog (push) Successful in 3s
Release / shellcheck (push) Successful in 5s
Release / test (push) Successful in 24s
Release / ci (push) Successful in 0s
Release / plan (push) Successful in 4s
Release / image (push) Successful in 35s
Release / chart (push) Successful in 5s
Release / release (push) Successful in 1s
|
||
| .forgejo/workflows | ||
| charts/flap | ||
| cmd | ||
| docs | ||
| internal | ||
| scripts | ||
| .dockerignore | ||
| .gitignore | ||
| .ko.yaml | ||
| CHANGELOG.md | ||
| Dockerfile | ||
| go.mod | ||
| README.md | ||
flap
A deterministic outage service for testing uptime monitors and retry logic. docs/spec.md is what it does.
Memory and load
docs/loadtest.md records the memory budget (idle 16 MiB, loaded 32 MiB, measured on Linux), how to measure it with scripts/loadtest.sh, the Linux numbers and the levers tried (9.4 MiB idle and 20.4 MiB loaded, so the budget is met), and the cross-process determinism check (go test ./... -run Determinism).
Container image
The Dockerfile builds a static binary (CGO_ENABLED=0, -trimpath) and ships it alone in a scratch image that runs as the numeric user 65532 and listens on 8080. The golang build image is pinned to a minor version; bump it on purpose.
docker build --build-arg VERSION=0.1.0 -t sarak.sh/mikluko/flap:0.1.0 .
docker run --rm -p 8080:8080 sarak.sh/mikluko/flap:0.1.0
curl -i localhost:8080/healthz
VERSION defaults to dev. The image path sarak.sh/mikluko/flap is a default to confirm; the chart takes it from image.repository.
Helm chart
charts/flap deploys two replicas spread across nodes, a PodDisruptionBudget (minAvailable: 1), liveness on /healthz, readiness on /readyz, a read-only non-root container, a Service and a TLS Ingress for flap.sarak.sh. There is no HorizontalPodAutoscaler.
scripts/check-chart.sh # lint, render and assert, default and prod-like values
helm template flap charts/flap -f charts/flap/ci/prod-values.yaml
helm upgrade --install flap charts/flap --set image.tag=0.1.0 -f my-values.yaml
Values you will usually override:
| Value | Default | Meaning |
|---|---|---|
image.repository, image.tag |
sarak.sh/mikluko/flap, chart appVersion |
Image to run |
ingress.className |
empty | Ingress class of the cluster |
ingress.tls.secretName |
flap-sarak-sh-tls |
Certificate secret for ingress.host |
ingress.annotations |
ingress-nginx timeouts | Proxy timeouts and the issuer annotation |
maxHangSeconds |
300 |
FLAP_MAX_HANG; the proxy read timeout must be higher |
drainDelaySeconds |
5 |
FLAP_DRAIN_DELAY and the preStop sleep |
Assumptions to confirm for the cluster:
- The
preStopsleep uses the nativesleepaction, which needs Kubernetes 1.30 or newer because the image has no shell. - The default ingress annotations are ingress-nginx ones. The chart refuses to render if
proxy-read-timeoutis not abovemaxHangSeconds, so long/hangresponses are not cut by the proxy. Adapt them for another controller. - The cert-manager issuer annotation is a commented placeholder in
values.yamluntil the cluster convention is known. terminationGracePeriodSecondsis computed as preStop sleep + drain delay + the 10 s shutdown deadline + 10 s margin unless you set it.replicaCountbelow 2 is rejected: with one pod the PodDisruptionBudget would block node drains.
To install into the saraksh cluster and verify the result, follow docs/deploy.md. A small service for testing how clients behave when a dependency fails. It serves outages on a fixed daily schedule, so an uptime monitor, a retry loop or an alert rule can be pointed at it and checked against failures that arrive when you expect them.
The schedule is a pure function of the clock and the query parameters. There is no state, no randomness at runtime and no coordination, so every replica and every restart agrees on when the outages are. docs/spec.md is the full specification; this page covers running, developing and releasing the service.
By default each UTC day holds ten outages of 15 minutes (90 % availability), spread evenly.
Run it
go run ./cmd/flap
curl -i localhost:8080/healthz
Configuration is environment variables only. Schedule behaviour is never configurable, only the limits and the listener:
| Variable | Default | Meaning |
|---|---|---|
FLAP_ADDR |
:8080 |
Listen address. |
FLAP_BASE_URL |
unset | Base URL for absolute links, without a trailing slash. |
FLAP_MAX_HANG |
5m |
Longest time /hang holds a response. |
FLAP_MAX_HANGS |
256 |
Concurrent /hang holds; more get 429. |
FLAP_MAX_DROP_BYTES |
65536 |
Most body bytes /drop writes before the reset. |
FLAP_LOG_LEVEL |
info |
Minimum log level: debug, info, warn or error. |
FLAP_DRAIN_DELAY |
5s |
How long to keep serving after SIGTERM turns /readyz to 503. |
An invalid value stops the server at startup and names every bad variable. Every request writes one JSON access log line to standard output.
Endpoints
| Path | What it does | Status |
|---|---|---|
GET /healthz |
Liveness: always 200 ok. |
Available |
GET /readyz |
200 ok, then 503 once shutdown begins. |
Available |
/status/{code} |
Answers code during an outage, 200 otherwise. |
Planned |
/hang |
Holds the response during an outage, then answers 200. | Planned |
/drop |
Resets the connection during an outage. Direct to a pod only; see below. | Planned |
/inspect |
Shows the schedule as JSON or an SVG timeline. | Planned |
/ and /docs |
Explorer and reference pages. | Planned |
"Planned" endpoints are specified but not in the code yet; they do not answer. Every failure endpoint takes the same schedule parameters, listed in the next section.
/drop writes its headers and bytes body bytes, then resets the connection,
but only a client connected directly to the pod sees that. Through an ingress
such as the Traefik one in front of flap.sarak.sh, the client gets no headers
and no body bytes: over HTTP/1.1 an empty reply (curl exits 52), over HTTP/2 a
stream reset (curl exits 92). The bytes count and a true TCP reset hold only
on a direct connection to the pod.
Schedule parameters
These are the planned query parameters for the schedule endpoints. They are not parsed by the code yet.
| Name | Default | Bounds |
|---|---|---|
period |
1d |
1s to 366d |
outage |
15m |
1s to period |
count |
derived | 0 to 10 000, at most period / outage |
availability |
90 |
0 to 100 percent |
seed |
0 |
any unsigned 64-bit integer |
placement |
even |
even, scattered or grid |
Durations are written as 15m, 1h30m, 1d or a bare number of seconds.
Periods align to the Unix epoch in UTC.
Develop
These are the commands CI runs on every pull request:
test -z "$(gofmt -l .)"
go vet ./...
go test -race -count=1 ./...
helm lint --strict charts/flap
helm template flap charts/flap > /dev/null
shellcheck scripts/*.sh
changelog -fragments ''
The changelog checker validates CHANGELOG.md; this repository keeps notes in
the file and not in .changelog/ fragments (the dot-directory is git-ignored),
hence -fragments ''. In CI it runs as the https://sarak.sh/mikluko/changelog@v1
action.
Add a note to the [Unreleased] section of CHANGELOG.md for
every change a user or operator would notice. It follows
Keep a Changelog 2.0.0.
Releasing
The Forgejo workflows live in .forgejo/workflows/ and follow
mikluko/jmap-mcp. All jobs run on
ubuntu-latest.
ci.yamlruns on every pull request, and the release workflow calls it. Its jobs aregofmt,go vet,go test -raceand a static build;helm lint --strictandhelm templateon the chart and its value sets;shellcheck scripts/*.sh; and the changelog check.release.yamlruns on every push tomain. It repeatsci.yaml, then builds the image with ko (.ko.yaml, basegcr.io/distroless/static:nonroot,linux/amd64andlinux/arm64) and pushes it tosarak.sh/mikluko/flapasmain-<sha>-<unix time>.
To cut a version, add its entry to CHANGELOG.md (move the [Unreleased] notes
under ## [X.Y.Z] - date) and merge. When the newest entry names a version
that has no tag yet, the same run also pushes the image as X.Y.Z and
latest, packages the chart with version and appVersion set to X.Y.Z,
pushes it to oci://sarak.sh/mikluko/charts/flap, and creates the tag
vX.Y.Z and the release with the changelog notes. The tag is created last, so
it exists only when everything it names does.
| Published | Name |
|---|---|
| Image | sarak.sh/mikluko/flap:<version> (and :latest, :main-<sha>-<unix time>) |
| Chart | oci://sarak.sh/mikluko/charts/flap:<version> |
Registry access
The release workflow holds no registry password. It sets
enable-openid-connect: true, asks the Forgejo runner for an OIDC token whose
audience is REGISTRY_AUDIENCE (an Authorized Integration of the owner's,
scoped write:package), and presents that token as the password to
ko login and helm registry login. Nothing needs to be set under the
repository's Actions secrets.
To rehearse the image build without pushing:
VERSION=0.0.0-dev KO_DOCKER_REPO=sarak.sh/mikluko/flap \
ko build --bare --push=false --tarball /tmp/flap.tar ./cmd/flap
The Dockerfile stays for local docker build; the release does not use it.