github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/rangefeed/metrics.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package rangefeed
    12  
    13  import (
    14  	"time"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/util/log"
    17  	"github.com/cockroachdb/cockroach/pkg/util/metric"
    18  	"github.com/cockroachdb/cockroach/pkg/util/syncutil/singleflight"
    19  )
    20  
    21  var (
    22  	metaRangeFeedCatchupScanNanos = metric.Metadata{
    23  		Name:        "kv.rangefeed.catchup_scan_nanos",
    24  		Help:        "Time spent in RangeFeed catchup scan",
    25  		Measurement: "Nanoseconds",
    26  		Unit:        metric.Unit_NANOSECONDS,
    27  	}
    28  )
    29  
    30  // Metrics are for production monitoring of RangeFeeds.
    31  type Metrics struct {
    32  	RangeFeedCatchupScanNanos *metric.Counter
    33  
    34  	RangeFeedSlowClosedTimestampLogN  log.EveryN
    35  	RangeFeedSlowClosedTimestampNudge singleflight.Group
    36  	// RangeFeedSlowClosedTimestampNudgeSem bounds the amount of work that can be
    37  	// spun up on behalf of the RangeFeed nudger. We don't expect to hit this
    38  	// limit, but it's here to limit the effect on stability in case something
    39  	// unexpected happens.
    40  	RangeFeedSlowClosedTimestampNudgeSem chan struct{}
    41  }
    42  
    43  // MetricStruct implements the metric.Struct interface.
    44  func (*Metrics) MetricStruct() {}
    45  
    46  // NewMetrics makes the metrics for RangeFeeds monitoring.
    47  func NewMetrics() *Metrics {
    48  	return &Metrics{
    49  		RangeFeedCatchupScanNanos:            metric.NewCounter(metaRangeFeedCatchupScanNanos),
    50  		RangeFeedSlowClosedTimestampLogN:     log.Every(5 * time.Second),
    51  		RangeFeedSlowClosedTimestampNudgeSem: make(chan struct{}, 1024),
    52  	}
    53  }