forked from kubevirt/containerized-data-importer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetricsdocs.go
101 lines (80 loc) · 2.53 KB
/
metricsdocs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"sort"
"strings"
"kubevirt.io/containerized-data-importer/pkg/monitoring"
)
// constant parts of the file
const (
title = "# Containerized Data Importer metrics\n"
background = "This document aims to help users that are not familiar with metrics exposed by the Containerized Data Importer.\n" +
"All metrics documented here are auto-generated by the utility tool `tools/metricsdocs` and reflects exactly what is being exposed.\n\n"
KVSpecificMetrics = "## Containerized Data Importer Metrics List\n"
opening = title +
background +
KVSpecificMetrics
// footer
footerHeading = "## Developing new metrics\n"
footerContent = "After developing new metrics or changing old ones, please run `make generate-doc` to regenerate this document.\n\n" +
"If you feel that the new metric doesn't follow these rules, please change `tools/metricsdocs` with your needs.\n"
footer = footerHeading + footerContent
)
func main() {
metricsList := recordRulesDescToMetricList(monitoring.GetRecordRulesDesc(""))
for _, opts := range monitoring.MetricOptsList {
metricsList = append(metricsList, opts)
}
sort.Slice(metricsList, func(i, j int) bool {
return metricsList[i].Name < metricsList[j].Name
})
writeToFile(metricsList)
}
func writeToFile(metricsList metricList) {
fmt.Print(opening)
metricsList.writeOut()
fmt.Print(footer)
}
func recordRulesDescToMetricList(mdl []monitoring.RecordRulesDesc) metricList {
res := make([]monitoring.MetricOpts, len(mdl))
for i, md := range mdl {
res[i] = metricDescriptionToMetric(md)
}
return res
}
func metricDescriptionToMetric(rrd monitoring.RecordRulesDesc) monitoring.MetricOpts {
return monitoring.MetricOpts{
Name: rrd.Opts.Name,
Help: rrd.Opts.Help,
Type: rrd.Opts.Type,
}
}
func writeOut(m monitoring.MetricOpts) {
fmt.Println("###", m.Name)
fmt.Println(m.Help + ". Type: " + m.Type + ".")
}
type metricList []monitoring.MetricOpts
// Len implements sort.Interface.Len
func (m metricList) Len() int {
return len(m)
}
// Less implements sort.Interface.Less
func (m metricList) Less(i, j int) bool {
return m[i].Name < m[j].Help
}
// Swap implements sort.Interface.Swap
func (m metricList) Swap(i, j int) {
m[i], m[j] = m[j], m[i]
}
func (m *metricList) add(line string) {
split := strings.Split(line, " ")
name := split[2]
split[3] = strings.Title(split[3])
description := strings.Join(split[3:], " ")
*m = append(*m, monitoring.MetricOpts{Name: name, Help: description})
}
func (m metricList) writeOut() {
for _, met := range m {
writeOut(met)
}
}