go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/common/eventbox/monitoring.go (about) 1 // Copyright 2021 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package eventbox 16 17 import ( 18 "context" 19 "math" 20 21 "go.chromium.org/luci/common/tsmon/distribution" 22 "go.chromium.org/luci/common/tsmon/field" 23 "go.chromium.org/luci/common/tsmon/metric" 24 "go.chromium.org/luci/common/tsmon/types" 25 ) 26 27 var ( 28 metricListDurationsS = metric.NewCumulativeDistribution( 29 "cv/internal/eventbox/list/duration", 30 "Distribution of duration of list ops.", 31 &types.MetricMetadata{Units: types.Milliseconds}, 32 // Bucketer for 1ms..10m range since anything above 10m is bad. 33 // 34 // $ python3 -c "print(((10**0.058)**100)/1e3/60.0)" 35 // 10.515955741336601 36 distribution.GeometricBucketer(math.Pow(10, 0.058), 100), 37 field.String("recipient"), 38 field.String("result"), 39 ) 40 41 metricSent = metric.NewCounter( 42 "cv/internal/eventbox/sent", 43 "Number of events sent.", 44 nil, 45 field.String("recipient"), 46 ) 47 48 metricRemoved = metric.NewCounter( 49 "cv/internal/eventbox/removed", 50 "Approximate, likely exaggerated, number of events removed.", 51 nil, 52 field.String("recipient"), 53 ) 54 55 metricSize = metric.NewInt( 56 "cv/internal/eventbox/size", 57 "Number of the events. Updated from successful list ops only.", 58 nil, 59 field.String("recipient"), 60 ) 61 62 metricOldestAgeS = metric.NewFloat( 63 "cv/internal/eventbox/oldest_age", 64 "Age of the oldest event. Updated from successful list ops only.", 65 &types.MetricMetadata{Units: types.Seconds}, 66 field.String("recipient"), 67 ) 68 ) 69 70 func monitoringResult(err error) string { 71 switch { 72 case err == nil: 73 return "OK" 74 case err == context.DeadlineExceeded: 75 return "TIMEOUT" 76 default: 77 return "FAILURE" 78 } 79 }