mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-10 15:14:09 +00:00
lib/pushmetrics: fix a panic caused by pushing metrics during the graceful shutdown process of vmstorage nodes. (#5549)
Co-authored-by: zhangdongdong <zhangdongdong@kuaishou.com> Co-authored-by: Roman Khavronenko <roman@victoriametrics.com> Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
parent
4542d86819
commit
66bafee651
1 changed files with 13 additions and 1 deletions
|
@ -24,12 +24,24 @@ func init() {
|
|||
flagutil.RegisterSecretFlag("pushmetrics.url")
|
||||
}
|
||||
|
||||
var (
|
||||
// create a custom context for the pushmetrics module to close the metric reporting goroutine when the vmstorage process is shutdown.
|
||||
pushMetricsCtx, cancelPushMetric = context.WithCancel(context.Background())
|
||||
)
|
||||
|
||||
// Init must be called after logger.Init
|
||||
func Init() {
|
||||
extraLabels := strings.Join(*pushExtraLabel, ",")
|
||||
for _, pu := range *pushURL {
|
||||
if err := metrics.InitPushExt(pu, *pushInterval, extraLabels, appmetrics.WritePrometheusMetrics); err != nil {
|
||||
opts := &metrics.PushOptions{
|
||||
ExtraLabels: extraLabels,
|
||||
}
|
||||
if err := metrics.InitPushExtWithOptions(pushMetricsCtx, pu, *pushInterval, appmetrics.WritePrometheusMetrics, opts); err != nil {
|
||||
logger.Fatalf("cannot initialize pushmetrics: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func StopPushMetrics() {
|
||||
cancelPushMetric()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue