Skip to content

Commit

Permalink
BEDS-306: monitoring: close clickhouse native writer if automagically…
Browse files Browse the repository at this point in the history
… opened

no way this will ever back fire right
  • Loading branch information
invis-bitfly committed Sep 12, 2024
1 parent 402b034 commit b50cbf8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/pkg/monitoring/monitoring.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package monitoring

import (
"sync"
"sync/atomic"

"github.com/gobitfly/beaconchain/pkg/commons/db"
"github.com/gobitfly/beaconchain/pkg/commons/log"
"github.com/gobitfly/beaconchain/pkg/commons/metrics"
Expand All @@ -11,11 +14,17 @@ import (
)

var monitoredServices []services.Service
var startedClickhouse atomic.Bool
var initMutex = sync.Mutex{}

func Init(full bool) {
initMutex.Lock()
defer initMutex.Unlock()
metrics.UUID.WithLabelValues(utils.GetUUID()).Set(1) // so we can find out where the uuid is set
metrics.DeploymentType.WithLabelValues(utils.Config.DeploymentType).Set(1)
if db.ClickHouseNativeWriter == nil {
log.Infof("initializing clickhouse writer")
startedClickhouse.Store(true)
db.ClickHouseNativeWriter = db.MustInitClickhouseNative(&types.DatabaseConfig{
Username: utils.Config.ClickHouse.WriterDatabase.Username,
Password: utils.Config.ClickHouse.WriterDatabase.Password,
Expand Down Expand Up @@ -58,4 +67,7 @@ func Stop() {
}
// this prevents status reports that werent shut down cleanly from triggering alerts
services.NewStatusReport(constants.CleanShutdownEvent, constants.Default, constants.Default)(constants.Success, nil)
if startedClickhouse.Load() {
db.ClickHouseNativeWriter.Close()
}
}

0 comments on commit b50cbf8

Please sign in to comment.