From 50b5d8888ef85aefd7c0a00b790ecc8a03a16faa Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Thu, 27 Feb 2025 10:56:01 -0500 Subject: [PATCH 1/2] fix(cosmos-vstorage): split size_delta counter into allocated and released refs: #10938 closes: #11062 --- golang/cosmos/x/vstorage/keeper/keeper.go | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/golang/cosmos/x/vstorage/keeper/keeper.go b/golang/cosmos/x/vstorage/keeper/keeper.go index 6e68a628649..721d3c2b43e 100644 --- a/golang/cosmos/x/vstorage/keeper/keeper.go +++ b/golang/cosmos/x/vstorage/keeper/keeper.go @@ -119,13 +119,19 @@ func NewKeeper(storeKey storetypes.StoreKey) Keeper { } } -var MetricKeysSizeDelta = []string{"store", "size_delta"} +var MetricKeyStoreAllocated = []string{"store", "allocated"} +var MetricKeyStoreReleased = []string{"store", "released"} const MetricLabelStoreKey = "storeKey" -func NewMetricsLabels(k Keeper) []metrics.Label { - return []metrics.Label{ +func ReportStoreSizeMetrics(k Keeper, sizeDelta float32) { + metricsLabel := []metrics.Label{ telemetry.NewLabel(MetricLabelStoreKey, k.storeKey.Name()), } + if sizeDelta >= 0 { + telemetry.IncrCounterWithLabels(MetricKeyStoreAllocated, sizeDelta, metricsLabel) + } else { + telemetry.IncrCounterWithLabels(MetricKeyStoreReleased, -sizeDelta, metricsLabel) + } } // ExportStorage fetches all storage @@ -228,7 +234,7 @@ func (k Keeper) RemoveEntriesWithPrefix(ctx sdk.Context, pathPrefix string) { for _, key := range keys { rawValue := store.Get(key) sizeDelta := float32(-len(key) - len(rawValue)) - telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k)) + ReportStoreSizeMetrics(k, sizeDelta) store.Delete(key) } @@ -386,19 +392,19 @@ func (k Keeper) SetStorage(ctx sdk.Context, entry agoric.KVEntry) { if !k.HasChildren(ctx, path) { // We have no children, can delete. sizeDelta := float32(-len(encodedKey) - len(oldRawValue)) - telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k)) + ReportStoreSizeMetrics(k, sizeDelta) store.Delete(encodedKey) } else { // We have children, mark as an empty placeholder without deleting. sizeDelta := float32(len(types.EncodedNoDataValue) - len(oldRawValue)) - telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k)) + ReportStoreSizeMetrics(k, sizeDelta) store.Set(encodedKey, types.EncodedNoDataValue) } } else { // Update the value. newRawValue := bytes.Join([][]byte{types.EncodedDataPrefix, []byte(entry.StringValue())}, []byte{}) sizeDelta := float32(len(newRawValue) - len(oldRawValue)) - telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k)) + ReportStoreSizeMetrics(k, sizeDelta) store.Set(encodedKey, newRawValue) } @@ -414,7 +420,7 @@ func (k Keeper) SetStorage(ctx sdk.Context, entry agoric.KVEntry) { } encodedAncestor := types.PathToEncodedKey(ancestor) sizeDelta := float32(-len(encodedAncestor) - len(types.EncodedNoDataValue)) - telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k)) + ReportStoreSizeMetrics(k, sizeDelta) store.Delete(encodedAncestor) } } else { @@ -427,7 +433,7 @@ func (k Keeper) SetStorage(ctx sdk.Context, entry agoric.KVEntry) { } encodedAncestor := types.PathToEncodedKey(ancestor) sizeDelta := float32(len(encodedAncestor) + len(types.EncodedNoDataValue)) - telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k)) + ReportStoreSizeMetrics(k, sizeDelta) store.Set(encodedAncestor, types.EncodedNoDataValue) } } From 513ee686d17b72ae8475d68d742f093f01ab7d0b Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Thu, 27 Feb 2025 13:48:12 -0500 Subject: [PATCH 2/2] fix(cosmos-vstorage): incorporate review comments refs: #11062 --- golang/cosmos/x/vstorage/keeper/keeper.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/golang/cosmos/x/vstorage/keeper/keeper.go b/golang/cosmos/x/vstorage/keeper/keeper.go index 721d3c2b43e..ace9568a6ac 100644 --- a/golang/cosmos/x/vstorage/keeper/keeper.go +++ b/golang/cosmos/x/vstorage/keeper/keeper.go @@ -119,8 +119,8 @@ func NewKeeper(storeKey storetypes.StoreKey) Keeper { } } -var MetricKeyStoreAllocated = []string{"store", "allocated"} -var MetricKeyStoreReleased = []string{"store", "released"} +var MetricKeyStoreSizeIncrease = []string{"store", "size_increase"} +var MetricKeyStoreSizeDecrese = []string{"store", "size_decrease"} const MetricLabelStoreKey = "storeKey" func ReportStoreSizeMetrics(k Keeper, sizeDelta float32) { @@ -128,9 +128,9 @@ func ReportStoreSizeMetrics(k Keeper, sizeDelta float32) { telemetry.NewLabel(MetricLabelStoreKey, k.storeKey.Name()), } if sizeDelta >= 0 { - telemetry.IncrCounterWithLabels(MetricKeyStoreAllocated, sizeDelta, metricsLabel) + telemetry.IncrCounterWithLabels(MetricKeyStoreSizeIncrease, sizeDelta, metricsLabel) } else { - telemetry.IncrCounterWithLabels(MetricKeyStoreReleased, -sizeDelta, metricsLabel) + telemetry.IncrCounterWithLabels(MetricKeyStoreSizeDecrese, -sizeDelta, metricsLabel) } }