Skip to content

Commit

Permalink
server: change nodeMetrics methods to pointer receivers
Browse files Browse the repository at this point in the history
Previously, nodeMetrics methods used value receivers, causing unnecessary copies
on each call. This patch changes these methods to use pointer receivers.

Part of: cockroachdb#126561
Release note: none
  • Loading branch information
wenyihu6 committed Jul 9, 2024
1 parent 37fd8f1 commit 1161089
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/server/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1161089

Please sign in to comment.