go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/metrics/public.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  	bbmetrics "go.chromium.org/luci/buildbucket/metrics"
    22  	"go.chromium.org/luci/common/tsmon/distribution"
    23  	"go.chromium.org/luci/common/tsmon/field"
    24  	"go.chromium.org/luci/common/tsmon/metric"
    25  	"go.chromium.org/luci/common/tsmon/types"
    26  )
    27  
    28  const nBuckets = 100
    29  
    30  // Public contains a collection of public LUCI CV metric definitions.
    31  var Public = struct {
    32  	RunCreated         metric.Counter
    33  	RunStarted         metric.Counter
    34  	RunEnded           metric.Counter
    35  	RunDuration        metric.CumulativeDistribution
    36  	RunTotalDuration   metric.CumulativeDistribution
    37  	ActiveRunCount     metric.Int
    38  	ActiveRunDuration  metric.NonCumulativeDistribution
    39  	PendingRunCount    metric.Int
    40  	PendingRunDuration metric.NonCumulativeDistribution
    41  	MaxPendingRunAge   metric.Int
    42  
    43  	TryjobLaunched        metric.Counter
    44  	TryjobEnded           metric.Counter
    45  	TryjobBuilderPresence metric.Bool
    46  
    47  	RunQuotaRejection metric.Counter
    48  }{
    49  	RunCreated: metric.NewCounter(
    50  		"cv/runs/created",
    51  		"Count of the newly created Runs",
    52  		nil,
    53  		field.String("project"),
    54  		field.String("config_group"),
    55  		field.String("mode"),
    56  	),
    57  	RunStarted: metric.NewCounter(
    58  		"cv/runs/started",
    59  		"Count of the started Runs",
    60  		nil,
    61  		field.String("project"),
    62  		field.String("config_group"),
    63  		field.String("mode"),
    64  	),
    65  	RunEnded: metric.NewCounter(
    66  		"cv/runs/ended",
    67  		"Count of the ended Runs",
    68  		nil,
    69  		field.String("project"),
    70  		field.String("config_group"),
    71  		field.String("mode"),
    72  		field.String("status"),
    73  		field.Bool("successfully_started"),
    74  	),
    75  	RunDuration: metric.NewCumulativeDistribution(
    76  		"cv/runs/ended/durations",
    77  		"The distribution of time elapsed from Run start to Run end",
    78  		&types.MetricMetadata{Units: types.Seconds},
    79  		// Bucketer for 1s .. 2d range.
    80  		distribution.GeometricBucketer(math.Pow(float64(2*24*time.Hour/time.Second), 1.0/nBuckets), nBuckets),
    81  		field.String("project"),
    82  		field.String("config_group"),
    83  		field.String("mode"),
    84  		field.String("status"),
    85  	),
    86  	RunTotalDuration: metric.NewCumulativeDistribution(
    87  		"cv/runs/ended/total_durations",
    88  		"The distribution of time elapsed from Run creation to Run end",
    89  		&types.MetricMetadata{Units: types.Seconds},
    90  		// Bucketer for 1s .. 2d range.
    91  		distribution.GeometricBucketer(math.Pow(float64(2*24*time.Hour/time.Second), 1.0/nBuckets), nBuckets),
    92  		field.String("project"),
    93  		field.String("config_group"),
    94  		field.String("mode"),
    95  		field.String("status"),
    96  		field.Bool("successfully_started"),
    97  	),
    98  	ActiveRunCount: metric.NewInt(
    99  		"cv/runs/active",
   100  		"The current count of the Runs that are active (started but not ended yet)",
   101  		nil,
   102  		field.String("project"),
   103  		field.String("config_group"),
   104  		field.String("mode"),
   105  	),
   106  	ActiveRunDuration: metric.NewNonCumulativeDistribution(
   107  		"cv/runs/active/durations",
   108  		"The distribution of all the currently active run durations (started but not ended yet)",
   109  		&types.MetricMetadata{Units: types.Seconds},
   110  		// Bucketer for 1s .. 2d range.
   111  		distribution.GeometricBucketer(math.Pow(float64(2*24*time.Hour/time.Second), 1.0/nBuckets), nBuckets),
   112  		field.String("project"),
   113  		field.String("config_group"),
   114  		field.String("mode"),
   115  	),
   116  	PendingRunCount: metric.NewInt(
   117  		"cv/runs/pending",
   118  		"The current count of the Runs that are pending (created but not started yet)",
   119  		nil,
   120  		field.String("project"),
   121  		field.String("config_group"),
   122  		field.String("mode"),
   123  	),
   124  	PendingRunDuration: metric.NewNonCumulativeDistribution(
   125  		"cv/runs/pending/durations",
   126  		"The distribution of all the currently pending Run durations (created but not started yet)",
   127  		&types.MetricMetadata{Units: types.Milliseconds},
   128  		// Bucketer for 1ms .. 2h range.
   129  		distribution.GeometricBucketer(math.Pow(float64(2*time.Hour/time.Millisecond), 1.0/nBuckets), nBuckets),
   130  		field.String("project"),
   131  		field.String("config_group"),
   132  		field.String("mode"),
   133  	),
   134  	MaxPendingRunAge: metric.NewInt(
   135  		"cv/runs/max_pending_age",
   136  		"The age of the oldest run that has been created but not started yet (aka age of the oldest pending run)",
   137  		&types.MetricMetadata{Units: types.Milliseconds},
   138  		field.String("project"),
   139  		field.String("config_group"),
   140  		field.String("mode"),
   141  	),
   142  	TryjobLaunched: metric.NewCounterWithTargetType(
   143  		"cv/tryjobs/launched",
   144  		((*bbmetrics.BuilderTarget)(nil)).Type(),
   145  		"Count of Tryjobs launched by LUCI CV",
   146  		nil,
   147  		field.String("cv_project"),
   148  		field.String("config_group"),
   149  		field.Bool("critical"),
   150  		field.Bool("retry"),
   151  	),
   152  	TryjobEnded: metric.NewCounterWithTargetType(
   153  		"cv/tryjobs/ended",
   154  		((*bbmetrics.BuilderTarget)(nil)).Type(),
   155  		"Count of Tryjobs launched by LUCI CV that have ended",
   156  		nil,
   157  		field.String("cv_project"),
   158  		field.String("config_group"),
   159  		field.Bool("critical"),
   160  		field.Bool("retry"),
   161  		field.String("status"),
   162  	),
   163  	TryjobBuilderPresence: metric.NewBoolWithTargetType(
   164  		"cv/tryjobs/builders/presence",
   165  		((*bbmetrics.BuilderTarget)(nil)).Type(),
   166  		"Provides a list of configured builders in the Project config",
   167  		nil,
   168  		field.String("cv_project"),
   169  		field.String("config_group"),
   170  		field.Bool("includable_only"),
   171  		field.Bool("path_cond"),
   172  		field.Bool("experimental"),
   173  	),
   174  	RunQuotaRejection: metric.NewCounter(
   175  		"cv/runs/quota/rejected",
   176  		"Count of run rejection",
   177  		nil,
   178  		field.String("project"),
   179  		field.String("config_group"),
   180  		field.String("gerrit_account_id"), // `{gerrit_host}/{account_id}`.
   181  	),
   182  }