mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/pushmetrics: wait until the background goroutines, which push metrics, are stopped at pushmetrics.Stop()
Previously the was a race condition when the background goroutine still could try collecting metrics
from already stopped resources after returning from pushmetrics.Stop().
Now the pushmetrics.Stop() waits until the background goroutine is stopped before returning.
This is a follow-up for https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5549
and the commit fe2d9f6646
.
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5548
This commit is contained in:
parent
978faf571d
commit
4f3764b140
10 changed files with 23 additions and 20 deletions
|
@ -94,7 +94,6 @@ func main() {
|
||||||
remotewrite.InitSecretFlags()
|
remotewrite.InitSecretFlags()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
if promscrape.IsDryRun() {
|
if promscrape.IsDryRun() {
|
||||||
if err := promscrape.CheckConfig(); err != nil {
|
if err := promscrape.CheckConfig(); err != nil {
|
||||||
|
@ -142,8 +141,10 @@ func main() {
|
||||||
}
|
}
|
||||||
logger.Infof("started vmagent in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("started vmagent in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
|
|
||||||
|
pushmetrics.Init()
|
||||||
sig := procutil.WaitForSigterm()
|
sig := procutil.WaitForSigterm()
|
||||||
logger.Infof("received signal %s", sig)
|
logger.Infof("received signal %s", sig)
|
||||||
|
pushmetrics.Stop()
|
||||||
|
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
if len(*httpListenAddr) > 0 {
|
if len(*httpListenAddr) > 0 {
|
||||||
|
@ -154,7 +155,6 @@ func main() {
|
||||||
logger.Infof("successfully shut down the webservice in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully shut down the webservice in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
pushmetrics.Stop()
|
|
||||||
promscrape.Stop()
|
promscrape.Stop()
|
||||||
|
|
||||||
if len(*influxListenAddr) > 0 {
|
if len(*influxListenAddr) > 0 {
|
||||||
|
|
|
@ -93,7 +93,6 @@ func main() {
|
||||||
datasource.InitSecretFlags()
|
datasource.InitSecretFlags()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
if !*remoteReadIgnoreRestoreErrors {
|
if !*remoteReadIgnoreRestoreErrors {
|
||||||
logger.Warnf("flag `remoteRead.ignoreRestoreErrors` is deprecated and will be removed in next releases.")
|
logger.Warnf("flag `remoteRead.ignoreRestoreErrors` is deprecated and will be removed in next releases.")
|
||||||
|
@ -179,12 +178,14 @@ func main() {
|
||||||
rh := &requestHandler{m: manager}
|
rh := &requestHandler{m: manager}
|
||||||
go httpserver.Serve(*httpListenAddr, *useProxyProtocol, rh.handler)
|
go httpserver.Serve(*httpListenAddr, *useProxyProtocol, rh.handler)
|
||||||
|
|
||||||
|
pushmetrics.Init()
|
||||||
sig := procutil.WaitForSigterm()
|
sig := procutil.WaitForSigterm()
|
||||||
logger.Infof("service received signal %s", sig)
|
logger.Infof("service received signal %s", sig)
|
||||||
|
pushmetrics.Stop()
|
||||||
|
|
||||||
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
||||||
logger.Fatalf("cannot stop the webservice: %s", err)
|
logger.Fatalf("cannot stop the webservice: %s", err)
|
||||||
}
|
}
|
||||||
pushmetrics.Stop()
|
|
||||||
cancel()
|
cancel()
|
||||||
manager.close()
|
manager.close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ func main() {
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
logger.Infof("starting vmauth at %q...", *httpListenAddr)
|
logger.Infof("starting vmauth at %q...", *httpListenAddr)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
@ -55,15 +54,16 @@ func main() {
|
||||||
go httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
go httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
||||||
logger.Infof("started vmauth in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("started vmauth in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
|
|
||||||
|
pushmetrics.Init()
|
||||||
sig := procutil.WaitForSigterm()
|
sig := procutil.WaitForSigterm()
|
||||||
logger.Infof("received signal %s", sig)
|
logger.Infof("received signal %s", sig)
|
||||||
|
pushmetrics.Stop()
|
||||||
|
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
logger.Infof("gracefully shutting down webservice at %q", *httpListenAddr)
|
logger.Infof("gracefully shutting down webservice at %q", *httpListenAddr)
|
||||||
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
||||||
logger.Fatalf("cannot stop the webservice: %s", err)
|
logger.Fatalf("cannot stop the webservice: %s", err)
|
||||||
}
|
}
|
||||||
pushmetrics.Stop()
|
|
||||||
logger.Infof("successfully shut down the webservice in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully shut down the webservice in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
stopAuthConfig()
|
stopAuthConfig()
|
||||||
logger.Infof("successfully stopped vmauth in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully stopped vmauth in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
|
|
|
@ -47,7 +47,6 @@ func main() {
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
// Storing snapshot delete function to be able to call it in case
|
// Storing snapshot delete function to be able to call it in case
|
||||||
// of error since logger.Fatal will exit the program without
|
// of error since logger.Fatal will exit the program without
|
||||||
|
@ -98,18 +97,19 @@ func main() {
|
||||||
|
|
||||||
go httpserver.Serve(*httpListenAddr, false, nil)
|
go httpserver.Serve(*httpListenAddr, false, nil)
|
||||||
|
|
||||||
|
pushmetrics.Init()
|
||||||
err := makeBackup()
|
err := makeBackup()
|
||||||
deleteSnapshot()
|
deleteSnapshot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("cannot create backup: %s", err)
|
logger.Fatalf("cannot create backup: %s", err)
|
||||||
}
|
}
|
||||||
|
pushmetrics.Stop()
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
logger.Infof("gracefully shutting down http server for metrics at %q", *httpListenAddr)
|
logger.Infof("gracefully shutting down http server for metrics at %q", *httpListenAddr)
|
||||||
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
||||||
logger.Fatalf("cannot stop http server for metrics: %s", err)
|
logger.Fatalf("cannot stop http server for metrics: %s", err)
|
||||||
}
|
}
|
||||||
pushmetrics.Stop()
|
|
||||||
logger.Infof("successfully shut down http server for metrics in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully shut down http server for metrics in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,6 @@ func main() {
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
logger.Infof("initializing netstorage for storageNodes %s...", *storageNodes)
|
logger.Infof("initializing netstorage for storageNodes %s...", *storageNodes)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
@ -147,8 +146,10 @@ func main() {
|
||||||
httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
pushmetrics.Init()
|
||||||
sig := procutil.WaitForSigterm()
|
sig := procutil.WaitForSigterm()
|
||||||
logger.Infof("service received signal %s", sig)
|
logger.Infof("service received signal %s", sig)
|
||||||
|
pushmetrics.Stop()
|
||||||
|
|
||||||
logger.Infof("gracefully shutting down http service at %q", *httpListenAddr)
|
logger.Infof("gracefully shutting down http service at %q", *httpListenAddr)
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
|
@ -157,8 +158,6 @@ func main() {
|
||||||
}
|
}
|
||||||
logger.Infof("successfully shut down http service in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully shut down http service in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
|
|
||||||
pushmetrics.Stop()
|
|
||||||
|
|
||||||
if len(*clusternativeListenAddr) > 0 {
|
if len(*clusternativeListenAddr) > 0 {
|
||||||
clusternativeServer.MustStop()
|
clusternativeServer.MustStop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ func main() {
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
go httpserver.Serve(*httpListenAddr, false, nil)
|
go httpserver.Serve(*httpListenAddr, false, nil)
|
||||||
|
|
||||||
|
@ -54,9 +53,11 @@ func main() {
|
||||||
Dst: dstFS,
|
Dst: dstFS,
|
||||||
SkipBackupCompleteCheck: *skipBackupCompleteCheck,
|
SkipBackupCompleteCheck: *skipBackupCompleteCheck,
|
||||||
}
|
}
|
||||||
|
pushmetrics.Init()
|
||||||
if err := a.Run(); err != nil {
|
if err := a.Run(); err != nil {
|
||||||
logger.Fatalf("cannot restore from backup: %s", err)
|
logger.Fatalf("cannot restore from backup: %s", err)
|
||||||
}
|
}
|
||||||
|
pushmetrics.Stop()
|
||||||
srcFS.MustStop()
|
srcFS.MustStop()
|
||||||
dstFS.MustStop()
|
dstFS.MustStop()
|
||||||
|
|
||||||
|
@ -65,7 +66,6 @@ func main() {
|
||||||
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
if err := httpserver.Stop(*httpListenAddr); err != nil {
|
||||||
logger.Fatalf("cannot stop http server for metrics: %s", err)
|
logger.Fatalf("cannot stop http server for metrics: %s", err)
|
||||||
}
|
}
|
||||||
pushmetrics.Stop()
|
|
||||||
logger.Infof("successfully shut down http server for metrics in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully shut down http server for metrics in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,6 @@ func main() {
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
logger.Infof("starting netstorage at storageNodes %s", *storageNodes)
|
logger.Infof("starting netstorage at storageNodes %s", *storageNodes)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
@ -133,8 +132,10 @@ func main() {
|
||||||
httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
pushmetrics.Init()
|
||||||
sig := procutil.WaitForSigterm()
|
sig := procutil.WaitForSigterm()
|
||||||
logger.Infof("service received signal %s", sig)
|
logger.Infof("service received signal %s", sig)
|
||||||
|
pushmetrics.Stop()
|
||||||
|
|
||||||
logger.Infof("gracefully shutting down http service at %q", *httpListenAddr)
|
logger.Infof("gracefully shutting down http service at %q", *httpListenAddr)
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
|
@ -143,8 +144,6 @@ func main() {
|
||||||
}
|
}
|
||||||
logger.Infof("successfully shut down http service in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully shut down http service in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
|
|
||||||
pushmetrics.Stop()
|
|
||||||
|
|
||||||
if vmselectapiServer != nil {
|
if vmselectapiServer != nil {
|
||||||
logger.Infof("stopping vmselectapi server...")
|
logger.Infof("stopping vmselectapi server...")
|
||||||
vmselectapiServer.MustStop()
|
vmselectapiServer.MustStop()
|
||||||
|
|
|
@ -83,7 +83,6 @@ func main() {
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
pushmetrics.Init()
|
|
||||||
|
|
||||||
storage.SetDedupInterval(*minScrapeInterval)
|
storage.SetDedupInterval(*minScrapeInterval)
|
||||||
storage.SetDataFlushInterval(*inmemoryDataFlushInterval)
|
storage.SetDataFlushInterval(*inmemoryDataFlushInterval)
|
||||||
|
@ -135,8 +134,10 @@ func main() {
|
||||||
httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
httpserver.Serve(*httpListenAddr, *useProxyProtocol, requestHandler)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
pushmetrics.Init()
|
||||||
sig := procutil.WaitForSigterm()
|
sig := procutil.WaitForSigterm()
|
||||||
logger.Infof("service received signal %s", sig)
|
logger.Infof("service received signal %s", sig)
|
||||||
|
pushmetrics.Stop()
|
||||||
|
|
||||||
logger.Infof("gracefully shutting down http service at %q", *httpListenAddr)
|
logger.Infof("gracefully shutting down http service at %q", *httpListenAddr)
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
|
@ -145,8 +146,6 @@ func main() {
|
||||||
}
|
}
|
||||||
logger.Infof("successfully shut down http service in %.3f seconds", time.Since(startTime).Seconds())
|
logger.Infof("successfully shut down http service in %.3f seconds", time.Since(startTime).Seconds())
|
||||||
|
|
||||||
pushmetrics.Stop()
|
|
||||||
|
|
||||||
logger.Infof("gracefully shutting down the service")
|
logger.Infof("gracefully shutting down the service")
|
||||||
startTime = time.Now()
|
startTime = time.Now()
|
||||||
stopStaleSnapshotsRemover()
|
stopStaleSnapshotsRemover()
|
||||||
|
|
|
@ -19,7 +19,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
|
||||||
* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly handle queries, which wrap [rollup functions](https://docs.victoriametrics.com/MetricsQL.html#rollup-functions) with multiple arguments without explicitly specified lookbehind window in square brackets into [aggregate functions](https://docs.victoriametrics.com/MetricsQL.html#aggregate-functions). For example, `sum(quantile_over_time(0.5, process_resident_memory_bytes))` was resulting to `expecting at least 2 args to ...; got 1 args' error. Thanks to @atykhyy for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5414).
|
* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly handle queries, which wrap [rollup functions](https://docs.victoriametrics.com/MetricsQL.html#rollup-functions) with multiple arguments without explicitly specified lookbehind window in square brackets into [aggregate functions](https://docs.victoriametrics.com/MetricsQL.html#aggregate-functions). For example, `sum(quantile_over_time(0.5, process_resident_memory_bytes))` was resulting to `expecting at least 2 args to ...; got 1 args' error. Thanks to @atykhyy for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5414).
|
||||||
* BUGFIX: `vmstorage`: properly expire `storage/prefetchedMetricIDs` cache. Previously this cache was never expired, so it could grow big under [high churn rate](https://docs.victoriametrics.com/FAQ.html#what-is-high-churn-rate). This could result in increasing CPU load over time.
|
* BUGFIX: `vmstorage`: properly expire `storage/prefetchedMetricIDs` cache. Previously this cache was never expired, so it could grow big under [high churn rate](https://docs.victoriametrics.com/FAQ.html#what-is-high-churn-rate). This could result in increasing CPU load over time.
|
||||||
* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly return results from [bottomk](https://docs.victoriametrics.com/MetricsQL.html#bottomk) and `bottomk_...()` functions when some of these results contain NaN values. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5506). Thanks to @xiaozongyang for [the fix](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5509).
|
* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly return results from [bottomk](https://docs.victoriametrics.com/MetricsQL.html#bottomk) and `bottomk_...()` functions when some of these results contain NaN values. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5506). Thanks to @xiaozongyang for [the fix](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5509).
|
||||||
* BUGFIX: all: fix potential panic during components shutdown when `-pushmetrics.url` is configured. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5548). Thanks to @zhdd99 for the [pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5549).
|
* BUGFIX: all: fix potential panic during components shutdown when [metrics push](https://docs.victoriametrics.com/#push-metrics) is configured. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5548). Thanks to @zhdd99 for the [pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5549).
|
||||||
|
|
||||||
## [v1.87.12](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.87.12)
|
## [v1.87.12](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.87.12)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package pushmetrics
|
package pushmetrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/appmetrics"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/appmetrics"
|
||||||
|
@ -26,6 +28,7 @@ func init() {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pushCtx, cancelPushCtx = context.WithCancel(context.Background())
|
pushCtx, cancelPushCtx = context.WithCancel(context.Background())
|
||||||
|
wgDone sync.WaitGroup
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init must be called after logger.Init
|
// Init must be called after logger.Init
|
||||||
|
@ -34,6 +37,7 @@ func Init() {
|
||||||
for _, pu := range *pushURL {
|
for _, pu := range *pushURL {
|
||||||
opts := &metrics.PushOptions{
|
opts := &metrics.PushOptions{
|
||||||
ExtraLabels: extraLabels,
|
ExtraLabels: extraLabels,
|
||||||
|
WaitGroup: &wgDone,
|
||||||
}
|
}
|
||||||
if err := metrics.InitPushExtWithOptions(pushCtx, pu, *pushInterval, appmetrics.WritePrometheusMetrics, opts); err != nil {
|
if err := metrics.InitPushExtWithOptions(pushCtx, pu, *pushInterval, appmetrics.WritePrometheusMetrics, opts); err != nil {
|
||||||
logger.Fatalf("cannot initialize pushmetrics: %s", err)
|
logger.Fatalf("cannot initialize pushmetrics: %s", err)
|
||||||
|
@ -48,4 +52,5 @@ func Init() {
|
||||||
// Stop must be called after Init.
|
// Stop must be called after Init.
|
||||||
func Stop() {
|
func Stop() {
|
||||||
cancelPushCtx()
|
cancelPushCtx()
|
||||||
|
wgDone.Wait()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue