go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/metrics/internal.go (about)

     1  // Copyright 2022 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 metrics
    16  
    17  import (
    18  	"math"
    19  	"time"
    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  // Internal contains a collection of metric definitions internal to LUCI CV.
    28  var Internal = struct {
    29  	BuildbucketRPCCount            metric.Counter
    30  	BuildbucketRPCDurations        metric.CumulativeDistribution
    31  	CLIngestionAttempted           metric.Counter
    32  	CLIngestionLatency             metric.CumulativeDistribution
    33  	CLIngestionLatencyWithoutFetch metric.CumulativeDistribution
    34  	CLTriggererTaskCompleted       metric.Counter
    35  	CLTriggererTaskDuration        metric.CumulativeDistribution
    36  	BigQueryExportDelay            metric.CumulativeDistribution
    37  	RunTryjobResultReportDelay     metric.CumulativeDistribution
    38  	RunResetTriggerAttempted       metric.Counter
    39  	QuotaOp                        metric.Counter
    40  }{
    41  	BuildbucketRPCCount: metric.NewCounter(
    42  		"cv/internal/buildbucket_rpc/count",
    43  		"Total number of RPCs to Buildbucket.",
    44  		nil,
    45  		field.String("project"),
    46  		field.String("host"),
    47  		field.String("method"),
    48  		field.String("canonical_code"), // status.Code of the result as string in UPPER_CASE.
    49  	),
    50  	BuildbucketRPCDurations: metric.NewCumulativeDistribution(
    51  		"cv/internal/buildbucket_rpc/durations",
    52  		"Distribution of RPC duration (in milliseconds).",
    53  		&types.MetricMetadata{Units: types.Milliseconds},
    54  		// Bucketer for 1ms..10m range since CV isn't going to wait longer than 10m
    55  		// anyway.
    56  		distribution.GeometricBucketer(math.Pow(float64(10*time.Minute/time.Millisecond), 1.0/nBuckets), nBuckets),
    57  		field.String("project"),
    58  		field.String("host"),
    59  		field.String("method"),
    60  		field.String("canonical_code"), // status.Code of the result as string in UPPER_CASE.
    61  	),
    62  	CLIngestionAttempted: metric.NewCounter(
    63  		"cv/internal/changelist/ingestion_attempted",
    64  		"Occurrences of CL updates by processing UpdateCLTask with an actual "+
    65  			"fetch operation in the updater backend",
    66  		nil,
    67  		field.String("requester"),
    68  		// Whether the CL ingestion mutated the CL entry.
    69  		// If false, it's either
    70  		// - the CL Update wasn't necessary
    71  		// - Gerrit API returned stale data
    72  		field.Bool("changed"),
    73  		// True if the ingestion was to retrieve the snapshot of a dep CL.
    74  		field.Bool("dep"),
    75  		// The LUCI project
    76  		field.String("project"),
    77  		// Whether the CL ingestion mutated the snapshot in the CL entity.
    78  		field.Bool("changed_snapshot"),
    79  	),
    80  	CLIngestionLatency: metric.NewCumulativeDistribution(
    81  		"cv/internal/changelist/ingestion_latency",
    82  		"Distribution of the time elapsed "+
    83  			"from the time of a Gerrit update event occurrence "+
    84  			"to the time of the snapshot ingested in CV",
    85  		&types.MetricMetadata{Units: types.Seconds},
    86  		// Bucketer for 1s...8h range since anything above 8h is too bad.
    87  		distribution.GeometricBucketer(
    88  			math.Pow(float64(8*time.Hour/time.Second), 1.0/nBuckets), nBuckets,
    89  		),
    90  		field.String("requester"),
    91  		field.Bool("dep"),
    92  		field.String("project"),
    93  		field.Bool("changed_snapshot"),
    94  	),
    95  	CLIngestionLatencyWithoutFetch: metric.NewCumulativeDistribution(
    96  		"cv/internal/changelist/ingestion_latency_without_fetch",
    97  		"Distribution of the time elapsed "+
    98  			"from the time of a Gerrit update event occurrence "+
    99  			"to the time of the snapshot ingested in CV, but excluding "+
   100  			"the time taken to fetch the snapshot from the backend",
   101  		&types.MetricMetadata{Units: types.Seconds},
   102  		// Bucketer for 1s...8h range since anything above 8h is too bad.
   103  		distribution.GeometricBucketer(
   104  			math.Pow(float64(8*time.Hour/time.Second), 1.0/nBuckets), nBuckets,
   105  		),
   106  		field.String("requester"),
   107  		field.Bool("dep"),
   108  		field.String("project"),
   109  		field.Bool("changed_snapshot"),
   110  	),
   111  	CLTriggererTaskCompleted: metric.NewCounter(
   112  		"cv/internal/cltriggerer/tasks/completed",
   113  		"Count of Chained CQ vote tasks completed",
   114  		nil,
   115  		// LUCI project
   116  		field.String("project"),
   117  		// Config Group name
   118  		field.String("config_group"),
   119  		// # of deps to trigger
   120  		field.Int("num_deps"),
   121  		// Status - skipped | succeeded | failed | canceled
   122  		field.String("status"),
   123  	),
   124  	CLTriggererTaskDuration: metric.NewCumulativeDistribution(
   125  		"cv/internal/cltriggerer/tasks/duration",
   126  		"Distribution of processing time for chained CQ vote processes",
   127  		&types.MetricMetadata{Units: types.Milliseconds},
   128  		// Bucketer for 1ms...20m range.
   129  		distribution.GeometricBucketer(
   130  			math.Pow(float64(20*time.Minute/time.Millisecond), 1.0/nBuckets), nBuckets,
   131  		),
   132  		// LUCI project
   133  		field.String("project"),
   134  		// Config Group name
   135  		field.String("config_group"),
   136  		// # of deps to trigger
   137  		field.Int("num_deps"),
   138  		// Status - skipped | succeeded | failed | canceled
   139  		field.String("status"),
   140  	),
   141  	BigQueryExportDelay: metric.NewCumulativeDistribution(
   142  		"cv/internal/runs/bq_export_delay",
   143  		"Distribution of the time elapsed from the time a Run ends to the "+
   144  			"time CV exports this Run to BigQuery",
   145  		&types.MetricMetadata{Units: types.Milliseconds},
   146  		// Bucketer for 1ms...8h range.
   147  		distribution.GeometricBucketer(
   148  			math.Pow(float64(8*time.Hour/time.Millisecond), 1.0/nBuckets), nBuckets,
   149  		),
   150  		field.String("project"),
   151  		field.String("config_group"),
   152  		field.String("mode"),
   153  	),
   154  	RunTryjobResultReportDelay: metric.NewCumulativeDistribution(
   155  		"cv/internal/runs/tryjob_result_report_delay",
   156  		"Distribution of the time elapsed from the time Run Tryjob execution has "+
   157  			"completed to the time LUCI CV successfully reports the result to the CL",
   158  		&types.MetricMetadata{Units: types.Milliseconds},
   159  		// Bucketer for 1ms...8h range.
   160  		distribution.GeometricBucketer(
   161  			math.Pow(float64(8*time.Hour/time.Millisecond), 1.0/nBuckets), nBuckets,
   162  		),
   163  		field.String("project"),
   164  		field.String("config_group"),
   165  		field.String("mode"),
   166  	),
   167  	RunResetTriggerAttempted: metric.NewCounter(
   168  		"cv/internal/runs/reset_trigger_attempted",
   169  		"Record the number of attempts to reset the triggers of Run",
   170  		nil,
   171  		field.String("project"),
   172  		field.String("config_group"),
   173  		field.String("mode"),
   174  		field.Bool("succeeded"),
   175  		field.String("gerrit_error"),
   176  	),
   177  	QuotaOp: metric.NewCounter(
   178  		"cv/internal/quota/op",
   179  		"Count of server quota operation",
   180  		nil,
   181  		field.String("project"),
   182  		field.String("policy_namespace"),
   183  		field.String("policy_name"),
   184  		field.String("policy_resource"),
   185  		field.String("op"),
   186  		field.String("status"),
   187  	),
   188  }