Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07be88a783 | ||
|
|
0aecadb699 | ||
|
|
0e2e5cba34 | ||
|
|
4277e0774e | ||
|
|
19e550df12 | ||
|
|
1704b5c61a | ||
|
|
7f568516d1 | ||
|
|
bb5b9f3026 | ||
|
|
88ae7f9158 | ||
|
|
40288eade8 | ||
|
|
7b35688819 | ||
|
|
82a8380b48 | ||
|
|
adb8d5fab1 | ||
|
|
55ab869735 | ||
|
|
daa3955cee | ||
|
|
09b1730954 | ||
|
|
9d9470b8cd | ||
|
|
590a50d959 | ||
|
|
db330b3fad | ||
|
|
1073d8dfde | ||
|
|
e14262db4d | ||
|
|
b2c00cd23d | ||
|
|
f323549ae7 | ||
|
|
60de2961b2 | ||
|
|
0780e1e794 | ||
|
|
930fefb32d |
@@ -1,3 +1,7 @@
|
||||
node_modules/
|
||||
.env
|
||||
*.log
|
||||
|
||||
# Monitoring: commit the pinned versions, never the Grafana secrets.
|
||||
!deploy/monitoring/.env
|
||||
deploy/monitoring/grafana.secrets.env
|
||||
|
||||
Vendored
+273
@@ -0,0 +1,273 @@
|
||||
// Pull requests run tests and checks only. On main, a change to pricing/,
|
||||
// ansible/ or this file builds one image and promotes its digest from staging
|
||||
// to production after a human approval. Setting RELEASE_RECORD redeploys an
|
||||
// existing release without building, which is how rollback and recovery run.
|
||||
|
||||
// Applies one release record with Ansible on the delivery agent.
|
||||
def deploy(String record, String label) {
|
||||
withCredentials([sshUserPrivateKey(credentialsId: 'delivery-ssh', keyFileVariable: 'SSH_KEY')]) {
|
||||
withEnv(["RECORD=${record}", "LABEL=${label}"]) {
|
||||
sh '''#!/bin/bash
|
||||
set -euo pipefail
|
||||
mkdir -p reports
|
||||
export ANSIBLE_COLLECTIONS_PATH="$WORKSPACE/.collections"
|
||||
"$TOOLS/ansible-galaxy" collection install -r ansible/requirements.yml -p "$ANSIBLE_COLLECTIONS_PATH"
|
||||
"$TOOLS/ansible-playbook" -i ansible/inventory.ini ansible/deploy.yml --syntax-check
|
||||
echo "deploy start: $(date -u +%FT%TZ) $RECORD"
|
||||
"$TOOLS/ansible-playbook" -i ansible/inventory.ini ansible/deploy.yml \
|
||||
--private-key "$SSH_KEY" -e "@$RECORD" | tee "reports/$LABEL.txt"
|
||||
echo "deploy end: $(date -u +%FT%TZ) $RECORD"
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prints the public behavior of a release as evidence; Ansible asserts it.
|
||||
def smoke(String record) {
|
||||
withEnv(["RECORD=${record}"]) {
|
||||
sh '''#!/bin/bash
|
||||
set -euo pipefail
|
||||
URL=$(sed -n 's/^public_url: //p' "$RECORD")
|
||||
curl -fsS "$URL/"; curl -fsS "$URL/health"; curl -fsS "$URL/price?quantity=3"
|
||||
test "$(curl -s -o /dev/null -w '%{http_code}' "$URL/price?quantity=0")" = 400
|
||||
echo "invalid quantity returned 400"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
pipeline {
|
||||
agent none
|
||||
|
||||
options {
|
||||
disableConcurrentBuilds()
|
||||
skipDefaultCheckout()
|
||||
}
|
||||
|
||||
parameters {
|
||||
string(name: 'RELEASE_RECORD', defaultValue: '', description: 'Redeploy this record without building, for example releases/v1-production.yml.')
|
||||
string(name: 'CONFIG_REF', defaultValue: '', description: 'Commit whose ansible/ directory to use. Empty uses this build\'s commit. Production accepts only commits on main.')
|
||||
}
|
||||
|
||||
environment {
|
||||
IMAGE = 'git.pollefeys.dev/seatbacktrivia/pricing'
|
||||
TOOLS = '/opt/delivery/bin'
|
||||
TRIVY_CACHE_DIR = '/home/jenkins/agent/trivy-cache'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Product tests') {
|
||||
agent { label 'built-in' }
|
||||
when { expression { !params.RELEASE_RECORD } }
|
||||
steps {
|
||||
checkout scm
|
||||
sh 'node --version'
|
||||
sh 'npm --version'
|
||||
sh 'npm ci'
|
||||
sh 'npm test'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Pricing tests') {
|
||||
agent { label 'delivery' }
|
||||
when { expression { !params.RELEASE_RECORD } }
|
||||
steps {
|
||||
script {
|
||||
env.RELEASE_COMMIT = checkout(scm).GIT_COMMIT
|
||||
}
|
||||
dir('pricing') {
|
||||
sh '''
|
||||
python3 -m venv .venv
|
||||
. .venv/bin/activate
|
||||
pip install --quiet --disable-pip-version-check -r requirements.txt
|
||||
python -m py_compile app.py test_app.py
|
||||
python -m unittest -v
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Dependency and secret checks') {
|
||||
agent { label 'delivery' }
|
||||
when { expression { !params.RELEASE_RECORD } }
|
||||
steps {
|
||||
sh '''
|
||||
mkdir -p reports
|
||||
trivy --version
|
||||
trivy fs --scanners secret --skip-dirs pricing/.venv --exit-code 1 --no-progress --output reports/secrets.txt . \
|
||||
|| { cat reports/secrets.txt; exit 1; }
|
||||
"$TOOLS/pip-audit" --version
|
||||
"$TOOLS/pip-audit" -r pricing/requirements.txt --no-deps --disable-pip > reports/pip-audit.txt 2>&1 \
|
||||
|| { cat reports/pip-audit.txt; exit 1; }
|
||||
cat reports/secrets.txt reports/pip-audit.txt
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Select release') {
|
||||
agent { label 'delivery' }
|
||||
when { allOf { branch 'main'; expression { !params.RELEASE_RECORD } } }
|
||||
steps {
|
||||
script {
|
||||
env.DELIVER = sh(returnStatus: true, script: 'git diff --quiet HEAD^1 HEAD -- pricing ansible Jenkinsfile') != 0 ? 'true' : 'false'
|
||||
echo "pricing/, ansible/ or Jenkinsfile changed: ${env.DELIVER}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build image') {
|
||||
agent { label 'delivery' }
|
||||
when { environment name: 'DELIVER', value: 'true' }
|
||||
steps {
|
||||
sh 'DOCKER_BUILDKIT=0 docker build --build-arg APP_COMMIT="$RELEASE_COMMIT" -t "$IMAGE:$RELEASE_COMMIT" pricing'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Scan image') {
|
||||
agent { label 'delivery' }
|
||||
when { environment name: 'DELIVER', value: 'true' }
|
||||
steps {
|
||||
sh '''
|
||||
trivy image --image-src docker --scanners vuln --severity HIGH,CRITICAL \
|
||||
--exit-code 1 --no-progress --output reports/image.txt "$IMAGE:$RELEASE_COMMIT" \
|
||||
|| { cat reports/image.txt; exit 1; }
|
||||
cat reports/image.txt
|
||||
trivy version | tee reports/trivy-version.txt
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish image') {
|
||||
agent { label 'delivery' }
|
||||
when { environment name: 'DELIVER', value: 'true' }
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'registry-write', usernameVariable: 'REG_USER', passwordVariable: 'REG_TOKEN')]) {
|
||||
sh '''#!/bin/bash
|
||||
set -euo pipefail
|
||||
mkdir -p releases reports
|
||||
export DOCKER_CONFIG=$(mktemp -d)
|
||||
trap 'rm -rf "$DOCKER_CONFIG"' EXIT
|
||||
printf '%s' "$REG_TOKEN" | docker login "${IMAGE%%/*}" -u "$REG_USER" --password-stdin
|
||||
docker push "$IMAGE:$RELEASE_COMMIT"
|
||||
docker pull "$IMAGE:$RELEASE_COMMIT"
|
||||
DIGEST=$(docker image inspect "$IMAGE:$RELEASE_COMMIT" --format '{{index .RepoDigests 0}}')
|
||||
VERSION=$(sed -n 's/^VERSION = "\\(.*\\)"/\\1/p' pricing/app.py)
|
||||
UNIT=$(sed -n 's/^UNIT_PRICE = //p' pricing/app.py)
|
||||
for TARGET in staging production; do
|
||||
HOST=app; [ "$TARGET" = staging ] && HOST=staging
|
||||
cat > "releases/$VERSION-$TARGET.yml" <<EOF
|
||||
target_env: $TARGET
|
||||
release_image: $DIGEST
|
||||
expected_version: $VERSION
|
||||
expected_commit: $RELEASE_COMMIT
|
||||
expected_total: $((UNIT * 3))
|
||||
public_url: https://$HOST.pollefeys.dev
|
||||
proxy_network: gitea_gitea-net
|
||||
EOF
|
||||
done
|
||||
echo "$VERSION" > reports/version.txt
|
||||
cat "releases/$VERSION-staging.yml"
|
||||
'''
|
||||
}
|
||||
stash name: 'release', includes: 'releases/*.yml,reports/version.txt'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy staging') {
|
||||
agent { label 'delivery' }
|
||||
when { environment name: 'DELIVER', value: 'true' }
|
||||
steps {
|
||||
unstash 'release'
|
||||
script {
|
||||
def version = readFile('reports/version.txt').trim()
|
||||
deploy("releases/${version}-staging.yml", 'staging-first-run')
|
||||
// An unchanged rerun must report no changes.
|
||||
deploy("releases/${version}-staging.yml", 'staging-second-run')
|
||||
sh 'grep -E "changed=0 +unreachable=0 +failed=0" reports/staging-second-run.txt'
|
||||
smoke("releases/${version}-staging.yml")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Redeploy selected record') {
|
||||
agent { label 'delivery' }
|
||||
when { expression { params.RELEASE_RECORD && !params.RELEASE_RECORD.contains('production') } }
|
||||
steps {
|
||||
checkout scm
|
||||
sh '''
|
||||
if [ -n "$CONFIG_REF" ]; then
|
||||
git fetch --quiet "$(git remote get-url origin)" '+refs/heads/*:refs/remotes/all/*'
|
||||
git checkout "$CONFIG_REF" -- ansible
|
||||
fi
|
||||
'''
|
||||
script {
|
||||
deploy(params.RELEASE_RECORD, 'redeploy')
|
||||
smoke(params.RELEASE_RECORD)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Production approval') {
|
||||
when {
|
||||
anyOf {
|
||||
environment name: 'DELIVER', value: 'true'
|
||||
expression { params.RELEASE_RECORD?.contains('production') }
|
||||
}
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def target = params.RELEASE_RECORD ?: 'the release built by this run'
|
||||
timeout(time: 30, unit: 'MINUTES') {
|
||||
env.APPROVER = input(
|
||||
message: "Deploy ${target} to production? Commit ${env.RELEASE_COMMIT ?: 'see record'}, build ${env.BUILD_NUMBER}. Check the image digest, scan result, and staging result in this run first.",
|
||||
ok: 'Approve production',
|
||||
submitter: 'natalie,cedric',
|
||||
submitterParameter: 'APPROVER'
|
||||
)
|
||||
}
|
||||
echo "Approved by ${env.APPROVER}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy production') {
|
||||
agent { label 'delivery' }
|
||||
when {
|
||||
anyOf {
|
||||
environment name: 'DELIVER', value: 'true'
|
||||
expression { params.RELEASE_RECORD?.contains('production') }
|
||||
}
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def record = params.RELEASE_RECORD
|
||||
if (record) {
|
||||
checkout scm
|
||||
// Production uses only reviewed configuration from main.
|
||||
sh '''
|
||||
if [ -n "$CONFIG_REF" ]; then
|
||||
git merge-base --is-ancestor "$CONFIG_REF" HEAD
|
||||
git checkout "$CONFIG_REF" -- ansible
|
||||
fi
|
||||
'''
|
||||
} else {
|
||||
unstash 'release'
|
||||
record = "releases/${readFile('reports/version.txt').trim()}-production.yml"
|
||||
}
|
||||
withEnv(["RECORD=${record}"]) {
|
||||
sh 'mkdir -p reports; echo "approver=$APPROVER time=$(date -u +%FT%TZ) record=$RECORD" | tee reports/approval.txt'
|
||||
}
|
||||
deploy(record, 'production')
|
||||
smoke(record)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
node('delivery') {
|
||||
archiveArtifacts artifacts: 'reports/**,releases/*.yml', allowEmptyArchive: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
- name: Deploy a selected immutable pricing release
|
||||
hosts: delivery
|
||||
become: true
|
||||
vars:
|
||||
project_dir: "/opt/startup/pricing-{{ target_env }}"
|
||||
tasks:
|
||||
- name: Validate release selection
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- target_env in ['staging', 'production']
|
||||
- "'@sha256:' in release_image"
|
||||
- expected_version in ['v1', 'v2']
|
||||
- expected_total | int > 0
|
||||
- public_url.startswith('https://')
|
||||
- proxy_network | length > 0
|
||||
- name: Create deployment directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ project_dir }}"
|
||||
state: directory
|
||||
mode: '0750'
|
||||
- name: Render selected Compose configuration
|
||||
ansible.builtin.template:
|
||||
src: compose.yaml.j2
|
||||
dest: "{{ project_dir }}/compose.yaml"
|
||||
mode: '0640'
|
||||
- name: Converge application without rebuilding
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ project_dir }}"
|
||||
project_name: "pricing-{{ target_env }}"
|
||||
state: present
|
||||
build: never
|
||||
pull: missing
|
||||
wait: true
|
||||
wait_timeout: 90
|
||||
- name: Verify health through public TLS endpoint
|
||||
ansible.builtin.uri:
|
||||
url: "{{ public_url }}/health"
|
||||
return_content: true
|
||||
validate_certs: true
|
||||
register: health
|
||||
until: health.status == 200 and health.json.status == 'ok'
|
||||
retries: 12
|
||||
delay: 5
|
||||
changed_when: false
|
||||
- name: Read release identity
|
||||
ansible.builtin.uri:
|
||||
url: "{{ public_url }}/"
|
||||
return_content: true
|
||||
register: identity
|
||||
changed_when: false
|
||||
- name: Exercise business behavior
|
||||
ansible.builtin.uri:
|
||||
url: "{{ public_url }}/price?quantity=3"
|
||||
return_content: true
|
||||
register: price
|
||||
changed_when: false
|
||||
- name: Check release identity and calculation
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- identity.json.version == expected_version
|
||||
- identity.json.commit == expected_commit
|
||||
- price.json.total | int == expected_total | int
|
||||
@@ -0,0 +1,3 @@
|
||||
[delivery]
|
||||
# 172.18.0.1 is the droplet host as seen from the delivery agent on gitea_gitea-net.
|
||||
startup ansible_host=172.18.0.1 ansible_user=deploy ansible_ssh_common_args='-o UserKnownHostsFile=ansible/known_hosts -o StrictHostKeyChecking=yes'
|
||||
@@ -0,0 +1 @@
|
||||
172.18.0.1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPvkyH0+3FOyLD81nBpbyYomdRhwEUhEnrRLfp7/UQPV
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copy to a release-specific file and replace EVERY placeholder.
|
||||
target_env: staging
|
||||
release_image: git.pollefeys.dev/seatbacktrivia/pricing@sha256:REPLACE_DIGEST
|
||||
expected_version: v1
|
||||
expected_commit: REPLACE_FULL_GIT_COMMIT
|
||||
expected_total: 30
|
||||
public_url: https://staging.pollefeys.dev
|
||||
proxy_network: gitea_gitea-net
|
||||
@@ -0,0 +1,3 @@
|
||||
collections:
|
||||
- name: community.docker
|
||||
version: ">=4.8.0,<6.0.0"
|
||||
@@ -0,0 +1,19 @@
|
||||
services:
|
||||
app:
|
||||
image: "{{ release_image }}"
|
||||
restart: unless-stopped
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks:
|
||||
edge:
|
||||
aliases:
|
||||
- "pricing-{{ target_env }}"
|
||||
networks:
|
||||
edge:
|
||||
external: true
|
||||
name: "{{ proxy_network }}"
|
||||
@@ -0,0 +1,19 @@
|
||||
# Caddy obtains and renews the Let's Encrypt certificate for this hostname
|
||||
# and redirects HTTP to HTTPS automatically. TLS terminates here.
|
||||
git.pollefeys.dev {
|
||||
reverse_proxy gitea:3000
|
||||
}
|
||||
ci.pollefeys.dev {
|
||||
reverse_proxy jenkins:8080
|
||||
}
|
||||
# Grafana joins gitea_gitea-net from the monitoring Compose project.
|
||||
metrics.pollefeys.dev {
|
||||
reverse_proxy grafana:3000
|
||||
}
|
||||
# Pricing service: one Compose project per environment, joined to gitea_gitea-net.
|
||||
staging.pollefeys.dev {
|
||||
reverse_proxy pricing-staging:8000
|
||||
}
|
||||
app.pollefeys.dev {
|
||||
reverse_proxy pricing-production:8000
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
# Seat-Back Trivia startup work hub: Gitea behind Caddy on the ssw-590 droplet.
|
||||
# Only Caddy publishes host ports. Gitea is reachable only on the private
|
||||
# gitea-net network, and its SQLite database lives in the gitea-data volume.
|
||||
name: gitea
|
||||
|
||||
services:
|
||||
caddy:
|
||||
image: caddy:2.11.4
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
||||
- caddy-data:/data
|
||||
- caddy-config:/config
|
||||
networks:
|
||||
- gitea-net
|
||||
depends_on:
|
||||
- gitea
|
||||
|
||||
gitea:
|
||||
image: docker.gitea.com/gitea:1.27.3
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- USER_UID=1000
|
||||
- USER_GID=1000
|
||||
- GITEA__server__DOMAIN=git.pollefeys.dev
|
||||
- GITEA__server__ROOT_URL=https://git.pollefeys.dev/
|
||||
- GITEA__server__HTTP_PORT=3000
|
||||
- GITEA__server__DISABLE_SSH=true
|
||||
- GITEA__database__DB_TYPE=sqlite3
|
||||
- GITEA__database__PATH=/data/gitea/gitea.db
|
||||
- GITEA__security__INSTALL_LOCK=true
|
||||
- GITEA__service__DISABLE_REGISTRATION=true
|
||||
volumes:
|
||||
- gitea-data:/data
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
networks:
|
||||
- gitea-net
|
||||
|
||||
networks:
|
||||
gitea-net:
|
||||
|
||||
volumes:
|
||||
gitea-data:
|
||||
caddy-data:
|
||||
caddy-config:
|
||||
@@ -0,0 +1,6 @@
|
||||
# Trusted delivery agent: Docker CLI, Ansible, Trivy, and pip-audit. All tools are
|
||||
# in the image, so recreating the container loses nothing.
|
||||
FROM jenkins/inbound-agent:3395.v6e5377b_0fb_3c-3-jdk21
|
||||
USER root
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-venv openssh-client curl ca-certificates && rm -rf /var/lib/apt/lists/* && curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-29.8.1.tgz | tar xz --strip-components=1 -C /usr/local/bin docker/docker && curl -fsSLo /tmp/trivy.tgz https://github.com/aquasecurity/trivy/releases/download/v0.75.0/trivy_0.75.0_Linux-64bit.tar.gz && echo "c6e65abddb348e25f10549df887045629cf28cc72453cd1c63acb717316b3f3f /tmp/trivy.tgz" | sha256sum -c - && tar xzf /tmp/trivy.tgz -C /usr/local/bin trivy && rm /tmp/trivy.tgz && python3 -m venv /opt/delivery && /opt/delivery/bin/pip install --no-cache-dir ansible-core==2.22.0 pip-audit==2.10.1
|
||||
USER jenkins
|
||||
@@ -0,0 +1,34 @@
|
||||
# Inbound Jenkins agent for the delivery stages. The Docker socket makes this
|
||||
# container equivalent to host root, so only reviewed main-branch stages use its
|
||||
# credentials. DOCKER_GID and JENKINS_SECRET come from an untracked .env file.
|
||||
name: jenkins-agent
|
||||
|
||||
services:
|
||||
agent:
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- JENKINS_URL=http://jenkins:8080
|
||||
- JENKINS_AGENT_NAME=delivery-agent
|
||||
- JENKINS_SECRET=${JENKINS_SECRET}
|
||||
- JENKINS_WEB_SOCKET=true
|
||||
- JAVA_OPTS=-Xmx96m
|
||||
group_add:
|
||||
- "${DOCKER_GID}"
|
||||
volumes:
|
||||
- agent-data:/home/jenkins/agent
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
networks:
|
||||
- gitea-net
|
||||
logging:
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
|
||||
volumes:
|
||||
agent-data:
|
||||
|
||||
networks:
|
||||
gitea-net:
|
||||
external: true
|
||||
name: gitea_gitea-net
|
||||
@@ -0,0 +1,17 @@
|
||||
services:
|
||||
jenkins:
|
||||
image: jenkins/jenkins:lts-jdk21
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- jenkins-data:/var/jenkins_home
|
||||
networks:
|
||||
- gitea-net
|
||||
|
||||
volumes:
|
||||
jenkins-data:
|
||||
|
||||
networks:
|
||||
gitea-net:
|
||||
external: true
|
||||
name: gitea_gitea-net
|
||||
@@ -0,0 +1,6 @@
|
||||
# Pinned releases of the four monitoring images (amd64). Version choices only,
|
||||
# never secrets: Grafana's Discord webhook lives in grafana.secrets.env.
|
||||
PROMETHEUS_TAG=v3.15.1
|
||||
GRAFANA_TAG=12.4.14
|
||||
NODE_EXPORTER_TAG=v1.12.1
|
||||
BLACKBOX_TAG=v0.29.1
|
||||
@@ -0,0 +1,16 @@
|
||||
# A probe succeeds only if DNS resolves over IPv4, the TLS certificate is valid
|
||||
# for the hostname, redirects (if any) are followed, the final hop is HTTPS,
|
||||
# and the final response is HTTP 200, all within 10 s.
|
||||
modules:
|
||||
http_2xx:
|
||||
prober: http
|
||||
timeout: 10s
|
||||
http:
|
||||
method: GET
|
||||
preferred_ip_protocol: ip4
|
||||
ip_protocol_fallback: false
|
||||
valid_status_codes: [200]
|
||||
follow_redirects: true
|
||||
fail_if_not_ssl: true
|
||||
tls_config:
|
||||
insecure_skip_verify: false
|
||||
@@ -0,0 +1,98 @@
|
||||
# Seat-Back Trivia monitoring on the ssw-590 droplet: Prometheus, Grafana OSS,
|
||||
# Node Exporter, and Blackbox Exporter. Nothing here publishes a host port.
|
||||
# Prometheus and the exporters sit only on the private monitoring network.
|
||||
# Grafana also joins the existing gitea_gitea-net so the Caddy container can
|
||||
# proxy https://metrics.pollefeys.dev to grafana:3000.
|
||||
# The droplet has 512 MB of RAM, so every container has a hard memory cap.
|
||||
name: monitoring
|
||||
|
||||
# Disk is tight, so container logs are capped at 3 x 10 MB each.
|
||||
x-logging: &logging
|
||||
driver: json-file
|
||||
options: {max-size: 10m, max-file: "3"}
|
||||
|
||||
services:
|
||||
prometheus:
|
||||
logging: *logging
|
||||
image: prom/prometheus:${PROMETHEUS_TAG:?choose a release}
|
||||
restart: unless-stopped
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=7d
|
||||
- --storage.tsdb.retention.size=256MB
|
||||
volumes:
|
||||
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- prometheus_data:/prometheus
|
||||
mem_limit: 160m
|
||||
networks: [monitoring]
|
||||
depends_on: [node-exporter, blackbox-exporter]
|
||||
|
||||
grafana:
|
||||
logging: *logging
|
||||
image: grafana/grafana:${GRAFANA_TAG:?choose a release}
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
GF_SERVER_DOMAIN: metrics.pollefeys.dev
|
||||
GF_SERVER_ROOT_URL: https://metrics.pollefeys.dev/
|
||||
GF_AUTH_ANONYMOUS_ENABLED: "false"
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_SECURITY_COOKIE_SECURE: "true"
|
||||
# Grafana's own /metrics would otherwise be public through Caddy.
|
||||
GF_METRICS_ENABLED: "false"
|
||||
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
||||
GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
|
||||
GF_ANALYTICS_CHECK_FOR_PLUGIN_UPDATES: "false"
|
||||
GF_PLUGINS_PREINSTALL_DISABLED: "true"
|
||||
GF_NEWS_NEWS_FEED_ENABLED: "false"
|
||||
GF_DATE_FORMATS_DEFAULT_TIMEZONE: UTC
|
||||
# DISCORD_WEBHOOK_URL for the team-alerts contact point. Untracked, mode 600.
|
||||
env_file: grafana.secrets.env
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
- ./grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./grafana/dashboards:/etc/grafana/dashboards:ro
|
||||
mem_limit: 192m
|
||||
networks: [monitoring, proxy]
|
||||
depends_on: [prometheus]
|
||||
|
||||
node-exporter:
|
||||
logging: *logging
|
||||
image: quay.io/prometheus/node-exporter:${NODE_EXPORTER_TAG:?choose a release}
|
||||
restart: unless-stopped
|
||||
pid: host
|
||||
command:
|
||||
- --path.rootfs=/host
|
||||
- --path.procfs=/host/proc
|
||||
- --path.sysfs=/host/sys
|
||||
# Only what the dashboard and alerts use, to keep Prometheus small.
|
||||
- --collector.disable-defaults
|
||||
- --collector.cpu
|
||||
- --collector.meminfo
|
||||
- --collector.filesystem
|
||||
- --collector.loadavg
|
||||
- --collector.uname
|
||||
volumes:
|
||||
- /:/host:ro,rslave
|
||||
mem_limit: 32m
|
||||
networks: [monitoring]
|
||||
|
||||
blackbox-exporter:
|
||||
logging: *logging
|
||||
image: quay.io/prometheus/blackbox-exporter:${BLACKBOX_TAG:?choose a release}
|
||||
restart: unless-stopped
|
||||
command: ["--config.file=/config/blackbox.yml"]
|
||||
volumes:
|
||||
- ./blackbox/blackbox.yml:/config/blackbox.yml:ro
|
||||
mem_limit: 32m
|
||||
networks: [monitoring]
|
||||
|
||||
networks:
|
||||
monitoring:
|
||||
proxy:
|
||||
external: true
|
||||
name: gitea_gitea-net
|
||||
|
||||
volumes:
|
||||
prometheus_data:
|
||||
grafana_data:
|
||||
@@ -0,0 +1,605 @@
|
||||
{
|
||||
"uid": "seatback-sre",
|
||||
"title": "Seat-Back Trivia SRE",
|
||||
"tags": [
|
||||
"sre",
|
||||
"assignment-7"
|
||||
],
|
||||
"timezone": "utc",
|
||||
"editable": true,
|
||||
"graphTooltip": 1,
|
||||
"refresh": "30s",
|
||||
"time": {
|
||||
"from": "now-3h",
|
||||
"to": "now"
|
||||
},
|
||||
"schemaVersion": 39,
|
||||
"version": 1,
|
||||
"description": "ssw-590 droplet health and Gitea/Jenkins HTTPS availability. Source: deploy/monitoring in SeatBackTrivia/seat-back-trivia.",
|
||||
"annotations": {
|
||||
"list": [
|
||||
{
|
||||
"builtIn": 1,
|
||||
"datasource": {
|
||||
"type": "grafana",
|
||||
"uid": "-- Grafana --"
|
||||
},
|
||||
"enable": true,
|
||||
"hide": true,
|
||||
"iconColor": "rgba(0, 211, 255, 1)",
|
||||
"name": "Annotations & Alerts",
|
||||
"type": "dashboard"
|
||||
}
|
||||
]
|
||||
},
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": "timeseries",
|
||||
"title": "Droplet CPU utilization",
|
||||
"description": "Whole-droplet CPU busy %, averaged across all CPUs: 100 minus the idle rate over 2 minutes (four 30 s samples). node_cpu_seconds_total is a counter, so it is rated, never graphed raw. Includes every process on the host, not only Jenkins.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 8,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"lineWidth": 2,
|
||||
"fillOpacity": 10,
|
||||
"showPoints": "never",
|
||||
"spanNulls": false,
|
||||
"lineInterpolation": "linear",
|
||||
"thresholdsStyle": {
|
||||
"mode": "line+area"
|
||||
}
|
||||
},
|
||||
"unit": "percent",
|
||||
"color": {
|
||||
"mode": "palette-classic"
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "orange",
|
||||
"value": 80
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"value": 95
|
||||
}
|
||||
]
|
||||
},
|
||||
"min": 0,
|
||||
"max": 100
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
"showLegend": true
|
||||
},
|
||||
"tooltip": {
|
||||
"mode": "multi",
|
||||
"sort": "none"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "100 * (1 - avg(rate(node_cpu_seconds_total{job=\"node\",mode=\"idle\"}[2m])))",
|
||||
"legendFormat": "CPU busy %",
|
||||
"range": true,
|
||||
"instant": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"type": "timeseries",
|
||||
"title": "Available host memory",
|
||||
"description": "MemAvailable in bytes (IEC units): the kernel's estimate of memory that can be given to applications without swapping, not merely unused RAM. Whole droplet; swap is not included.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 8,
|
||||
"y": 0,
|
||||
"w": 8,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"lineWidth": 2,
|
||||
"fillOpacity": 10,
|
||||
"showPoints": "never",
|
||||
"spanNulls": false,
|
||||
"lineInterpolation": "linear",
|
||||
"thresholdsStyle": {
|
||||
"mode": "line+area"
|
||||
}
|
||||
},
|
||||
"unit": "bytes",
|
||||
"color": {
|
||||
"mode": "palette-classic"
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "red",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "orange",
|
||||
"value": 67108864
|
||||
},
|
||||
{
|
||||
"color": "green",
|
||||
"value": 134217728
|
||||
}
|
||||
]
|
||||
},
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
"showLegend": true
|
||||
},
|
||||
"tooltip": {
|
||||
"mode": "multi",
|
||||
"sort": "none"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "node_memory_MemAvailable_bytes{job=\"node\"}",
|
||||
"legendFormat": "Available",
|
||||
"range": true,
|
||||
"instant": false
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "node_memory_MemTotal_bytes{job=\"node\"}",
|
||||
"legendFormat": "Total RAM",
|
||||
"range": true,
|
||||
"instant": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"type": "timeseries",
|
||||
"title": "Root filesystem free space",
|
||||
"description": "Available bytes divided by size bytes for the host root filesystem (mountpoint /, ext4, /dev/vda1 seen through the /host mount), as a percent. The 15% line is the capacity alert threshold.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 0,
|
||||
"w": 8,
|
||||
"h": 8
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"lineWidth": 2,
|
||||
"fillOpacity": 10,
|
||||
"showPoints": "never",
|
||||
"spanNulls": false,
|
||||
"lineInterpolation": "linear",
|
||||
"thresholdsStyle": {
|
||||
"mode": "line+area"
|
||||
}
|
||||
},
|
||||
"unit": "percent",
|
||||
"color": {
|
||||
"mode": "palette-classic"
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "red",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "orange",
|
||||
"value": 15
|
||||
},
|
||||
{
|
||||
"color": "green",
|
||||
"value": 25
|
||||
}
|
||||
]
|
||||
},
|
||||
"min": 0,
|
||||
"max": 100
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
"showLegend": true
|
||||
},
|
||||
"tooltip": {
|
||||
"mode": "multi",
|
||||
"sort": "none"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "100 * node_filesystem_avail_bytes{job=\"node\",mountpoint=\"/\",fstype=\"ext4\"} / node_filesystem_size_bytes{job=\"node\",mountpoint=\"/\",fstype=\"ext4\"}",
|
||||
"legendFormat": "/ free %",
|
||||
"range": true,
|
||||
"instant": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"type": "timeseries",
|
||||
"title": "Gitea HTTPS availability",
|
||||
"description": "probe_success for https://git.pollefeys.dev/user/login: 1 when DNS, TLS, and an HTTP 200 login page all succeed within 10 s through Caddy, 0 otherwise. A gap means no probe result was collected (unknown, not up).",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 8,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"lineWidth": 2,
|
||||
"fillOpacity": 10,
|
||||
"showPoints": "never",
|
||||
"spanNulls": false,
|
||||
"lineInterpolation": "stepAfter",
|
||||
"thresholdsStyle": {
|
||||
"mode": "off"
|
||||
}
|
||||
},
|
||||
"unit": "none",
|
||||
"color": {
|
||||
"mode": "palette-classic"
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"mappings": [
|
||||
{
|
||||
"type": "value",
|
||||
"options": {
|
||||
"0": {
|
||||
"text": "DOWN",
|
||||
"color": "red"
|
||||
},
|
||||
"1": {
|
||||
"text": "UP",
|
||||
"color": "green"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
"showLegend": true
|
||||
},
|
||||
"tooltip": {
|
||||
"mode": "multi",
|
||||
"sort": "none"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "probe_success{job=\"https\",instance=\"https://git.pollefeys.dev/user/login\"}",
|
||||
"legendFormat": "Gitea",
|
||||
"range": true,
|
||||
"instant": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"type": "timeseries",
|
||||
"title": "Jenkins HTTPS availability",
|
||||
"description": "probe_success for https://ci.pollefeys.dev/login: 1 when DNS, TLS, and an HTTP 200 login page all succeed within 10 s through Caddy, 0 otherwise. A gap means no probe result was collected (unknown, not up).",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 8,
|
||||
"y": 8,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"lineWidth": 2,
|
||||
"fillOpacity": 10,
|
||||
"showPoints": "never",
|
||||
"spanNulls": false,
|
||||
"lineInterpolation": "stepAfter",
|
||||
"thresholdsStyle": {
|
||||
"mode": "off"
|
||||
}
|
||||
},
|
||||
"unit": "none",
|
||||
"color": {
|
||||
"mode": "palette-classic"
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"mappings": [
|
||||
{
|
||||
"type": "value",
|
||||
"options": {
|
||||
"0": {
|
||||
"text": "DOWN",
|
||||
"color": "red"
|
||||
},
|
||||
"1": {
|
||||
"text": "UP",
|
||||
"color": "green"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
"showLegend": true
|
||||
},
|
||||
"tooltip": {
|
||||
"mode": "multi",
|
||||
"sort": "none"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "probe_success{job=\"https\",instance=\"https://ci.pollefeys.dev/login\"}",
|
||||
"legendFormat": "Jenkins",
|
||||
"range": true,
|
||||
"instant": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"type": "timeseries",
|
||||
"title": "HTTPS probe duration",
|
||||
"description": "probe_duration_seconds for each login URL: total time of the probe, including DNS, TCP, TLS, and the HTTP response, as measured from the droplet itself.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 8,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"lineWidth": 2,
|
||||
"fillOpacity": 10,
|
||||
"showPoints": "never",
|
||||
"spanNulls": false,
|
||||
"lineInterpolation": "linear",
|
||||
"thresholdsStyle": {
|
||||
"mode": "line+area"
|
||||
}
|
||||
},
|
||||
"unit": "s",
|
||||
"color": {
|
||||
"mode": "palette-classic"
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "orange",
|
||||
"value": 2
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"value": 10
|
||||
}
|
||||
]
|
||||
},
|
||||
"min": 0
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
"showLegend": true
|
||||
},
|
||||
"tooltip": {
|
||||
"mode": "multi",
|
||||
"sort": "none"
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "probe_duration_seconds{job=\"https\"}",
|
||||
"legendFormat": "{{instance}}",
|
||||
"range": true,
|
||||
"instant": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"type": "stat",
|
||||
"title": "Scrape health (up)",
|
||||
"description": "Prometheus's own record of whether each scrape target answered: 1 = scraped, 0 = scrape failed. For the https job this says the probe ran, not that the site is up.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 15,
|
||||
"w": 24,
|
||||
"h": 4
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"mappings": [
|
||||
{
|
||||
"type": "value",
|
||||
"options": {
|
||||
"0": {
|
||||
"text": "DOWN",
|
||||
"color": "red"
|
||||
},
|
||||
"1": {
|
||||
"text": "UP",
|
||||
"color": "green"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"unit": "none",
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "red",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "green",
|
||||
"value": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"colorMode": "background",
|
||||
"graphMode": "none",
|
||||
"textMode": "value_and_name",
|
||||
"reduceOptions": {
|
||||
"calcs": [
|
||||
"lastNotNull"
|
||||
],
|
||||
"fields": "",
|
||||
"values": false
|
||||
},
|
||||
"justifyMode": "auto",
|
||||
"orientation": "auto"
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "up",
|
||||
"legendFormat": "{{job}} {{instance}}",
|
||||
"range": false,
|
||||
"instant": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
apiVersion: 1
|
||||
|
||||
# Grafana expands $NAME from its environment in provisioning files, so the
|
||||
# Discord webhook comes from grafana.secrets.env and never appears in Git.
|
||||
# Templates below use .Labels instead of $labels for the same reason.
|
||||
contactPoints:
|
||||
- orgId: 1
|
||||
name: team-alerts
|
||||
receivers:
|
||||
- uid: team-alerts-discord
|
||||
type: discord
|
||||
settings:
|
||||
url: $DISCORD_WEBHOOK_URL
|
||||
use_discord_username: false
|
||||
disableResolveMessage: false
|
||||
|
||||
# Every alert goes to team-alerts; one notification per rule and instance.
|
||||
policies:
|
||||
- orgId: 1
|
||||
receiver: team-alerts
|
||||
group_by: [grafana_folder, alertname, instance]
|
||||
group_wait: 30s
|
||||
group_interval: 1m
|
||||
repeat_interval: 4h
|
||||
|
||||
groups:
|
||||
- orgId: 1
|
||||
name: https-availability
|
||||
folder: Seat-Back Trivia SRE
|
||||
interval: 30s
|
||||
rules:
|
||||
- uid: https-unavailable
|
||||
title: HTTPS service unavailable
|
||||
condition: C
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: {from: 300, to: 0}
|
||||
datasourceUid: prometheus
|
||||
model:
|
||||
refId: A
|
||||
expr: probe_success{job="https"}
|
||||
instant: true
|
||||
range: false
|
||||
- refId: C
|
||||
datasourceUid: __expr__
|
||||
model:
|
||||
refId: C
|
||||
type: threshold
|
||||
expression: A
|
||||
conditions:
|
||||
- evaluator: {type: lt, params: [1]}
|
||||
# A missing probe series or a failed query is a monitoring failure,
|
||||
# not health: both fire the alert.
|
||||
noDataState: Alerting
|
||||
execErrState: Alerting
|
||||
for: 1m
|
||||
labels:
|
||||
severity: critical
|
||||
owner: CP
|
||||
annotations:
|
||||
summary: "{{ .Labels.instance }} has failed its HTTPS probe for at least 1 minute."
|
||||
description: "probe_success is 0, or the probe series is missing. Check the service container, Caddy, DNS, and the TLS certificate."
|
||||
runbook_url: https://git.pollefeys.dev/SeatBackTrivia/devops-manual/src/branch/master/devopsMonitoring.tex
|
||||
|
||||
- orgId: 1
|
||||
name: host-capacity
|
||||
folder: Seat-Back Trivia SRE
|
||||
interval: 1m
|
||||
rules:
|
||||
- uid: root-disk-low
|
||||
title: Root filesystem below 15% free
|
||||
condition: C
|
||||
data:
|
||||
- refId: A
|
||||
relativeTimeRange: {from: 600, to: 0}
|
||||
datasourceUid: prometheus
|
||||
model:
|
||||
refId: A
|
||||
expr: node_filesystem_avail_bytes{job="node",mountpoint="/",fstype="ext4"} / node_filesystem_size_bytes{job="node",mountpoint="/",fstype="ext4"}
|
||||
instant: true
|
||||
range: false
|
||||
- refId: C
|
||||
datasourceUid: __expr__
|
||||
model:
|
||||
refId: C
|
||||
type: threshold
|
||||
expression: A
|
||||
conditions:
|
||||
# Free-space threshold as a fraction. The capacity test raises
|
||||
# it temporarily; the final value is 0.15.
|
||||
- evaluator: {type: lt, params: [0.15]}
|
||||
noDataState: Alerting
|
||||
execErrState: Alerting
|
||||
for: 5m
|
||||
labels:
|
||||
severity: warning
|
||||
owner: NA
|
||||
annotations:
|
||||
summary: "Root filesystem on ssw-590 has had less than 15% free space for 5 minutes."
|
||||
description: "Check docker system df and du -sh /var/log; remove build cache and unused images, never named volumes."
|
||||
runbook_url: https://git.pollefeys.dev/SeatBackTrivia/devops-manual/src/branch/master/devopsMonitoring.tex
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: 1
|
||||
|
||||
# The dashboard JSON in Git is the source of truth; edits in the UI are refused.
|
||||
providers:
|
||||
- name: seat-back-trivia
|
||||
folder: Seat-Back Trivia SRE
|
||||
type: file
|
||||
disableDeletion: true
|
||||
allowUiUpdates: false
|
||||
options:
|
||||
path: /etc/grafana/dashboards
|
||||
@@ -0,0 +1,14 @@
|
||||
apiVersion: 1
|
||||
|
||||
# Grafana reaches Prometheus by its service name on the monitoring network.
|
||||
# localhost would mean the Grafana container itself.
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
editable: false
|
||||
jsonData:
|
||||
timeInterval: 30s
|
||||
@@ -0,0 +1,37 @@
|
||||
# Scrape and rule timing: every 30 s. Targets are container names on the
|
||||
# private monitoring network; none of these ports is published.
|
||||
global:
|
||||
scrape_interval: 30s
|
||||
evaluation_interval: 30s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
- targets: ["prometheus:9090"]
|
||||
|
||||
- job_name: node
|
||||
static_configs:
|
||||
- targets: ["node-exporter:9100"]
|
||||
|
||||
# Blackbox Exporter's own metrics, separate from the probes it runs.
|
||||
- job_name: blackbox
|
||||
static_configs:
|
||||
- targets: ["blackbox-exporter:9115"]
|
||||
|
||||
# HTTPS login-page probes through Caddy. Each URL becomes the probe target
|
||||
# and the instance label; the scrape itself goes to blackbox-exporter:9115.
|
||||
- job_name: https
|
||||
metrics_path: /probe
|
||||
params:
|
||||
module: [http_2xx]
|
||||
static_configs:
|
||||
- targets:
|
||||
- https://git.pollefeys.dev/user/login
|
||||
- https://ci.pollefeys.dev/login
|
||||
relabel_configs:
|
||||
- source_labels: [__address__]
|
||||
target_label: __param_target
|
||||
- source_labels: [__param_target]
|
||||
target_label: instance
|
||||
- target_label: __address__
|
||||
replacement: blackbox-exporter:9115
|
||||
Generated
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "seat-back-trivia",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "seat-back-trivia",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"ws": "8.18.3"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.18.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
|
||||
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "seat-back-trivia",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Minimal WebSocket quiz server for SeatBack Trivia",
|
||||
"scripts": {
|
||||
"test": "node --test"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": "8.18.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
__pycache__
|
||||
.venv
|
||||
.git
|
||||
*.pyc
|
||||
@@ -0,0 +1,12 @@
|
||||
FROM python:3.13-alpine3.23@sha256:e4aeaca9081549f19bd5bc8605ed5ab257ba34f97e0471f8e09161f45b4b08b8
|
||||
ARG APP_COMMIT=development
|
||||
ENV APP_COMMIT=$APP_COMMIT PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
# pip is not needed at runtime, and its bundled packages carry scanner findings.
|
||||
RUN pip install --no-cache-dir -r requirements.txt && python -m pip uninstall -y pip && rm -rf /usr/local/lib/python3.13/ensurepip
|
||||
COPY app.py .
|
||||
USER 10001:10001
|
||||
EXPOSE 8000
|
||||
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=3 CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=2)"
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "1", "--worker-tmp-dir", "/tmp", "app:app"]
|
||||
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
from flask import Flask, jsonify, request
|
||||
|
||||
app = Flask(__name__)
|
||||
VERSION = "v2"
|
||||
UNIT_PRICE = 12
|
||||
COMMIT = os.environ.get("APP_COMMIT", "development")
|
||||
|
||||
|
||||
def total_price(quantity):
|
||||
if quantity < 1 or quantity > 1000:
|
||||
raise ValueError("quantity must be between 1 and 1000")
|
||||
return UNIT_PRICE * quantity
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def index():
|
||||
return jsonify(service="Startup Pricing", version=VERSION, commit=COMMIT)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return jsonify(status="ok", version=VERSION)
|
||||
|
||||
|
||||
@app.get("/price")
|
||||
def price():
|
||||
try:
|
||||
quantity = int(request.args.get("quantity", "1"))
|
||||
total = total_price(quantity)
|
||||
except ValueError as error:
|
||||
return jsonify(error=str(error)), 400
|
||||
return jsonify(quantity=quantity, total=total, currency="USD")
|
||||
@@ -0,0 +1,9 @@
|
||||
blinker==1.9.0
|
||||
click==8.5.0
|
||||
Flask==3.1.3
|
||||
gunicorn==23.0.0
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
MarkupSafe==3.0.4
|
||||
packaging==26.3
|
||||
Werkzeug==3.1.9
|
||||
@@ -0,0 +1,25 @@
|
||||
import unittest
|
||||
from app import app, total_price
|
||||
|
||||
|
||||
class PricingTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.client = app.test_client()
|
||||
|
||||
def test_price(self):
|
||||
self.assertEqual(total_price(3), 36)
|
||||
response = self.client.get("/price?quantity=3")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json["total"], 36)
|
||||
|
||||
def test_invalid_quantity(self):
|
||||
for value in ["0", "-1", "1001", "abc", "1.5"]:
|
||||
self.assertEqual(self.client.get("/price?quantity=" + value).status_code, 400)
|
||||
|
||||
def test_release_identity(self):
|
||||
self.assertEqual(self.client.get("/").json["version"], "v2")
|
||||
self.assertEqual(self.client.get("/health").json["status"], "ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,15 @@
|
||||
const WebSocket = require('ws');
|
||||
|
||||
const PORT = process.env.PORT || 8080;
|
||||
const wss = new WebSocket.Server({ port: PORT });
|
||||
|
||||
const question = {
|
||||
question: 'What is the capital of France?',
|
||||
answer: 'Paris'
|
||||
};
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
ws.send(JSON.stringify(question));
|
||||
});
|
||||
|
||||
console.log(`SeatBack Trivia WebSocket server listening on port ${PORT}`);
|
||||
@@ -0,0 +1,11 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
test('sample trivia question has the expected answer', () => {
|
||||
const question = {
|
||||
question: 'What is the capital of France?',
|
||||
answer: 'Paris'
|
||||
};
|
||||
|
||||
assert.equal(question.answer, 'Paris');
|
||||
});
|
||||
Reference in New Issue
Block a user