From e8c09d7b640f69317ef34e605e827afaf2d574b8 Mon Sep 17 00:00:00 2001 From: hectorzhao Date: Tue, 1 Sep 2026 10:26:07 +0800 Subject: [PATCH] fix: baseline analytics counters on planned release restart --- infra/server-b/caller-analytics/deploy.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/infra/server-b/caller-analytics/deploy.sh b/infra/server-b/caller-analytics/deploy.sh index 58a78cd..a759298 100644 --- a/infra/server-b/caller-analytics/deploy.sh +++ b/infra/server-b/caller-analytics/deploy.sh @@ -23,6 +23,8 @@ if systemctl --quiet is-active lisglosips-caller-analytics-redis.service && test cp -a /var/lib/redis-caller-analytics "$backup/redis-caller-analytics" fi cp -a /etc/opensips/opensips.cfg "$backup/opensips.cfg" +checkpoint_file=/var/lib/lisglosips/caller-analytics-offset.json +if test -f "$checkpoint_file"; then cp -a "$checkpoint_file" "$backup/caller-analytics-offset.json"; fi printf '%s\n' "$old" > "$backup/previous-release" managed_files=(/etc/lisglosips/caller-analytics.env /etc/rsyslog.d/35-caller-analytics.conf /etc/redis/caller-analytics.conf /etc/systemd/system/lisglosips-caller-analytics-redis.service /etc/logrotate.d/lisglosips-caller-analytics /etc/systemd/system/lisglosips-caller-analytics-maintenance.service /etc/systemd/system/lisglosips-caller-analytics-maintenance.timer /etc/systemd/system/lisglosips.target) for file in "${managed_files[@]}"; do @@ -43,6 +45,7 @@ rollback() { systemctl stop lisglosips@caller-analytics || true systemctl stop lisglosips-caller-analytics-maintenance.timer lisglosips-caller-analytics-redis || true cp -a "$backup/opensips.cfg" /etc/opensips/opensips.cfg + if test -f "$backup/caller-analytics-offset.json"; then cp -a "$backup/caller-analytics-offset.json" "$checkpoint_file"; fi for file in "${managed_files[@]}"; do if test -f "$backup/$(basename "$file")"; then cp -a "$backup/$(basename "$file")" "$file"; else rm -f "$file"; fi done @@ -114,6 +117,24 @@ chmod -R u=rwX,g=rX,o= "$new/apps/api/dist" "$new/apps/worker-cdr/dist" "$new/pa systemctl restart rsyslog install -o root -g root -m 0644 "$new/opensips-candidate.cfg" /etc/opensips/opensips.cfg ln -sfn "$new" /opt/lisglosips/current +systemctl stop lisglosips@caller-analytics +# This is a coordinated producer restart after the spool is quiescent. Reset +# only the per-process reconciliation baseline; preserve any pre-existing gap. +if test -f "$checkpoint_file"; then + python3 - "$checkpoint_file" <<'PY' +import json, os, sys +p=sys.argv[1]; st=os.stat(p) +with open(p,encoding='utf-8') as f: data=json.load(f) +spool='/var/log/lisglosips/caller-analytics.log' +assert int(data.get('offset',-1)) == os.path.getsize(spool), 'analytics spool is not quiescent' +produced=data.get('lastProducerCount'); collected=data.get('eventsSinceProducerStart') +assert produced is None or produced == collected, 'producer/collector counters differ before planned restart' +data.pop('lastProducerCount',None); data['eventsSinceProducerStart']=0 +t=p+'.deploy-tmp' +with open(t,'w',encoding='utf-8') as f: json.dump(data,f,separators=(',',':')) +os.chown(t,st.st_uid,st.st_gid); os.chmod(t,st.st_mode); os.replace(t,p) +PY +fi systemctl restart opensips lisglosips@api systemctl enable --now lisglosips@caller-analytics systemctl restart lisglosips@caller-analytics