Compare commits

..
2 Commits
Author SHA1 Message Date
Michael Kinder fd578807cd README: the apps check uses the status canary 2026-11-22 23:49:54 -05:00
Michael Kinder 26e2548dd5 Check apps in US East through the status canary
A small ntfy app ("Status canary" on Cottage's own account) now runs on the
Virginia servers, so the apps monitor checks its health endpoint: the whole
path a customer's app takes.
2026-11-22 23:49:43 -05:00
8 changed files with 31 additions and 116 deletions

No files matched your search

File renamed without changes.
@@ -5,8 +5,8 @@ on:
branches: ['main']
workflow_dispatch:
# Cottage (Gitea Actions): deploys only once the repository variable CLOUDFLARE_DEPLOY is "true" (set
# at launch, with the CLOUDFLARE_API_TOKEN secret). Until then a push to main does nothing.
# Cottage: deploys only once the repository variable CLOUDFLARE_DEPLOY is "true" (set at launch,
# with the CLOUDFLARE_API_TOKEN secret). Until then a push to main does nothing.
env:
WRANGLER_SEND_METRICS: 'false'
@@ -63,9 +63,6 @@ jobs:
run: |
npx @cloudflare/next-on-pages
- name: Install Python dependencies (the Gitea runner image lacks them)
run: pip install --quiet requests
- name: Create D1 database and tables
run: |
python3 deploy/init_d1.py # This sets D1_ID in GITHUB_ENV
@@ -107,8 +104,6 @@ jobs:
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
TF_VAR_CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
TF_VAR_APPS_US_EAST_TARGET: ${{ secrets.APPS_US_EAST_TARGET }}
TF_VAR_MATTERMOST_WEBHOOK: ${{ secrets.MATTERMOST_WEBHOOK }}
D1_ID: ${{ env.D1_ID }}
# Currently Terraform Cloudflare provider doesn't support direct upload, use wrangler to upload instead.
@@ -1,8 +1,9 @@
name: Upstream Sync
# Pulls the latest UptimeFlare code from github.com/lyc8503/UptimeFlare while keeping our
# uptime.config.ts. The push uses SYNC_TOKEN (an access token with write access to this
# repository) so that it starts the Deploy workflow like any other push to main.
permissions:
contents: write
actions: write
on:
workflow_dispatch:
inputs:
@@ -11,6 +12,9 @@ on:
type: boolean
required: true
default: false
override-token:
description: '[Optional] Paste a PAT here. If left blank, PAT_TOKEN secret will be used (if set). Used to solve `refusing to allow a GitHub App to create or update workflow... `, more info at https://github.com/lyc8503/UptimeFlare/wiki/Synchronize-updates-from-upstream#upgrade-methods'
required: false
jobs:
sync_latest_from_upstream:
@@ -19,9 +23,9 @@ jobs:
steps:
- name: Checkout target repo
uses: actions/checkout@v4
uses: actions/checkout@v3
with:
token: ${{ secrets.SYNC_TOKEN }}
token: ${{ inputs.override-token || secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Current config
run: |
@@ -29,9 +33,10 @@ jobs:
cp uptime.config.ts /tmp/origin.config.ts
- name: Sync upstream changes
id: sync
run: |
git config user.name "Cottage status sync"
git config user.email "[email protected]"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Fetch latest code
git clone https://github.com/lyc8503/UptimeFlare /tmp/latest
@@ -44,3 +49,9 @@ jobs:
git add .
git commit -m "Sync latest code from upstream"
git push
- name: Trigger deployment
if: ${{ inputs.override-token == '' }}
uses: benc-uk/workflow-dispatch@v1
with:
workflow: deploy.yml
+1 -1
View File
@@ -23,7 +23,7 @@ export default function Footer() {
<span>
Built on{' '}
<a href="https://github.com/lyc8503/UptimeFlare">UptimeFlare</a>, open source (
<a href="https://git.cottage.host/cottage/status">our copy</a>)
<a href="https://github.com/cottage-host/status">our copy</a>)
</span>
</div>
</div>
-21
View File
@@ -16,19 +16,6 @@ variable "CLOUDFLARE_ACCOUNT_ID" {
type = string
}
# Cottage: private monitor addresses (see `secret:` targets in uptime.config.ts).
variable "APPS_US_EAST_TARGET" {
# read from $TF_VAR_APPS_US_EAST_TARGET (the GitHub Actions secret of the same name)
type = string
sensitive = true
}
variable "MATTERMOST_WEBHOOK" {
# read from $TF_VAR_MATTERMOST_WEBHOOK (the GitHub Actions secret of the same name)
type = string
sensitive = true
}
variable "enable_do_migration" {
type = bool
default = false
@@ -72,14 +59,6 @@ resource "cloudflare_workers_script" "uptimeflare_worker" {
name = "UPTIMEFLARE_D1"
type = "d1"
id = cloudflare_d1_database.uptimeflare_d1.id
}, {
name = "APPS_US_EAST_TARGET"
type = "secret_text"
text = var.APPS_US_EAST_TARGET
}, {
name = "MATTERMOST_WEBHOOK"
type = "secret_text"
text = var.MATTERMOST_WEBHOOK
}]
}
+5 -18
View File
@@ -43,33 +43,20 @@ const workerConfig: WorkerConfig = {
headers: { 'User-Agent': 'cottage-status (+https://status.cottage.host)' },
},
{
// A real app running on the region's servers (on Cottage's own internal account), so this
// checks the whole path a customer's app takes: Cloudflare, the node's proxy, Harbor and a
// running container. Its address is private: the worker reads it from the Worker secret
// APPS_US_EAST_TARGET (GitHub Actions secret of the same name, bound in deploy.tf).
// A small app Cottage runs for itself on the region's servers (ntfy, "Status canary" on
// Cottage's own internal account), so this checks the whole path a customer's app takes:
// Cloudflare, the node's proxy, Harbor and a running container.
id: 'apps-us-east',
name: 'Apps in US East',
tooltip: 'Customer apps hosted in Virginia',
method: 'GET',
target: 'secret:APPS_US_EAST_TARGET',
target: 'https://status-canary-m7ec.cottagehost.com/v1/health',
expectedCodes: [200],
timeout: 10000,
headers: { 'User-Agent': 'cottage-status (+https://status.cottage.host)' },
},
],
// Down and back-up messages go to the founder's Mattermost (channel "alerts"). The webhook address
// is private: the worker reads it from the Worker secret MATTERMOST_WEBHOOK (GitHub Actions secret of
// the same name, bound in deploy.tf). Grafana Cloud (hearth infra/monitoring) alerts there too.
notification: {
webhook: {
url: 'secret:MATTERMOST_WEBHOOK',
payloadType: 'json',
payload: { text: '$MSG', username: 'Status' },
},
timeZone: 'Etc/UTC',
// Wait a few minutes before saying something is down, so a single failed check doesn't page.
gracePeriod: 3,
},
// Alerts come from Grafana Cloud (hearth infra/monitoring). A webhook here could page too.
}
// Notices shown on the page: incident updates and planned maintenance. Newest last.
+2 -35
View File
@@ -2,7 +2,7 @@ import { DurableObject } from 'cloudflare:workers'
import { MonitorTarget } from '../../types/config'
import { workerConfig } from '../../uptime.config'
import { doMonitor, getStatus } from './monitor'
import { formatAndNotify, getWorkerLocation, setWebhookSecrets } from './util'
import { formatAndNotify, getWorkerLocation } from './util'
import { CompactedMonitorStateWrapper, getFromStore, setToStore } from './store'
import pLimit from 'p-limit'
@@ -11,41 +11,8 @@ export interface Env {
UPTIMEFLARE_D1: D1Database
}
// Cottage: a monitor's target may be `secret:NAME`, read at check time from the Worker secret
// NAME (bound in deploy.tf from a GitHub Actions secret), so a private address never appears in
// this public repo. Error text is scrubbed of the address before it's stored or shown.
type CheckStatus = { ping: number; up: boolean; err: string }
function secretTarget(monitor: MonitorTarget, env: Env): { monitor: MonitorTarget; secret?: string } | { missing: string } {
if (!monitor.target.startsWith('secret:')) return { monitor }
const name = monitor.target.slice('secret:'.length)
const value = (env as unknown as Record<string, unknown>)[name]
if (typeof value !== 'string' || value === '') return { missing: name }
return { monitor: { ...monitor, target: value }, secret: value }
}
function scrub(status: CheckStatus, secret: string): CheckStatus {
let err = status.err
const parts = [secret]
try {
parts.push(new URL(secret).host, new URL(secret).hostname)
} catch {}
for (const p of parts) if (p) err = err.split(p).join('the app')
return { ...status, err }
}
async function checkMonitor(monitor: MonitorTarget, location: string, env: Env) {
const r = secretTarget(monitor, env)
if ('missing' in r) {
return { id: monitor.id, location, status: { ping: 0, up: false, err: `Check address not configured (${r.missing})` } }
}
const result = await doMonitor(r.monitor, location, env)
return r.secret ? { ...result, status: scrub(result.status, r.secret) } : result
}
const Worker = {
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
setWebhookSecrets(env)
const workerLocation = (await getWorkerLocation()) || 'ERROR'
console.log(`Running scheduled event on ${workerLocation}...`)
@@ -64,7 +31,7 @@ const Worker = {
let checkResult: Record<string, CheckResult> = {};
const limit = pLimit(5);
for (const monitor of workerConfig.monitors) {
checkQueue.push(limit(() => checkMonitor(monitor, workerLocation, env)))
checkQueue.push(limit(() => doMonitor(monitor, workerLocation, env)))
}
for (const result of await Promise.all(checkQueue)) {
checkResult[result.id] = result
+3 -27
View File
@@ -79,24 +79,6 @@ function templateWebhookPlayload(payload: any, message: string) {
}
}
// Cottage: a webhook url may be `secret:NAME`, read at send time from the Worker secret NAME (bound in
// deploy.tf from a GitHub Actions secret), so the address never appears in this public repo or the logs.
let webhookSecrets: Record<string, unknown> = {}
function setWebhookSecrets(env: object) {
webhookSecrets = env as Record<string, unknown>
}
function resolveWebhookUrl(url: string): string | undefined {
if (!url.startsWith('secret:')) return url
const value = webhookSecrets[url.slice('secret:'.length)]
return typeof value === 'string' && value !== '' ? value : undefined
}
function hideUrl(text: string, url: string, real: string): string {
return real === url ? text : text.split(real).join(url)
}
async function webhookNotify(webhook: WebhookConfig, message: string) {
if (Array.isArray(webhook)) {
for (const w of webhook) {
@@ -108,13 +90,8 @@ async function webhookNotify(webhook: WebhookConfig, message: string) {
console.log(
'Sending webhook notification: ' + JSON.stringify(message) + ' to webhook ' + webhook.url
)
const realUrl = resolveWebhookUrl(webhook.url)
if (realUrl === undefined) {
console.log(`Webhook address not configured (${webhook.url}), skipping notification`)
return
}
try {
let url = realUrl
let url = webhook.url
let method = webhook.method
let headers = new Headers(webhook.headers as any)
let payloadTemplated: { [key: string]: string | number } = JSON.parse(
@@ -151,7 +128,7 @@ async function webhookNotify(webhook: WebhookConfig, message: string) {
}
console.log(
`Webhook finalized parameters: ${method} ${hideUrl(url, webhook.url, realUrl)}, headers ${JSON.stringify(
`Webhook finalized parameters: ${method} ${url}, headers ${JSON.stringify(
Object.fromEntries(headers.entries())
)}, body ${JSON.stringify(body)}`
)
@@ -165,7 +142,7 @@ async function webhookNotify(webhook: WebhookConfig, message: string) {
console.log('Webhook notification sent successfully, code: ' + resp.status)
}
} catch (e) {
console.log('Error calling webhook server: ' + hideUrl(String(e), webhook.url, realUrl))
console.log('Error calling webhook server: ' + e)
}
}
@@ -221,5 +198,4 @@ export {
webhookNotify,
formatStatusChangeNotification,
formatAndNotify,
setWebhookSecrets,
}