github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ccl/changefeedccl/kvfeed/metrics.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Licensed as a CockroachDB Enterprise file under the Cockroach Community 4 // License (the "License"); you may not use this file except in compliance with 5 // the License. You may obtain a copy of the License at 6 // 7 // https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt 8 9 package kvfeed 10 11 import ( 12 "time" 13 14 "github.com/cockroachdb/cockroach/pkg/util/metric" 15 ) 16 17 const pollRequestNanosHistMaxLatency = time.Hour 18 19 var ( 20 metaChangefeedBufferEntriesIn = metric.Metadata{ 21 Name: "changefeed.buffer_entries.in", 22 Help: "Total entries entering the buffer between raft and changefeed sinks", 23 Measurement: "Entries", 24 Unit: metric.Unit_COUNT, 25 } 26 metaChangefeedBufferEntriesOut = metric.Metadata{ 27 Name: "changefeed.buffer_entries.out", 28 Help: "Total entries leaving the buffer between raft and changefeed sinks", 29 Measurement: "Entries", 30 Unit: metric.Unit_COUNT, 31 } 32 metaChangefeedPollRequestNanos = metric.Metadata{ 33 Name: "changefeed.poll_request_nanos", 34 Help: "Time spent fetching changes", 35 Measurement: "Nanoseconds", 36 Unit: metric.Unit_NANOSECONDS, 37 } 38 ) 39 40 // Metrics is a metric.Struct for kvfeed metrics. 41 // 42 // TODO(ajwerner): Make these metrics more reasonable given the removal of the 43 // poller and polling in general. 44 type Metrics struct { 45 BufferEntriesIn *metric.Counter 46 BufferEntriesOut *metric.Counter 47 PollRequestNanosHist *metric.Histogram 48 } 49 50 // MakeMetrics constructs a Metrics struct with the provided histogram window. 51 func MakeMetrics(histogramWindow time.Duration) Metrics { 52 return Metrics{ 53 BufferEntriesIn: metric.NewCounter(metaChangefeedBufferEntriesIn), 54 BufferEntriesOut: metric.NewCounter(metaChangefeedBufferEntriesOut), 55 // Metrics for changefeed performance debugging: - PollRequestNanos and 56 // PollRequestNanosHist, things are first 57 // fetched with some limited concurrency. We're interested in both the 58 // total amount of time fetching as well as outliers, so we need both 59 // the counter and the histogram. 60 // - N/A. Each change is put into a buffer. Right now nothing measures 61 // this since the buffer doesn't actually buffer and so it just tracks 62 // the poll sleep time. 63 // - ProcessingNanos. Everything from the buffer until the SQL row is 64 // about to be emitted. This includes TableMetadataNanos, which is 65 // dependent on network calls, so also tracked in case it's ever the 66 // cause of a ProcessingNanos blowup. 67 // - EmitNanos and FlushNanos. All of our interactions with the sink. 68 PollRequestNanosHist: metric.NewHistogram( 69 metaChangefeedPollRequestNanos, histogramWindow, 70 pollRequestNanosHistMaxLatency.Nanoseconds(), 1), 71 } 72 } 73 74 var _ (metric.Struct) = (*Metrics)(nil) 75 76 // MetricStruct makes Metrics a metric.Struct. 77 func (m Metrics) MetricStruct() {}