Metrics, dashboard and alert for posts (phase 3, step 9)
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 59s
CI / test (push) Successful in 2m53s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 59s
CI / test (push) Successful in 2m53s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
New counters: scrobbler_federation_posts_total{kind,visibility},
post_deletions_total{reason} (manual vs sharing_off), and
milestone_checks_total / weekly_total{result}, each incremented at a
single point (publish()/_delete(), and a thin public wrapper around
each module's check_and_post()) rather than at every call site.
Federation dashboard gains a "Posts" row: posts/min by kind and
visibility, deletions/min by reason, and weekly/milestone checks by
result - the same shape as the existing rows, so a stalled worker (all
zero) looks the same as one with nothing to do (all "disabled"/"none").
New alert FederationWeeklySummariesMissing, on scrobbler_worker_tasks_total
rather than the new weekly_total metric: weekly_total only increments
once check_all() reaches a real sharing user, so on a quiet instance
with nobody sharing yet it would sit at zero forever and false-alarm
immediately. worker_tasks_total counts every periodic run regardless of
whether there was anyone to check, matching the same pattern already
used by ImportWorkerDown and FederationInboxBacklog.
Verified deploy/prometheus/alerts.yml and prometheus.yml with promtool
(via the prom/prometheus image, matching CI's validate-monitoring job).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
0acce9b948
commit
de1519a066
9 files changed
+300
-8
No files matched your search
@@ -51,3 +51,23 @@ followers = Gauge(
|
||||
["state"],
|
||||
multiprocess_mode="max",
|
||||
)
|
||||
posts_total = Counter(
|
||||
"scrobbler_federation_posts_total",
|
||||
"Posts published: weekly summaries and milestones",
|
||||
["kind", "visibility"],
|
||||
)
|
||||
post_deletions_total = Counter(
|
||||
"scrobbler_federation_post_deletions_total",
|
||||
"Posts deleted, by reason",
|
||||
["reason"],
|
||||
)
|
||||
milestone_checks_total = Counter(
|
||||
"scrobbler_federation_milestone_checks_total",
|
||||
"Milestone checks, by result: disabled, none or posted",
|
||||
["result"],
|
||||
)
|
||||
weekly_total = Counter(
|
||||
"scrobbler_federation_weekly_total",
|
||||
"Weekly summary checks, by result: disabled, skipped_empty, already_posted or posted",
|
||||
["result"],
|
||||
)
|
||||
@@ -14,6 +14,7 @@ from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation import activities, followers, ids, sharing
|
||||
from scrobbler.federation import metrics as fed_metrics
|
||||
from scrobbler.federation.models import FederationActivity, FederationPost
|
||||
from scrobbler.federation.protocol import addressing, vocab
|
||||
|
||||
@@ -141,6 +142,7 @@ def publish(
|
||||
except IntegrityError: # posted with this key by a concurrent pass
|
||||
db.session.rollback()
|
||||
return None
|
||||
fed_metrics.posts_total.labels(kind=kind, visibility=settings.visibility).inc()
|
||||
return post
|
||||
|
||||
|
||||
@@ -150,7 +152,7 @@ def delete_post(user_id: int, username: str, post: FederationPost) -> Federation
|
||||
None if it's already deleted."""
|
||||
if post.deleted_at is not None:
|
||||
return None
|
||||
return _delete(user_id, username, post)
|
||||
return _delete(user_id, username, post, reason="manual")
|
||||
|
||||
|
||||
def delete_all_for(user_id: int, username: str) -> int:
|
||||
@@ -161,11 +163,13 @@ def delete_all_for(user_id: int, username: str) -> int:
|
||||
db.select(FederationPost).filter_by(user_id=user_id, deleted_at=None)
|
||||
).all()
|
||||
for post in posts:
|
||||
_delete(user_id, username, post)
|
||||
_delete(user_id, username, post, reason="sharing_off")
|
||||
return len(posts)
|
||||
|
||||
|
||||
def _delete(user_id: int, username: str, post: FederationPost) -> FederationActivity:
|
||||
def _delete(
|
||||
user_id: int, username: str, post: FederationPost, *, reason: str
|
||||
) -> FederationActivity:
|
||||
# The post's own visibility at the time it was posted, not the user's current
|
||||
# setting: a Delete has to reach whoever could have seen the Create.
|
||||
note_id = post.activity.document["object"]["id"]
|
||||
@@ -179,4 +183,5 @@ def _delete(user_id: int, username: str, post: FederationPost) -> FederationActi
|
||||
if inboxes:
|
||||
activities.queue(activity, inboxes)
|
||||
post.deleted_at = _now()
|
||||
fed_metrics.post_deletions_total.labels(reason=reason).inc()
|
||||
return activity
|
||||
@@ -12,6 +12,7 @@ never gets a burst of "congratulations" for plays from years ago.
|
||||
import logging
|
||||
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation import metrics as fed_metrics
|
||||
from scrobbler.federation import publishing, sharing
|
||||
from scrobbler.federation.models import FederationMilestoneMark, FederationPendingCheck
|
||||
from scrobbler.federation.protocol import content
|
||||
@@ -132,6 +133,12 @@ def check_and_post(user_id: int) -> str:
|
||||
"""For one user, post at most one milestone: the first of scrobble-count, top-10
|
||||
entry, or artist-plays (in that priority) that has a new, unmarked threshold to
|
||||
report. Returns a result: disabled, none or posted."""
|
||||
result = _check_and_post(user_id)
|
||||
fed_metrics.milestone_checks_total.labels(result=result).inc()
|
||||
return result
|
||||
|
||||
|
||||
def _check_and_post(user_id: int) -> str:
|
||||
settings = sharing.settings_for(user_id)
|
||||
if not (settings.enabled and settings.post_milestones):
|
||||
return "disabled"
|
||||
|
||||
@@ -11,6 +11,7 @@ import logging
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation import metrics as fed_metrics
|
||||
from scrobbler.federation import publishing, sharing
|
||||
from scrobbler.federation.models import FederationSettings
|
||||
from scrobbler.federation.protocol import content, schedule
|
||||
@@ -61,6 +62,12 @@ def build_content(count: int, top_artists: list, top_tracks: list) -> tuple[str,
|
||||
def check_and_post(settings: FederationSettings, now_utc: datetime) -> str:
|
||||
"""For one user's settings, post their most recent eligible week if it's due and not
|
||||
already posted. Returns a result: disabled, already_posted, skipped_empty or posted."""
|
||||
result = _check_and_post(settings, now_utc)
|
||||
fed_metrics.weekly_total.labels(result=result).inc()
|
||||
return result
|
||||
|
||||
|
||||
def _check_and_post(settings: FederationSettings, now_utc: datetime) -> str:
|
||||
if not settings.post_weekly_summary:
|
||||
return "disabled"
|
||||
user = accounts.get_user(settings.user_id)
|
||||
|
||||
Reference in new issue
Block a user