go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/services/bugupdater/metrics.go (about) 1 // Copyright 2023 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 bugupdater 16 17 import ( 18 "context" 19 20 "go.chromium.org/luci/common/tsmon" 21 "go.chromium.org/luci/common/tsmon/field" 22 "go.chromium.org/luci/common/tsmon/metric" 23 "go.chromium.org/luci/common/tsmon/types" 24 ) 25 26 var ( 27 // runsCounter is the metric that counts the number of bug filing 28 // runs by LUCI Analysis, by project and outcome. 29 runsCounter = metric.NewCounter("analysis/bug_updater/runs", 30 "The number of auto-bug filing runs completed, "+ 31 "by LUCI Project and status.", 32 &types.MetricMetadata{ 33 Units: "runs", 34 }, 35 // The LUCI project. 36 field.String("project"), 37 // The run status. 38 field.String("status"), // success | failure 39 ) 40 41 // statusGauge reports the most recent status of the bug updater job. 42 // Reports either "success" or "failure". 43 statusGauge = metric.NewString("analysis/bug_updater/status", 44 "Whether automatic bug updates are succeeding, by LUCI Project.", 45 nil, 46 // The LUCI project. 47 field.String("project"), 48 ) 49 50 durationGauge = metric.NewFloat("analysis/bug_updater/duration", 51 "How long it is taking to update bugs, by LUCI Project.", 52 &types.MetricMetadata{ 53 Units: types.Seconds, 54 }, 55 // The LUCI project. 56 field.String("project"), 57 ) 58 ) 59 60 func init() { 61 // Register metrics as global metrics, which has the effort of 62 // resetting them after every flush. 63 tsmon.RegisterGlobalCallback(func(ctx context.Context) { 64 // Do nothing -- the metrics will be populated by the cron 65 // job itself and does not need to be triggered externally. 66 }, statusGauge, durationGauge) 67 }