From e8695dc6f346b4431ea4bfa47f26c11c134f439b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 23 Jun 2022 11:47:11 +0200 Subject: [PATCH 1/3] informer/disk: set repoSize weight to negative smaller repositories should have more priority --- informer/disk/disk.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/informer/disk/disk.go b/informer/disk/disk.go index 17012809..e50e5b45 100644 --- a/informer/disk/disk.go +++ b/informer/disk/disk.go @@ -105,7 +105,8 @@ func (disk *Informer) GetMetrics(ctx context.Context) []api.Metric { } var repoStat api.IPFSRepoStat - var metric uint64 + var weight uint64 + var value string valid := true @@ -126,24 +127,27 @@ func (disk *Informer) GetMetrics(ctx context.Context) []api.Metric { size := repoStat.RepoSize total := repoStat.StorageMax if size < total { - metric = total - size + weight = total - size } else { // Make sure we don't underflow and stop // sending this metric when space is exhausted. - metric = 0 + weight = 0 valid = false logger.Warn("reported freespace is 0") } + value = fmt.Sprintf("%d", weight) case MetricRepoSize: - metric = repoStat.RepoSize + // smaller repositories have more priority + weight = -repoStat.RepoSize + value = fmt.Sprintf("%d", repoStat.RepoSize) } } m := api.Metric{ Name: disk.Name(), - Value: fmt.Sprintf("%d", metric), + Value: value, Valid: valid, - Weight: int64(metric), + Weight: int64(weight), Partitionable: false, } From 2aec92301dfb4a8fce309e3d3233d7f57054cf8f Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 23 Jun 2022 11:58:07 +0200 Subject: [PATCH 2/3] metrics: set block/added_size unit to bytes --- observations/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/observations/metrics.go b/observations/metrics.go index 48d7dd0f..59667b07 100644 --- a/observations/metrics.go +++ b/observations/metrics.go @@ -44,7 +44,7 @@ var ( PinsPinAdd = stats.Int64("pins/pin_add", "Total number of IPFS pin requests", stats.UnitDimensionless) PinsPinAddError = stats.Int64("pins/pin_add_errors", "Total number of failed pin requests", stats.UnitDimensionless) BlocksPut = stats.Int64("blocks/put", "Total number of blocks/put requests", stats.UnitDimensionless) - BlocksAddedSize = stats.Int64("blocks/added_size", "Total size of blocks added in bytes", stats.UnitDimensionless) + BlocksAddedSize = stats.Int64("blocks/added_size", "Total size of blocks added in bytes", stats.UnitBytes) BlocksAdded = stats.Int64("blocks/added", "Total number of blocks added", stats.UnitDimensionless) BlocksAddedError = stats.Int64("blocks/put_errors", "Total number of block/put errors", stats.UnitDimensionless) From c4547698878583e6e166deb4652cc6a48598af45 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 23 Jun 2022 11:58:35 +0200 Subject: [PATCH 3/3] Informer/disk: record issued metric weights as prometheus metric. --- informer/disk/disk.go | 5 +++++ observations/metrics.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/informer/disk/disk.go b/informer/disk/disk.go index e50e5b45..cd941a4c 100644 --- a/informer/disk/disk.go +++ b/informer/disk/disk.go @@ -8,10 +8,12 @@ import ( "sync" "github.com/ipfs-cluster/ipfs-cluster/api" + "github.com/ipfs-cluster/ipfs-cluster/observations" logging "github.com/ipfs/go-log/v2" rpc "github.com/libp2p/go-libp2p-gorpc" + "go.opencensus.io/stats" "go.opencensus.io/trace" ) @@ -152,5 +154,8 @@ func (disk *Informer) GetMetrics(ctx context.Context) []api.Metric { } m.SetTTL(disk.config.MetricTTL) + + stats.Record(ctx, observations.InformerDisk.M(m.Weight)) + return []api.Metric{m} } diff --git a/observations/metrics.go b/observations/metrics.go index 59667b07..adf7d39f 100644 --- a/observations/metrics.go +++ b/observations/metrics.go @@ -48,6 +48,8 @@ var ( BlocksAdded = stats.Int64("blocks/added", "Total number of blocks added", stats.UnitDimensionless) BlocksAddedError = stats.Int64("blocks/put_errors", "Total number of block/put errors", stats.UnitDimensionless) + + InformerDisk = stats.Int64("informer/disk", "The metric value weight issued by disk informer", stats.UnitDimensionless) ) // views, which is just the aggregation of the metrics @@ -114,6 +116,11 @@ var ( Aggregation: view.Sum(), } + InformerDiskView = &view.View{ + Measure: InformerDisk, + Aggregation: view.LastValue(), + } + DefaultViews = []*view.View{ PinsView, PinsQueuedView, @@ -126,6 +133,7 @@ var ( BlocksAddedSizeView, BlocksAddedView, BlocksAddedErrorView, + InformerDiskView, } )