go.etcd.io/etcd@v3.3.27+incompatible/functional/tester/metrics_report.go (about)

     1  // Copyright 2018 The etcd 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 tester
    16  
    17  import (
    18  	"fmt"
    19  	"sort"
    20  
    21  	"github.com/prometheus/client_golang/prometheus"
    22  )
    23  
    24  var (
    25  	caseTotal = make(map[string]int)
    26  
    27  	caseTotalCounter = prometheus.NewCounterVec(
    28  		prometheus.CounterOpts{
    29  			Namespace: "etcd",
    30  			Subsystem: "funcational_tester",
    31  			Name:      "case_total",
    32  			Help:      "Total number of finished test cases",
    33  		},
    34  		[]string{"desc"},
    35  	)
    36  
    37  	caseFailedTotalCounter = prometheus.NewCounterVec(
    38  		prometheus.CounterOpts{
    39  			Namespace: "etcd",
    40  			Subsystem: "funcational_tester",
    41  			Name:      "case_failed_total",
    42  			Help:      "Total number of failed test cases",
    43  		},
    44  		[]string{"desc"},
    45  	)
    46  
    47  	roundTotalCounter = prometheus.NewCounter(
    48  		prometheus.CounterOpts{
    49  			Namespace: "etcd",
    50  			Subsystem: "funcational_tester",
    51  			Name:      "round_total",
    52  			Help:      "Total number of finished test rounds.",
    53  		})
    54  
    55  	roundFailedTotalCounter = prometheus.NewCounter(
    56  		prometheus.CounterOpts{
    57  			Namespace: "etcd",
    58  			Subsystem: "funcational_tester",
    59  			Name:      "round_failed_total",
    60  			Help:      "Total number of failed test rounds.",
    61  		})
    62  )
    63  
    64  func init() {
    65  	prometheus.MustRegister(caseTotalCounter)
    66  	prometheus.MustRegister(caseFailedTotalCounter)
    67  	prometheus.MustRegister(roundTotalCounter)
    68  	prometheus.MustRegister(roundFailedTotalCounter)
    69  }
    70  
    71  func printReport() {
    72  	rows := make([]string, 0, len(caseTotal))
    73  	for k, v := range caseTotal {
    74  		rows = append(rows, fmt.Sprintf("%s: %d", k, v))
    75  	}
    76  	sort.Strings(rows)
    77  
    78  	println()
    79  	for _, row := range rows {
    80  		fmt.Println(row)
    81  	}
    82  	println()
    83  }