From 38902a088cdd95cbc9b09a02ca08c4db74087422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 28 May 2024 21:01:29 +0200 Subject: [PATCH 1/3] Fix harmonydb metrics --- harmony/harmonydb/harmonydb.go | 15 +++---- harmony/harmonydb/metrics.go | 77 ---------------------------------- 2 files changed, 8 insertions(+), 84 deletions(-) delete mode 100644 harmony/harmonydb/metrics.go diff --git a/harmony/harmonydb/harmonydb.go b/harmony/harmonydb/harmonydb.go index a20eebee3..90f829427 100644 --- a/harmony/harmonydb/harmonydb.go +++ b/harmony/harmonydb/harmonydb.go @@ -20,6 +20,7 @@ import ( "github.com/yugabyte/pgx/v5/pgxpool" "golang.org/x/xerrors" + lotusdb "github.com/filecoin-project/lotus/lib/harmony/harmonydb" "github.com/filecoin-project/lotus/node/config" ) @@ -104,7 +105,7 @@ func New(hosts []string, username, password, database, port string, itestID ITes cfg.ConnConfig.OnNotice = func(conn *pgconn.PgConn, n *pgconn.Notice) { logger.Debug("database notice: " + n.Message + ": " + n.Detail) - DBMeasures.Errors.M(1) + lotusdb.DBMeasures.Errors.M(1) } db := DB{cfg: cfg, schema: schema, hostnames: hosts} // pgx populated in AddStatsAndConnect @@ -127,12 +128,12 @@ func (t tracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.Tr return context.WithValue(context.WithValue(ctx, SQL_START, time.Now()), SQL_STRING, data.SQL) } func (t tracer) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryEndData) { - DBMeasures.Hits.M(1) + lotusdb.DBMeasures.Hits.M(1) ms := time.Since(ctx.Value(SQL_START).(time.Time)).Milliseconds() - DBMeasures.TotalWait.M(ms) - DBMeasures.Waits.Observe(float64(ms)) + lotusdb.DBMeasures.TotalWait.M(ms) + lotusdb.DBMeasures.Waits.Observe(float64(ms)) if data.Err != nil { - DBMeasures.Errors.M(1) + lotusdb.DBMeasures.Errors.M(1) } logger.Debugw("SQL run", "query", ctx.Value(SQL_STRING).(string), @@ -166,8 +167,8 @@ func (db *DB) addStatsAndConnect() error { } db.cfg.AfterConnect = func(ctx context.Context, c *pgx.Conn) error { s := db.pgx.Stat() - DBMeasures.OpenConnections.M(int64(s.TotalConns())) - DBMeasures.WhichHost.Observe(hostnameToIndex[c.Config().Host]) + lotusdb.DBMeasures.OpenConnections.M(int64(s.TotalConns())) + lotusdb.DBMeasures.WhichHost.Observe(hostnameToIndex[c.Config().Host]) //FUTURE place for any connection seasoning return nil diff --git a/harmony/harmonydb/metrics.go b/harmony/harmonydb/metrics.go deleted file mode 100644 index b29a76ad5..000000000 --- a/harmony/harmonydb/metrics.go +++ /dev/null @@ -1,77 +0,0 @@ -package harmonydb - -import ( - "github.com/prometheus/client_golang/prometheus" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" - - "github.com/filecoin-project/lotus/metrics" -) - -var ( - dbTag, _ = tag.NewKey("db_name") - pre = "harmonydb_base_" - waitsBuckets = []float64{0, 10, 20, 30, 50, 80, 130, 210, 340, 550, 890} - whichHostBuckets = []float64{0, 1, 2, 3, 4, 5} -) - -// DBMeasures groups all db metrics. -var DBMeasures = struct { - Hits *stats.Int64Measure - TotalWait *stats.Int64Measure - Waits prometheus.Histogram - OpenConnections *stats.Int64Measure - Errors *stats.Int64Measure - WhichHost prometheus.Histogram -}{ - Hits: stats.Int64(pre+"hits", "Total number of uses.", stats.UnitDimensionless), - TotalWait: stats.Int64(pre+"total_wait", "Total delay. A numerator over hits to get average wait.", stats.UnitMilliseconds), - Waits: prometheus.NewHistogram(prometheus.HistogramOpts{ - Name: pre + "waits", - Buckets: waitsBuckets, - Help: "The histogram of waits for query completions.", - }), - OpenConnections: stats.Int64(pre+"open_connections", "Total connection count.", stats.UnitDimensionless), - Errors: stats.Int64(pre+"errors", "Total error count.", stats.UnitDimensionless), - WhichHost: prometheus.NewHistogram(prometheus.HistogramOpts{ - Name: pre + "which_host", - Buckets: whichHostBuckets, - Help: "The index of the hostname being used", - }), -} - -// CacheViews groups all cache-related default views. -func init() { - metrics.RegisterViews( - &view.View{ - Measure: DBMeasures.Hits, - Aggregation: view.Sum(), - TagKeys: []tag.Key{dbTag}, - }, - &view.View{ - Measure: DBMeasures.TotalWait, - Aggregation: view.Sum(), - TagKeys: []tag.Key{dbTag}, - }, - &view.View{ - Measure: DBMeasures.OpenConnections, - Aggregation: view.LastValue(), - TagKeys: []tag.Key{dbTag}, - }, - &view.View{ - Measure: DBMeasures.Errors, - Aggregation: view.Sum(), - TagKeys: []tag.Key{dbTag}, - }, - ) - err := prometheus.Register(DBMeasures.Waits) - if err != nil { - panic(err) - } - - err = prometheus.Register(DBMeasures.WhichHost) - if err != nil { - panic(err) - } -} From 344974f410fd748f34ba0b561520ed1ae5a07804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 28 May 2024 21:07:04 +0200 Subject: [PATCH 2/3] Set bash as the shell in Makefile --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e98c28577..f7622269b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +SHELL=/usr/bin/env bash + GOCC?=go FFI_PATH:=extern/filecoin-ffi/ @@ -104,4 +106,4 @@ dist-clean: # TODO API GEN # TODO DOCS GEN -# TODO DEVNET IMAGES \ No newline at end of file +# TODO DEVNET IMAGES From 8769c6e72ad28f567e96a49f9e598f93e482af52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 28 May 2024 21:19:32 +0200 Subject: [PATCH 3/3] Fix harmonytask owner unset --- harmony/harmonytask/harmonytask.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harmony/harmonytask/harmonytask.go b/harmony/harmonytask/harmonytask.go index bc1514dd5..39d7e3ab9 100644 --- a/harmony/harmonytask/harmonytask.go +++ b/harmony/harmonytask/harmonytask.go @@ -181,7 +181,7 @@ func New( // edge-case: if old assignments are not available tasks, unlock them. h := e.taskMap[w.Name] if h == nil { - _, err := db.Exec(e.ctx, `UPDATE harmony_task SET owner=NULL WHERE id=$1`, w.ID) + _, err := db.Exec(e.ctx, `UPDATE harmony_task SET owner_id=NULL WHERE id=$1`, w.ID) if err != nil { log.Errorw("Cannot remove self from owner field", "error", err) continue // not really fatal, but not great