prometheus / prometheus/exporter-toolkit

Signal handling

Open
#152 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
311
Forks
109
Avg merge
3d 59m
Merged PRs (30d)
6

Description

Would like to see signal processing for SIGQUIT and SIGTERM in subsequent versions for proper systemd unit operation. Currently, the systemd unit transitions to a failed state after stopping the service.
Here is a short patch for version 0.21.0:

--- main.go.orig    2023-05-24 16:14:47.781711964 +0300
+++ main.go 2023-05-24 14:09:05.000000000 +0300
@@ -181,6 +181,22 @@
    hup := make(chan os.Signal, 1)
    reloadCh = make(chan chan error)
    signal.Notify(hup, syscall.SIGHUP)
+   term_chan := make(chan os.Signal, 1)
+   signal.Notify(term_chan, syscall.SIGTERM, syscall.SIGQUIT)
+   go func(s <-chan os.Signal) {
+       for {
+           sig := <-s
+           switch sig {
+           case syscall.SIGTERM:
+               level.Info(logger).Log("msg", "Got SIGTERM. Exiting")
+               os.Exit(0)
+           case syscall.SIGQUIT:
+               level.Info(logger).Log("msg", "Got SIGQUIT. Exiting")
+               os.Exit(0)
+           }
+       }
+   }(term_chan)
+
    go func() {
        for {
            select {

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in main.go around the signal setup near line 181 and review the provided patch in the issue. Confirm the service handles SIGTERM and SIGQUIT as intended, then verify that stopping the systemd unit no longer leaves it in a failed state.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
operating-systems
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.