github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/cruisectl.go (about)

     1  package metrics
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  	"github.com/prometheus/client_golang/prometheus/promauto"
     8  
     9  	"github.com/onflow/flow-go/module"
    10  )
    11  
    12  // CruiseCtlMetrics captures metrics about the Block Rate Controller, which adjusts
    13  // the proposal duration to attain a target epoch switchover time.
    14  type CruiseCtlMetrics struct {
    15  	proportionalErr          prometheus.Gauge
    16  	integralErr              prometheus.Gauge
    17  	derivativeErr            prometheus.Gauge
    18  	targetProposalDur        prometheus.Gauge
    19  	controllerOutput         prometheus.Gauge
    20  	proposalPublicationDelay prometheus.Gauge
    21  }
    22  
    23  var _ module.CruiseCtlMetrics = (*CruiseCtlMetrics)(nil)
    24  
    25  func NewCruiseCtlMetrics() *CruiseCtlMetrics {
    26  	return &CruiseCtlMetrics{
    27  		proportionalErr: promauto.NewGauge(prometheus.GaugeOpts{
    28  			Name:      "proportional_err_s",
    29  			Namespace: namespaceConsensus,
    30  			Subsystem: subsystemCruiseCtl,
    31  			Help:      "The current proportional error measured by the controller",
    32  		}),
    33  		integralErr: promauto.NewGauge(prometheus.GaugeOpts{
    34  			Name:      "integral_err_s",
    35  			Namespace: namespaceConsensus,
    36  			Subsystem: subsystemCruiseCtl,
    37  			Help:      "The current integral error measured by the controller",
    38  		}),
    39  		derivativeErr: promauto.NewGauge(prometheus.GaugeOpts{
    40  			Name:      "derivative_err_per_s",
    41  			Namespace: namespaceConsensus,
    42  			Subsystem: subsystemCruiseCtl,
    43  			Help:      "The current derivative error measured by the controller",
    44  		}),
    45  		targetProposalDur: promauto.NewGauge(prometheus.GaugeOpts{
    46  			Name:      "target_proposal_dur_s",
    47  			Namespace: namespaceConsensus,
    48  			Subsystem: subsystemCruiseCtl,
    49  			Help:      "The current target duration from parent to child proposal [seconds]",
    50  		}),
    51  		controllerOutput: promauto.NewGauge(prometheus.GaugeOpts{
    52  			Name:      "controller_output_s",
    53  			Namespace: namespaceConsensus,
    54  			Subsystem: subsystemCruiseCtl,
    55  			Help:      "The most recent output of the controller [seconds]; the adjustment to subtract from the baseline proposal duration",
    56  		}),
    57  		proposalPublicationDelay: promauto.NewGauge(prometheus.GaugeOpts{
    58  			Name:      "proposal_publication_delay_s",
    59  			Namespace: namespaceConsensus,
    60  			Subsystem: subsystemCruiseCtl,
    61  			Help:      "Effective delay the controller imposes on publishing the node's own proposals [seconds]; with all limits of authority",
    62  		}),
    63  	}
    64  }
    65  
    66  func (c *CruiseCtlMetrics) PIDError(p, i, d float64) {
    67  	c.proportionalErr.Set(p)
    68  	c.integralErr.Set(i)
    69  	c.derivativeErr.Set(d)
    70  }
    71  
    72  func (c *CruiseCtlMetrics) TargetProposalDuration(duration time.Duration) {
    73  	c.targetProposalDur.Set(duration.Seconds())
    74  }
    75  
    76  func (c *CruiseCtlMetrics) ControllerOutput(duration time.Duration) {
    77  	c.controllerOutput.Set(duration.Seconds())
    78  }
    79  
    80  func (c *CruiseCtlMetrics) ProposalPublicationDelay(duration time.Duration) {
    81  	c.proposalPublicationDelay.Set(duration.Seconds())
    82  }