metrics_report.go 2.1 KB

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