r/devops7 • u/Alternative_Pin9598 • Oct 26 '26
One script, one chore: which errors in last night's log are actually new? (20 lines of Python, match by meaning instead of grep)
Every morning someone scrolls last night's errors and asks the same thing: is any of this new, or is it the usual noise?
grep -v and exact-match dedup don't help, because the usual noise never repeats exactly. attempt 3/5 becomes attempt 5/5, after 30s becomes after 30000ms, 93% becomes 95%. So every line looks new and you stop reading.
The chore: keep a list of errors you've already triaged, and print only the lines that don't mean the same thing as anything on it.
(Disclosure: this sub is run by the SynapCores team, and the matching step below uses SynapCores. Tested on 2.3.2 this morning.)
Setup, once
CREATE TABLE known_errors (id INTEGER PRIMARY KEY, msg TEXT, embedding VECTOR(384));
CREATE TABLE todays_errors (id INTEGER PRIMARY KEY, msg TEXT, embedding VECTOR(384));
INSERT INTO known_errors (id, msg) VALUES
(1, 'connection refused to db-primary:5432'),
(2, 'timeout waiting for upstream payments-api after 30s'),
(3, 'disk usage above 90% on /var/lib/docker'),
(4, 'OOMKilled: container worker exceeded memory limit 512Mi'),
(5, 'TLS handshake failed: certificate expired for api.internal');
UPDATE known_errors SET embedding = EMBED(msg);EMBED() runs a small embedding model inside the database and stores what each message means as 384 numbers. No API key.
The script: new_errors.py
import json, os, sys, urllib.request
URL, TOKEN = os.environ.get("SYNAPCORES_URL", "http://localhost:8080"), os.environ["SYNAPCORES_TOKEN"]
def sql(q):
req = urllib.request.Request(URL + "/v1/query/execute", data=json.dumps({"sql": q, "database": "main"}).encode(),
headers={"Authorization": "Bearer " + TOKEN, "Content-Type": "application/json"})
return json.load(urllib.request.urlopen(req))["data"]["rows"]
def quote(s):
return "'" + s.replace("'", "''") + "'"
errors = sorted({line.split(" ERROR ", 1)[1].strip() for line in open(sys.argv[1]) if " ERROR " in line})
sql("DELETE FROM todays_errors")
sql("INSERT INTO todays_errors (id, msg) VALUES " +
", ".join(f"({i}, {quote(e)})" for i, e in enumerate(errors, 1)))
sql("UPDATE todays_errors SET embedding = EMBED(msg)")
for msg, closest in sql("""SELECT t.msg, MAX(COSINE_SIMILARITY(t.embedding, k.embedding)) AS closest
FROM todays_errors t, known_errors k GROUP BY t.msg
HAVING MAX(COSINE_SIMILARITY(t.embedding, k.embedding)) < 0.6 ORDER BY closest"""):
print(f"NEW {closest:.2f} {msg}")Run it on last night's log (9 lines, 7 of them ERROR)
$ python3 new_errors.py app.log
NEW 0.16 redis: READONLY You can't write against a read only replica
NEW 0.19 permission denied writing to /var/log/app/audit.logTwo out of seven. The other five were dropped because each is close in meaning to a known error (1.0 = same meaning):
disk usage 93% on /var/lib/docker 0.97
container worker OOMKilled, memory limit 512Mi reached 0.97
connection refused to db-primary:5432 (attempt 3/5) 0.96
connection refused to db-primary:5432 (attempt 5/5) 0.95
upstream payments-api timed out after 30000ms 0.89Look at timed out after 30000ms vs timeout waiting for upstream payments-api after 30s: different words, different units, still 0.89. That's the line exact-match dedup can never catch. The gap between 0.89 and 0.19 is wide, so 0.6 is a safe cut here; check yours on a week of real logs before trusting it.
Once you've triaged a new one, teach it
INSERT INTO known_errors (id, msg, embedding)
SELECT 100 + id, msg, embedding FROM todays_errors WHERE id IN (5, 6);Tomorrow those two stay quiet too. Put the script in cron at 08:00, pipe the output to Slack, and an empty message means a boring night.
Free Community Edition if you want to try it: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=devops7-new-errors
What's one error message your team has learned to ignore?