github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/ci/metrics.go (about)

     1  package ci
     2  
     3  import "github.com/prometheus/client_golang/prometheus"
     4  
     5  // TestExecutionMetricsCollectors returns a list of Prometheus metrics collectors for test execution.
     6  func TestExecutionMetricsCollectors() []prometheus.Collector {
     7  	return []prometheus.Collector{
     8  		cloneTimeGauge,
     9  		validationTimeGauge,
    10  		testExecutionTimeGauge,
    11  		testsStartedCounter,
    12  		testsFailedCounter,
    13  		testsSucceededCounter,
    14  	}
    15  }
    16  
    17  var (
    18  	cloneTimeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
    19  		Name: "quickfeed_clone_repositories_time",
    20  		Help: "The time to clone tests and student repository for test execution.",
    21  	}, []string{"user", "course"})
    22  
    23  	validationTimeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
    24  		Name: "quickfeed_repository_validation_time",
    25  		Help: "The time to validate student repository for issues.",
    26  	}, []string{"user", "course"})
    27  
    28  	testExecutionTimeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
    29  		Name: "quickfeed_test_execution_time",
    30  		Help: "The time to run test execution.",
    31  	}, []string{"user", "course"})
    32  
    33  	testsStartedCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    34  		Name: "quickfeed_test_execution_attempts",
    35  		Help: "Total number of times test execution was attempted",
    36  	}, []string{"user", "course"})
    37  
    38  	testsFailedCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    39  		Name: "quickfeed_test_execution_failed",
    40  		Help: "Total number of times test execution failed",
    41  	}, []string{"user", "course"})
    42  
    43  	testsFailedWithOutputCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    44  		Name: "quickfeed_test_execution_failed_with_output",
    45  		Help: "Total number of times test execution failed with output",
    46  	}, []string{"user", "course"})
    47  
    48  	testsFailedExtractResultsCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    49  		Name: "quickfeed_test_execution_failed_to_extract_results",
    50  		Help: "Total number of times test execution failed to extract results",
    51  	}, []string{"user", "course"})
    52  
    53  	testsSucceededCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    54  		Name: "quickfeed_test_execution_succeeded",
    55  		Help: "Total number of times test execution succeeded",
    56  	}, []string{"user", "course"})
    57  )
    58  
    59  func timer(jobOwner, course string, gauge *prometheus.GaugeVec) func() {
    60  	responseTimer := prometheus.NewTimer(prometheus.ObserverFunc(
    61  		gauge.WithLabelValues(jobOwner, course).Set),
    62  	)
    63  	return func() { responseTimer.ObserveDuration() }
    64  }