go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/appengine/gaeauth/server/internal/authdbimpl/metrics.go (about)

     1  // Copyright 2015 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 authdbimpl
    16  
    17  import (
    18  	"context"
    19  
    20  	"go.chromium.org/luci/common/clock"
    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  	latestSnapshotInfoDuration = metric.NewCumulativeDistribution(
    29  		"luci/authdb/methods/latest_snapshot_info",
    30  		"Distribution of 'GetLatestSnapshotInfo' call durations per result.",
    31  		&types.MetricMetadata{Units: types.Microseconds},
    32  		distribution.DefaultBucketer,
    33  		field.String("result"))
    34  
    35  	getSnapshotDuration = metric.NewCumulativeDistribution(
    36  		"luci/authdb/methods/get_snapshot",
    37  		"Distribution of 'GetAuthDBSnapshot' call durations per result.",
    38  		&types.MetricMetadata{Units: types.Microseconds},
    39  		distribution.DefaultBucketer,
    40  		field.String("result"))
    41  
    42  	syncAuthDBDuration = metric.NewCumulativeDistribution(
    43  		"luci/authdb/methods/sync_auth_db",
    44  		"Distribution of 'syncAuthDB' call durations per result.",
    45  		&types.MetricMetadata{Units: types.Microseconds},
    46  		distribution.DefaultBucketer,
    47  		field.String("result"))
    48  )
    49  
    50  func durationReporter(ctx context.Context, m metric.CumulativeDistribution) func(...any) {
    51  	startTs := clock.Now(ctx)
    52  	return func(fields ...any) {
    53  		m.Add(ctx, float64(clock.Since(ctx, startTs).Nanoseconds()/1000), fields...)
    54  	}
    55  }