From 7adfcb150be183405fa0cef929b6e13f07b575e9 Mon Sep 17 00:00:00 2001 From: Wenyi Hu Date: Mon, 8 Jul 2024 08:57:01 -0400 Subject: [PATCH] server: change nodeMetrics methods to pointer receivers Previously, nodeMetrics methods used value receivers, causing unnecessary copies on each call. This patch changes these methods to use pointer receivers. Epic: none Release note: none --- pkg/server/helpers_test.go | 4 ++-- pkg/server/node.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/server/helpers_test.go b/pkg/server/helpers_test.go index f5613344b0ad..020125e0ed03 100644 --- a/pkg/server/helpers_test.go +++ b/pkg/server/helpers_test.go @@ -26,10 +26,10 @@ import ( // Assumption: 1. The metricNames parameter should consist of string literals // that match the metadata names used for metric counters. 2. Each metric name // provided in `metricNames` must exist, unique and be a counter type. -func (nm nodeMetrics) getNodeCounterMetrics(metricsName []string) (map[string]int64, error) { +func (nm *nodeMetrics) getNodeCounterMetrics(metricsName []string) (map[string]int64, error) { metricCountMap := make(map[string]int64) getFirstNodeMetric := func(metricName string) int64 { - metricsStruct := reflect.ValueOf(nm) + metricsStruct := reflect.ValueOf(*nm) for i := 0; i < metricsStruct.NumField(); i++ { field := metricsStruct.Field(i) switch t := field.Interface().(type) { diff --git a/pkg/server/node.go b/pkg/server/node.go index 7d700eb99cd3..c762bb2b2da9 100644 --- a/pkg/server/node.go +++ b/pkg/server/node.go @@ -262,8 +262,8 @@ type nodeMetrics struct { ActiveMuxRangeFeed *metric.Gauge } -func makeNodeMetrics(reg *metric.Registry, histogramWindow time.Duration) nodeMetrics { - nm := nodeMetrics{ +func makeNodeMetrics(reg *metric.Registry, histogramWindow time.Duration) *nodeMetrics { + nm := &nodeMetrics{ Latency: metric.NewHistogram(metric.HistogramOptions{ Mode: metric.HistogramModePreferHdrLatency, Metadata: metaExecLatency, @@ -298,7 +298,7 @@ func makeNodeMetrics(reg *metric.Registry, histogramWindow time.Duration) nodeMe // callComplete records very high-level metrics about the number of completed // calls and their latency. Currently, this only records statistics at the batch // level; stats on specific lower-level kv operations are not recorded. -func (nm nodeMetrics) callComplete(d time.Duration, pErr *kvpb.Error) { +func (nm *nodeMetrics) callComplete(d time.Duration, pErr *kvpb.Error) { if pErr != nil && pErr.TransactionRestart() == kvpb.TransactionRestart_NONE { nm.Err.Inc(1) } else { @@ -314,7 +314,7 @@ func (nm nodeMetrics) callComplete(d time.Duration, pErr *kvpb.Error) { // activities across different zones within the same region or in cases where // region tiers are not configured. These metrics may include batches that were // not successfully sent but were terminated at an early stage. -func (nm nodeMetrics) updateCrossLocalityMetricsOnBatchRequest( +func (nm *nodeMetrics) updateCrossLocalityMetricsOnBatchRequest( comparisonResult roachpb.LocalityComparisonType, inc int64, ) { nm.BatchRequestsBytes.Inc(inc) @@ -331,7 +331,7 @@ func (nm nodeMetrics) updateCrossLocalityMetricsOnBatchRequest( // parameter determined during the initial batch requests check. The underlying // assumption is that the response should match the cross-region or cross-zone // nature of the requests. -func (nm nodeMetrics) updateCrossLocalityMetricsOnBatchResponse( +func (nm *nodeMetrics) updateCrossLocalityMetricsOnBatchResponse( comparisonResult roachpb.LocalityComparisonType, inc int64, ) { nm.BatchResponsesBytes.Inc(inc) @@ -359,7 +359,7 @@ type Node struct { storeCfg kvserver.StoreConfig // Config to use and pass to stores execCfg *sql.ExecutorConfig // For event logging stores *kvserver.Stores // Access to node-local stores - metrics nodeMetrics + metrics *nodeMetrics recorder *status.MetricsRecorder startedAt int64 lastUp int64