Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/subzero-ion-connect/subzero_ion_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ice-blockchain/subzero/dvm"
hashtagssender "github.com/ice-blockchain/subzero/hashtags-sender"
"github.com/ice-blockchain/subzero/model"
"github.com/ice-blockchain/subzero/monitoring"
pushnotifications "github.com/ice-blockchain/subzero/push-notifications"
"github.com/ice-blockchain/subzero/server"
wsserver "github.com/ice-blockchain/subzero/server/ws"
Expand All @@ -40,6 +41,7 @@ var (
Version: getVersion(),
Run: func(cmd *cobra.Command, _ []string) {
cfg.MustInit(configPath)
monitoring.MustInit()
validation.MustInit()
query.MustInit(cmd.Context())
command.MustInit(cmd.Context())
Expand Down Expand Up @@ -127,6 +129,7 @@ func init() {
if err := query.AcceptEvents(ctx, events...); err != nil {
return errors.Wrap(err, "query.AcceptEvent failed")
}
monitoring.RecordEventStored(len(events))
if ch, err := dvm.AcceptJob(ctx, events[0]); err == nil && ch != nil {
antsPool.Submit(func() {
result := <-ch
Expand Down
14 changes: 12 additions & 2 deletions database/query/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/ice-blockchain/subzero/cfg"
"github.com/ice-blockchain/subzero/model"
"github.com/ice-blockchain/subzero/monitoring"
)

var (
Expand All @@ -22,6 +23,7 @@ var (
Once sync.Once
}
UsedDatabaseStorage atomic.Uint64
DatabaseEventsCount atomic.Uint64
)

type (
Expand Down Expand Up @@ -121,7 +123,7 @@ func MustInit(ctx context.Context, opts ...Option) {
WithRelayURL(conf.RelayURL)

go globalDB.Client.StartExpiredEventsCleanup(ctx)
go globalDB.Client.StartCollectingUsedDatabaseStorage(ctx)
go globalDB.Client.StartCollectingUsedDatabaseInfo(ctx)

go func() {
<-ctx.Done()
Expand Down Expand Up @@ -206,7 +208,7 @@ func (db *dbClient) StartExpiredEventsCleanup(ctx context.Context) {
}
}

func (db *dbClient) StartCollectingUsedDatabaseStorage(ctx context.Context) {
func (db *dbClient) StartCollectingUsedDatabaseInfo(ctx context.Context) {
ticks := make(chan struct{}, 1)
ticks <- struct{}{}
go func() {
Expand All @@ -233,7 +235,15 @@ func (db *dbClient) StartCollectingUsedDatabaseStorage(ctx context.Context) {
log.Printf("failed to query database size: %v", err)
} else {
UsedDatabaseStorage.Store(usedDatabaseStorage)
monitoring.SetDatabaseSize("subzero", "localhost", int64(usedDatabaseStorage))
}
if eventsCount, err := db.queryEventsCount(queryCtx); err != nil {
log.Printf("failed to query events count: %v", err)
} else {
DatabaseEventsCount.Store(eventsCount)
monitoring.SetDatabaseEventsCount("subzero", "localhost", eventsCount)
}

cancel()
}
}
Expand Down
19 changes: 17 additions & 2 deletions database/query/internal/connector/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"math"
"net/url"
"reflect"
"strings"
"sync"
Expand All @@ -22,6 +23,7 @@ import (
"github.com/jackc/pgx/v5/tracelog"

"github.com/ice-blockchain/subzero/model"
"github.com/ice-blockchain/subzero/monitoring"
)

func WithWriteURLs(urls ...string) Option {
Expand Down Expand Up @@ -244,8 +246,21 @@ func poolConnect(ctx context.Context, connectionString string, log tracelog.Logg
if !strings.Contains(strings.ToLower(connectionString), "pool_min_conns") {
conf.MinConns = 1
}
conf.ConnConfig.Tracer = &tracelog.TraceLog{Logger: log, LogLevel: tracelog.LogLevelDebug}
return pgxpool.NewWithConfig(ctx, conf)
host := conf.ConnConfig.Host
if host == "" {
if u, parseErr := url.Parse(connectionString); parseErr == nil {
host = u.Host
}
}
dbTracer := monitoring.NewAdvancedDBTracer(host, "main")
conf.ConnConfig.Tracer = dbTracer
pool, err := pgxpool.NewWithConfig(ctx, conf)
if err != nil {
return nil, err
}
monitoring.RegisterPoolFromConnector(pool, "subzero", host)

return pool, nil
}

func poolDoAfterConnect(ctx context.Context, conn *pgx.Conn) error {
Expand Down
9 changes: 9 additions & 0 deletions database/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,3 +1216,12 @@ func (db *dbClient) queryDatabaseSize(ctx context.Context) (uint64, error) {
}
return *sizePtr, nil
}

func (db *dbClient) queryEventsCount(ctx context.Context) (uint64, error) {
countPtr, err := connector.Get[uint64](ctx, db.db, `SELECT count(*) FROM events WHERE deleted = false`)
if err != nil {
return 0, errors.Wrapf(err, "failed to query events count")
}

return *countPtr, nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ replace (

require (
firebase.google.com/go/v4 v4.18.0
github.com/IBM/pgxpoolprometheus v1.1.2
github.com/alitto/pond/v2 v2.5.0
github.com/bzick/tokenizer v1.4.10
github.com/caddyserver/certmagic v0.23.0
Expand Down Expand Up @@ -45,6 +46,7 @@ require (
github.com/mxschmitt/golang-combinations v1.2.0
github.com/nbd-wtf/go-nostr v0.51.12
github.com/panjf2000/ants/v2 v2.11.3
github.com/prometheus/client_golang v1.23.0
github.com/puzpuzpuz/xsync/v4 v4.1.0
github.com/quic-go/quic-go v0.54.0
github.com/quic-go/webtransport-go v0.9.0
Expand Down Expand Up @@ -207,7 +209,6 @@ require (
github.com/planetscale/vtprotobuf v0.6.1-0.20250313105119-ba97887b0a25 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus/client_golang v1.23.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.65.0 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.53.0/go.mod h1:jUZ5LYlw40WMd07qxcQJD5M40aUxrfwqQX1g7zxYnrQ=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.53.0 h1:Ron4zCA/yk6U7WOBXhTJcDpsUBG9npumK6xw2auFltQ=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.53.0/go.mod h1:cSgYe11MCNYunTnRXrKiR/tHc0eoKjICUuWpNZoVCOo=
github.com/IBM/pgxpoolprometheus v1.1.2 h1:sHJwxoL5Lw4R79Zt+H4Uj1zZ4iqXJLdk7XDE7TPs97U=
github.com/IBM/pgxpoolprometheus v1.1.2/go.mod h1:+vWzISN6S9ssgurhUNmm6AlXL9XLah3TdWJktquKTR8=
github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs=
github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8=
github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII=
Expand Down
Loading
Loading