| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package sd |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/plugin/framework/dyncfg" |
| 9 | ) |
| 10 | |
| 11 | const sdShuttingDownMsg = "Service discovery is shutting down." |
| 12 | |
| 13 | // enqueueDyncfgFunction blocks until the function is accepted by the run loop |
| 14 | // or service discovery shuts down. We deliberately do NOT honor a per-function |
| 15 | // timeout here: dropping an awaited enable/disable would wedge the wait gate |
| 16 | // (since waitDecisionTimeout was removed) because the caller would keep |
| 17 | // waiting for a decision that can never be produced. Back-pressure flows |
| 18 | // upstream to netdata via the OS pipe. |
| 19 | func (d *ServiceDiscovery) enqueueDyncfgFunction(fn dyncfg.Function) { |
| 20 | ctx := d.ctx |
| 21 | if ctx == nil { |
| 22 | ctx = context.Background() |
| 23 | } |
| 24 | select { |
| 25 | case d.dyncfgCh <- fn: |
| 26 | case <-ctx.Done(): |
| 27 | d.dyncfgApi.SendCodef(fn, 503, sdShuttingDownMsg) |
| 28 | } |
| 29 | } |