metrics.go raw

   1  /*
   2   *
   3   * Copyright 2024 gRPC authors.
   4   *
   5   * Licensed under the Apache License, Version 2.0 (the "License");
   6   * you may not use this file except in compliance with the License.
   7   * You may obtain a copy of the License at
   8   *
   9   *     http://www.apache.org/licenses/LICENSE-2.0
  10   *
  11   * Unless required by applicable law or agreed to in writing, software
  12   * distributed under the License is distributed on an "AS IS" BASIS,
  13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14   * See the License for the specific language governing permissions and
  15   * limitations under the License.
  16   *
  17   */
  18  
  19  // Package stats contains experimental metrics/stats API's.
  20  package stats
  21  
  22  import "google.golang.org/grpc/stats"
  23  
  24  // MetricsRecorder records on metrics derived from metric registry.
  25  type MetricsRecorder interface {
  26  	// RecordInt64Count records the measurement alongside labels on the int
  27  	// count associated with the provided handle.
  28  	RecordInt64Count(handle *Int64CountHandle, incr int64, labels ...string)
  29  	// RecordFloat64Count records the measurement alongside labels on the float
  30  	// count associated with the provided handle.
  31  	RecordFloat64Count(handle *Float64CountHandle, incr float64, labels ...string)
  32  	// RecordInt64Histo records the measurement alongside labels on the int
  33  	// histo associated with the provided handle.
  34  	RecordInt64Histo(handle *Int64HistoHandle, incr int64, labels ...string)
  35  	// RecordFloat64Histo records the measurement alongside labels on the float
  36  	// histo associated with the provided handle.
  37  	RecordFloat64Histo(handle *Float64HistoHandle, incr float64, labels ...string)
  38  	// RecordInt64Gauge records the measurement alongside labels on the int
  39  	// gauge associated with the provided handle.
  40  	RecordInt64Gauge(handle *Int64GaugeHandle, incr int64, labels ...string)
  41  	// RecordInt64UpDownCounter records the measurement alongside labels on the int
  42  	// count associated with the provided handle.
  43  	RecordInt64UpDownCount(handle *Int64UpDownCountHandle, incr int64, labels ...string)
  44  }
  45  
  46  // AsyncMetricsRecorder records on asynchronous metrics derived from metric registry.
  47  type AsyncMetricsRecorder interface {
  48  	// RecordInt64AsyncGauge records the measurement alongside labels on the int
  49  	// count associated with the provided handle asynchronously
  50  	RecordInt64AsyncGauge(handle *Int64AsyncGaugeHandle, incr int64, labels ...string)
  51  }
  52  
  53  // Metrics is an experimental legacy alias of the now-stable stats.MetricSet.
  54  // Metrics will be deleted in a future release.
  55  type Metrics = stats.MetricSet
  56  
  57  // Metric was replaced by direct usage of strings.
  58  type Metric = string
  59  
  60  // NewMetrics is an experimental legacy alias of the now-stable
  61  // stats.NewMetricSet.  NewMetrics will be deleted in a future release.
  62  func NewMetrics(metrics ...Metric) *Metrics {
  63  	return stats.NewMetricSet(metrics...)
  64  }
  65