vitess.io/vitess@v0.16.2/go/vt/vtorc/metrics/query/metric.go (about) 1 /* 2 Copyright 2017 Simon J Mudd 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package query 18 19 /* 20 query holds information about query metrics and records the time taken 21 waiting before doing the query plus the time taken executing the query. 22 */ 23 import ( 24 "time" 25 ) 26 27 // Metric records query metrics of backend writes that go through 28 // a sized channel. It allows us to compare the time waiting to 29 // execute the query against the time needed to run it and in a 30 // "sized channel" the wait time may be significant and is good to 31 // measure. 32 type Metric struct { 33 Timestamp time.Time // time the metric was started 34 WaitLatency time.Duration // time that we had to wait before starting query execution 35 ExecuteLatency time.Duration // time the query took to execute 36 Err error // any error resulting from the query execution 37 } 38 39 // NewMetric returns a new metric with timestamp starting from now 40 func NewMetric() *Metric { 41 bqm := &Metric{ 42 Timestamp: time.Now(), 43 } 44 45 return bqm 46 } 47 48 // When records the timestamp of the start of the recording 49 func (m Metric) When() time.Time { 50 return m.Timestamp 51 }