Skip to content

fix: keep the error counter when a worker initializes again - #21

Open
bwangll wants to merge 1 commit into
api7:mainfrom
bwangll:fix/0915_keep_error_counter_on_worker_respawn
Open

bwangll wants to merge 1 commit into
api7:mainfrom
bwangll:fix/0915_keep_error_counter_on_worker_respawn

Conversation

@bwangll

@bwangll bwangll commented Sep 15, 2026

Copy link
Copy Markdown

Problem

Prometheus.init() runs in every init_worker, including when nginx respawns a crashed worker. It sets nginx_metric_errors_total to 0 with dict:set, so a respawn wipes the errors already counted by all workers, and the counter goes backwards.

Fix

Create the counter with dict:add, which leaves an existing value untouched.

Tests

TestPrometheus:testInitKeepsErrorCount initializes the library again on a dict that already holds an error count and checks the count is kept. It fails without the fix.

init() runs in every init_worker, including a respawned worker's, so setting the error counter to 0 wiped errors already counted by the other workers. Only create it when it does not exist.
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: e07a073f-488d-45e3-80f4-25fd58a85128


Comment @coderabbitai help to get the list of available commands.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


bwang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants