Persistent logs, no health checks in them, and softer copy
Backend and the workers also write their log as JSON into the logs volume, one file a day kept 30 days (LOG_DIR, LOG_NAME, LOG_KEEP_DAYS), so errors can be looked up after a container is replaced. The Docker health check (/healthz every 30 s) no longer goes into the request log of the backend and the horoscope API. The home, login and packages pages no longer compare the analyses to an experienced astrologer's depth; they say what the user gets: detailed, personal text in minutes, for a fraction of a personal consultation's price. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
Generated
+29
@@ -337,6 +337,15 @@ version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.3.14"
|
||||
@@ -1855,6 +1864,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
@@ -2197,6 +2207,12 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "symlink"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
@@ -2421,6 +2437,19 @@ dependencies = [
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-appender"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "050686193eb999b4bb3bc2acfa891a13da00f79734704c4b8b4ef1a10b368a3c"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"symlink",
|
||||
"thiserror",
|
||||
"time",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.31"
|
||||
|
||||
@@ -53,6 +53,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "signal
|
||||
tower-http = { version = "0.6", features = ["trace", "cors"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
|
||||
tracing-appender = "0.2"
|
||||
|
||||
[profile.release]
|
||||
lto = "thin"
|
||||
|
||||
@@ -11,3 +11,4 @@ anyhow.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
tracing-appender.workspace = true
|
||||
|
||||
@@ -3,21 +3,51 @@
|
||||
//! Environment:
|
||||
//! * `BIND_ADDR` listen address (each service has its own default)
|
||||
//! * `LOG_FORMAT` `text` (default) or `json`; `RUST_LOG` sets the level
|
||||
//! * `LOG_DIR` also write the log there, as JSON, one file a day
|
||||
//! (`<LOG_NAME>.YYYY-MM-DD.log`), keeping `LOG_KEEP_DAYS` (default 30) files
|
||||
//! * `LOG_NAME` the file name prefix (default: the service's name)
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Context;
|
||||
|
||||
/// Initializes `tracing` from `RUST_LOG` and `LOG_FORMAT`.
|
||||
pub fn init_logging() {
|
||||
use tracing_subscriber::EnvFilter;
|
||||
/// Days of log files kept in `LOG_DIR` by default.
|
||||
const LOG_KEEP_DAYS: usize = 30;
|
||||
|
||||
/// Initializes `tracing` from `RUST_LOG` and `LOG_FORMAT`, and the log files
|
||||
/// in `LOG_DIR` (named after `LOG_NAME`, else `name`), so the log outlives the
|
||||
/// container.
|
||||
pub fn init_logging(name: &str) {
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
use tracing_subscriber::{EnvFilter, Layer, fmt};
|
||||
|
||||
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info,tower_http=info"));
|
||||
let builder = tracing_subscriber::fmt().with_env_filter(filter);
|
||||
if std::env::var("LOG_FORMAT").is_ok_and(|f| f.eq_ignore_ascii_case("json")) {
|
||||
builder.json().init();
|
||||
} else {
|
||||
builder.init();
|
||||
let json = std::env::var("LOG_FORMAT").is_ok_and(|f| f.eq_ignore_ascii_case("json"));
|
||||
let stdout = if json { fmt::layer().json().boxed() } else { fmt::layer().boxed() };
|
||||
let mut problem = None;
|
||||
let file = std::env::var("LOG_DIR").ok().filter(|d| !d.trim().is_empty()).and_then(|dir| {
|
||||
let prefix =
|
||||
std::env::var("LOG_NAME").ok().filter(|n| !n.trim().is_empty()).unwrap_or_else(|| name.to_string());
|
||||
let keep = std::env::var("LOG_KEEP_DAYS").ok().and_then(|d| d.parse().ok()).unwrap_or(LOG_KEEP_DAYS);
|
||||
let appender = tracing_appender::rolling::Builder::new()
|
||||
.rotation(tracing_appender::rolling::Rotation::DAILY)
|
||||
.filename_prefix(prefix)
|
||||
.filename_suffix("log")
|
||||
.max_log_files(keep.max(1))
|
||||
.build(&dir);
|
||||
match appender {
|
||||
Ok(appender) => Some(fmt::layer().json().with_ansi(false).with_writer(appender).boxed()),
|
||||
Err(e) => {
|
||||
problem = Some(format!("cannot write the log files in {dir}: {e}"));
|
||||
None
|
||||
}
|
||||
}
|
||||
});
|
||||
tracing_subscriber::registry().with(filter).with(stdout).with(file).init();
|
||||
if let Some(problem) = problem {
|
||||
tracing::warn!("{problem}; logging to stdout only");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -82,7 +82,8 @@ A Google OAuth kliensnél a `https://sorsfonalak.hu` címet fel kell venni az en
|
||||
|
||||
## Üzemeltetés
|
||||
|
||||
- Naplók: `docker compose logs -f backend worker worker-ai`
|
||||
- Naplók élőben: `docker compose logs -f backend worker worker-ai` (ez a konténer újraindításáig/cseréjéig él).
|
||||
- Naplók utólag: a backend és a két worker JSON-sorokat ír a `logs` volume-ba is, naponta új fájlba (`backend.2026-11-20.log`, `worker…`, `worker-ai…`), 30 napig megőrizve (`LOG_DIR`, `LOG_KEEP_DAYS`, `LOG_NAME`). A fájlok helye a szerveren: `docker volume inspect -f '{{.Mountpoint}}' sorsfonalak_logs`, például `grep -h '"level":"ERROR"' /var/lib/docker/volumes/sorsfonalak_logs/_data/backend.*.log | tail`. A Docker 30 másodpercenkénti `/healthz` ellenőrzése nem kerül a naplóba.
|
||||
- A worker két konténerben fut, ugyanabból az image-ből: a `worker` küldi az e-maileket és takarít (`WORKER_TASKS=email,cleanup`, ide kerülnek a további háttérfeladatok is), a `worker-ai` írja az elemzéseket és a válaszokat (`WORKER_TASKS=analyses`, gyors és lassú sáv). A sávok mérete a szerver `.env` fájljában állítható (`QUICK_CONCURRENCY`, `ANALYSIS_CONCURRENCY`).
|
||||
- Visszaállás korábbi verzióra: `.env`-ben `TAG=<régebbi hash>`, utána `docker compose up -d`
|
||||
- Mentés: naponta egy `pg_dump` a `/opt/sorsfonalak/backups` mappába, 14 napig megmarad. A mentéseket érdemes a szerverről is elvinni (DigitalOcean backup, vagy `rsync` otthonra).
|
||||
|
||||
@@ -103,6 +103,9 @@ services:
|
||||
FREE_PERSON_SLOTS: ${FREE_PERSON_SLOTS:-0}
|
||||
# invite: new accounts need an invitation (admin page "Meghívók"); open: anyone.
|
||||
SIGNUP_MODE: ${SIGNUP_MODE:-invite}
|
||||
# The log also goes to the logs volume, one file a day, kept 30 days
|
||||
# (deploy/README.md: Logs).
|
||||
LOG_DIR: /logs
|
||||
# STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET (docs/fizetes.md): with them
|
||||
# packages can be bought (a test key: by admins only).
|
||||
env_file:
|
||||
@@ -114,6 +117,8 @@ services:
|
||||
horoscope-api:
|
||||
condition: service_healthy
|
||||
read_only: true
|
||||
volumes:
|
||||
- logs:/logs
|
||||
logging: *logging
|
||||
restart: unless-stopped
|
||||
|
||||
@@ -128,6 +133,7 @@ services:
|
||||
SES_REGION: ${SES_REGION:-eu-central-1}
|
||||
MAIL_FROM: ${MAIL_FROM:-Sorsfonalak <hello@sorsfonalak.hu>}
|
||||
PUBLIC_BASE_URL: https://${DOMAIN}
|
||||
LOG_DIR: /logs
|
||||
env_file:
|
||||
- path: .env.secrets
|
||||
required: false
|
||||
@@ -135,6 +141,8 @@ services:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
read_only: true
|
||||
volumes:
|
||||
- logs:/logs
|
||||
logging: *logging
|
||||
restart: unless-stopped
|
||||
|
||||
@@ -148,6 +156,8 @@ services:
|
||||
QUICK_CONCURRENCY: ${QUICK_CONCURRENCY:-2}
|
||||
ANALYSIS_CONCURRENCY: ${ANALYSIS_CONCURRENCY:-4}
|
||||
PUBLIC_BASE_URL: https://${DOMAIN}
|
||||
LOG_DIR: /logs
|
||||
LOG_NAME: worker-ai
|
||||
env_file:
|
||||
- path: .env.secrets
|
||||
required: false
|
||||
@@ -155,6 +165,8 @@ services:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
read_only: true
|
||||
volumes:
|
||||
- logs:/logs
|
||||
logging: *logging
|
||||
restart: unless-stopped
|
||||
|
||||
@@ -177,5 +189,7 @@ services:
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
# Backend and worker logs (backend.YYYY-MM-DD.log, worker…, worker-ai…).
|
||||
logs:
|
||||
caddy-data:
|
||||
caddy-config:
|
||||
|
||||
@@ -16,10 +16,13 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
|
||||
--mount=type=cache,target=/app/target,sharing=locked \
|
||||
cargo build --release --locked -p backend \
|
||||
&& cp target/release/backend /backend
|
||||
# The log directory (LOG_DIR); a volume mounted here takes over its owner.
|
||||
RUN mkdir /logs
|
||||
|
||||
# --- 2. runtime: the binary only (TLS roots are compiled in via webpki-roots) ---
|
||||
FROM scratch
|
||||
COPY --from=build /backend /backend
|
||||
COPY --from=build --chown=65532:65532 /logs /logs
|
||||
ENV BIND_ADDR=0.0.0.0:8081 \
|
||||
LOG_FORMAT=json \
|
||||
RUST_LOG=info
|
||||
|
||||
@@ -66,7 +66,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
if std::env::args().nth(1).as_deref() == Some("healthcheck") {
|
||||
return service_kit::healthcheck(addr);
|
||||
}
|
||||
service_kit::init_logging();
|
||||
service_kit::init_logging("backend");
|
||||
let config = Config::from_env()?;
|
||||
let pool = db::connect(&config.database_url).await.context("connecting to the database")?;
|
||||
db::migrate(&pool).await.context("running database migrations")?;
|
||||
|
||||
@@ -60,7 +60,6 @@ where
|
||||
|
||||
pub fn router(state: Arc<AppState>) -> Router {
|
||||
Router::new()
|
||||
.route("/healthz", get(health))
|
||||
.route("/v1/config", get(public_config))
|
||||
.route("/v1/packages", get(payments::catalog))
|
||||
// login
|
||||
@@ -146,6 +145,8 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
|
||||
.on_response(DefaultOnResponse::new().level(Level::INFO)),
|
||||
)
|
||||
// After the layers: the Docker health check (every 30 s) stays out of the log.
|
||||
.route("/healthz", get(health))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,8 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) {
|
||||
belőle. Megmutatjuk, mit hoz az éved, és mennyire illetek össze azzal, akit szeretsz.
|
||||
</p>
|
||||
<p className="ai-line lp-ai-line lp-rise lp-r3">
|
||||
Részletes elemzések a legfejlettebb AI-modellekkel: egy tapasztalt asztrológushoz közelítő mélység, töredék
|
||||
áron.
|
||||
Részletes, személyre szóló elemzések a legfejlettebb AI-modellekkel: percek alatt, egy személyes konzultáció
|
||||
árának töredékéért.
|
||||
</p>
|
||||
<div className="lp-actions lp-rise lp-r4">
|
||||
<Link href="/belepes" className="btn btn-primary lp-btn">
|
||||
@@ -142,7 +142,7 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) {
|
||||
<div className="lp-intro">
|
||||
<span className="eyebrow">Miért más?</span>
|
||||
<h2 id="why-title" className="lp-h2">
|
||||
Egy asztrológus mélysége, töredék áron
|
||||
Alapos elemzés, töredék áron
|
||||
</h2>
|
||||
</div>
|
||||
<ul className="lp-why-grid">
|
||||
@@ -163,10 +163,10 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) {
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 3v5M12 16v5M3 12h5M16 12h5" />
|
||||
</svg>
|
||||
<h3 className="lp-step-title">Asztrológusi mélység</h3>
|
||||
<h3 className="lp-step-title">Az egész képletet olvassa</h3>
|
||||
<p className="lp-small">
|
||||
A bolygókat jegyükben, házukban, fényszögeikben és uralkodóik láncolatában olvassa, a holdcsomópontokkal és
|
||||
az év tranzitjaival együtt, ahogy egy tapasztalt asztrológus is tenné.
|
||||
az év tranzitjaival együtt: nem egy-egy fényállást, hanem az összefüggéseket.
|
||||
</p>
|
||||
</li>
|
||||
<li className="card lp-why-card">
|
||||
|
||||
@@ -96,8 +96,8 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis
|
||||
Születési képlet, szinasztria és közösség – egy helyen.
|
||||
</p>
|
||||
<p className="ai-line" style={{ fontSize: 15 }}>
|
||||
Részletes elemzések a legfejlettebb AI-modellekkel: egy tapasztalt asztrológushoz közelítő mélység, töredék
|
||||
áron.
|
||||
Részletes, személyre szóló elemzések a legfejlettebb AI-modellekkel: percek alatt, egy személyes konzultáció
|
||||
árának töredékéért.
|
||||
</p>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
return {
|
||||
title: { absolute: "Sorsfonalak – születési képlet, éves előrejelzés, kapcsolati összevetés" },
|
||||
description:
|
||||
"Percre pontos születési képlet és személyre szóló elemzés a legfejlettebb AI-modellekkel: egy tapasztalt asztrológushoz közelítő mélység, töredék áron. Éves előrejelzés, kapcsolati összevetés és kártyajóslás.",
|
||||
"Percre pontos születési képlet és személyre szóló elemzés a legfejlettebb AI-modellekkel, percek alatt és töredék áron. Éves előrejelzés, kapcsolati összevetés és kártyajóslás.",
|
||||
alternates: { canonical: `${base}/` },
|
||||
openGraph: { type: "website", siteName: "Sorsfonalak", locale: "hu_HU", url: `${base}/`, title, description, images: [image] },
|
||||
twitter: { card: "summary_large_image", title, description, images: [image.url] },
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
/** Shown where people decide: the analyses are written by top AI models (never named: a business secret). */
|
||||
export const AI_SHORT =
|
||||
"A legfejlettebb AI-modellek írják: egy tapasztalt asztrológus írásos elemzéséhez közelítő mélység, töredék áron.";
|
||||
"A legfejlettebb AI-modellek írják a képleted pontos adataiból: alapos, személyre szabott elemzés percek alatt, egy személyes konzultáció árának töredékéért.";
|
||||
|
||||
/** A highlighted note on the analysis quality. */
|
||||
export function AiNote() {
|
||||
return (
|
||||
<section className="card ai-note" aria-labelledby="ai-note-title">
|
||||
<span className="eyebrow">Az elemzésekről</span>
|
||||
<h2 id="ai-note-title">Profi mélység, töredék áron</h2>
|
||||
<h2 id="ai-note-title">Alapos elemzés, töredék áron</h2>
|
||||
<p className="muted">
|
||||
Az elemzéseket a legfejlettebb AI-modellek írják, a képleted pontos pozícióiból. Részletességben és
|
||||
árnyaltságban megközelítik egy tapasztalt asztrológus írásos elemzését, annak az árnak a töredékéért.
|
||||
Az elemzéseket a legfejlettebb AI-modellek írják, a képleted csillagászati pontosságú adataiból. Részletes,
|
||||
személyre szabott szöveget kapsz percek alatt, egy személyes konzultáció árának töredékéért, és amit nem értesz,
|
||||
arra rá is kérdezhetsz.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -54,7 +54,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
if std::env::args().nth(1).as_deref() == Some("healthcheck") {
|
||||
return service_kit::healthcheck(addr);
|
||||
}
|
||||
service_kit::init_logging();
|
||||
service_kit::init_logging("horoscope-api");
|
||||
let state = Arc::new(tokio::task::spawn_blocking(load_state).await??);
|
||||
let app = routes::router(state);
|
||||
let listener = tokio::net::TcpListener::bind(addr).await.with_context(|| format!("binding {addr}"))?;
|
||||
|
||||
@@ -22,7 +22,6 @@ type AppResult<T> = Result<Json<T>, ApiError>;
|
||||
|
||||
pub fn router(state: Arc<AppState>) -> Router {
|
||||
Router::new()
|
||||
.route("/healthz", get(health))
|
||||
.route("/v1/info", get(info))
|
||||
.route("/v1/countries", get(countries))
|
||||
.route("/v1/places", get(places))
|
||||
@@ -36,6 +35,8 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
|
||||
.on_response(DefaultOnResponse::new().level(Level::INFO)),
|
||||
)
|
||||
// After the layers: the Docker health check (every 30 s) stays out of the log.
|
||||
.route("/healthz", get(health))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,13 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
|
||||
--mount=type=cache,target=/app/target,sharing=locked \
|
||||
cargo build --release --locked -p worker \
|
||||
&& cp target/release/worker /worker
|
||||
# The log directory (LOG_DIR); a volume mounted here takes over its owner.
|
||||
RUN mkdir /logs
|
||||
|
||||
# --- 2. runtime: the binary only (TLS roots are compiled in via webpki-roots) ---
|
||||
FROM scratch
|
||||
COPY --from=build /worker /worker
|
||||
COPY --from=build --chown=65532:65532 /logs /logs
|
||||
ENV BIND_ADDR=0.0.0.0:8082 \
|
||||
LOG_FORMAT=json \
|
||||
RUST_LOG=info
|
||||
|
||||
@@ -84,12 +84,12 @@ async fn main() -> anyhow::Result<()> {
|
||||
match std::env::args().nth(1).as_deref() {
|
||||
Some("healthcheck") => return service_kit::healthcheck(addr),
|
||||
Some("compare-models") => {
|
||||
service_kit::init_logging();
|
||||
service_kit::init_logging("worker");
|
||||
return compare::main(std::env::args().skip(2).collect()).await;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
service_kit::init_logging();
|
||||
service_kit::init_logging("worker");
|
||||
let config = Config::from_env()?;
|
||||
let pool = db::connect(&config.database_url).await.context("connecting to the database")?;
|
||||
db::migrate(&pool).await.context("running database migrations")?;
|
||||
|
||||
Reference in New Issue
Block a user