github.com/pvitto98/fabric@v2.1.1+incompatible/common/metrics/provider.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package metrics
     8  
     9  // A Provider is an abstraction for a metrics provider. It is a factory for
    10  // Counter, Gauge, and Histogram meters.
    11  type Provider interface {
    12  	// NewCounter creates a new instance of a Counter.
    13  	NewCounter(CounterOpts) Counter
    14  	// NewGauge creates a new instance of a Gauge.
    15  	NewGauge(GaugeOpts) Gauge
    16  	// NewHistogram creates a new instance of a Histogram.
    17  	NewHistogram(HistogramOpts) Histogram
    18  }
    19  
    20  // A Counter represents a monotonically increasing value.
    21  type Counter interface {
    22  	// With is used to provide label values when updating a Counter. This must be
    23  	// used to provide values for all LabelNames provided to CounterOpts.
    24  	With(labelValues ...string) Counter
    25  
    26  	// Add increments a counter value.
    27  	Add(delta float64)
    28  }
    29  
    30  // CounterOpts is used to provide basic information about a counter to the
    31  // metrics subsystem.
    32  type CounterOpts struct {
    33  	// Namespace, Subsystem, and Name are components of the fully-qualified name
    34  	// of the Metric. The fully-qualified aneme is created by joining these
    35  	// components with an appropriate separator. Only Name is mandatory, the
    36  	// others merely help structuring the name.
    37  	Namespace string
    38  	Subsystem string
    39  	Name      string
    40  
    41  	// Help provides information about this metric.
    42  	Help string
    43  
    44  	// LabelNames provides the names of the labels that can be attached to this
    45  	// metric. When a metric is recorded, label values must be provided for each
    46  	// of these label names.
    47  	LabelNames []string
    48  
    49  	// LabelHelp provides help information for labels. When set, this information
    50  	// will be used to populate the documentation.
    51  	LabelHelp map[string]string
    52  
    53  	// StatsdFormat determines how the fully-qualified statsd bucket name is
    54  	// constructed from Namespace, Subsystem, Name, and Labels. This is done by
    55  	// including field references in `%{reference}` escape sequences.
    56  	//
    57  	// The following reference names are supported:
    58  	// - #namespace   - the value of Namespace
    59  	// - #subsystem   - the value of Subsystem
    60  	// - #name        - the value of Name
    61  	// - #fqname      - the fully-qualified metric name
    62  	// - label_name   - the value associated with the named label
    63  	//
    64  	// The result of the formatting must be a valid statsd bucket name.
    65  	StatsdFormat string
    66  }
    67  
    68  // A Gauge is a meter that expresses the current value of some metric.
    69  type Gauge interface {
    70  	// With is used to provide label values when recording a Gauge value. This
    71  	// must be used to provide values for all LabelNames provided to GaugeOpts.
    72  	With(labelValues ...string) Gauge
    73  
    74  	// Add increments a Gauge value.
    75  	Add(delta float64) // TODO: consider removing
    76  
    77  	// Set is used to update the current value associted with a Gauge.
    78  	Set(value float64)
    79  }
    80  
    81  // GaugeOpts is used to provide basic information about a gauge to the
    82  // metrics subsystem.
    83  type GaugeOpts struct {
    84  	// Namespace, Subsystem, and Name are components of the fully-qualified name
    85  	// of the Metric. The fully-qualified aneme is created by joining these
    86  	// components with an appropriate separator. Only Name is mandatory, the
    87  	// others merely help structuring the name.
    88  	Namespace string
    89  	Subsystem string
    90  	Name      string
    91  
    92  	// Help provides information about this metric.
    93  	Help string
    94  
    95  	// LabelNames provides the names of the labels that can be attached to this
    96  	// metric. When a metric is recorded, label values must be provided for each
    97  	// of these label names.
    98  	LabelNames []string
    99  
   100  	// LabelHelp provides help information for labels. When set, this information
   101  	// will be used to populate the documentation.
   102  	LabelHelp map[string]string
   103  
   104  	// StatsdFormat determines how the fully-qualified statsd bucket name is
   105  	// constructed from Namespace, Subsystem, Name, and Labels. This is done by
   106  	// including field references in `%{reference}` escape sequences.
   107  	//
   108  	// The following reference names are supported:
   109  	// - #namespace   - the value of Namespace
   110  	// - #subsystem   - the value of Subsystem
   111  	// - #name        - the value of Name
   112  	// - #fqname      - the fully-qualified metric name
   113  	// - label_name   - the value associated with the named label
   114  	//
   115  	// The result of the formatting must be a valid statsd bucket name.
   116  	StatsdFormat string
   117  }
   118  
   119  // A Histogram is a meter that records an observed value into quantized
   120  // buckets.
   121  type Histogram interface {
   122  	// With is used to provide label values when recording a Histogram
   123  	// observation. This must be used to provide values for all LabelNames
   124  	// provided to HistogramOpts.
   125  	With(labelValues ...string) Histogram
   126  	Observe(value float64)
   127  }
   128  
   129  // HistogramOpts is used to provide basic information about a histogram to the
   130  // metrics subsystem.
   131  type HistogramOpts struct {
   132  	// Namespace, Subsystem, and Name are components of the fully-qualified name
   133  	// of the Metric. The fully-qualified aneme is created by joining these
   134  	// components with an appropriate separator. Only Name is mandatory, the
   135  	// others merely help structuring the name.
   136  	Namespace string
   137  	Subsystem string
   138  	Name      string
   139  
   140  	// Help provides information about this metric.
   141  	Help string
   142  
   143  	// Buckets can be used to provide the bucket boundaries for Prometheus. When
   144  	// omitted, the default Prometheus bucket values are used.
   145  	Buckets []float64
   146  
   147  	// LabelNames provides the names of the labels that can be attached to this
   148  	// metric. When a metric is recorded, label values must be provided for each
   149  	// of these label names.
   150  	LabelNames []string
   151  
   152  	// LabelHelp provides help information for labels. When set, this information
   153  	// will be used to populate the documentation.
   154  	LabelHelp map[string]string
   155  
   156  	// StatsdFormat determines how the fully-qualified statsd bucket name is
   157  	// constructed from Namespace, Subsystem, Name, and Labels. This is done by
   158  	// including field references in `%{reference}` escape sequences.
   159  	//
   160  	// The following reference names are supported:
   161  	// - #namespace   - the value of Namespace
   162  	// - #subsystem   - the value of Subsystem
   163  	// - #name        - the value of Name
   164  	// - #fqname      - the fully-qualified metric name
   165  	// - label_name   - the value associated with the named label
   166  	//
   167  	// The result of the formatting must be a valid statsd bucket name.
   168  	StatsdFormat string
   169  }