-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to generate metrics documentation (#2043)
Signed-off-by: João Vilaça <[email protected]>
- Loading branch information
1 parent
f3e54f7
commit 2b7f786
Showing
4 changed files
with
247 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Containerized Data Importer metrics | ||
This document aims to help users that are not familiar with metrics exposed by the Containerized Data Importer. | ||
All metrics documented here are auto-generated by the utility tool `tools/metricsdocs` and reflects exactly what is being exposed. | ||
|
||
## Containerized Data Importer Metrics List | ||
### kubevirt_cdi_clone_dv_unusual_restartcount_total | ||
Total restart count in CDI Data Volume cloner pod | ||
### kubevirt_cdi_dataimportcron_outdated_total | ||
Total count of outdated DataImportCron imports | ||
### kubevirt_cdi_import_dv_unusual_restartcount_total | ||
Total restart count in CDI Data Volume importer pod | ||
### kubevirt_cdi_operator_up_total | ||
CDI operator status | ||
### kubevirt_cdi_upload_dv_unusual_restartcount_total | ||
Total restart count in CDI Data Volume upload server pod | ||
## Developing new metrics | ||
After developing new metrics or changing old ones, please run `make generate-doc` to regenerate this document. | ||
|
||
If you feel that the new metric doesn't follow these rules, please change `tools/metricsdocs` with your needs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"kubevirt.io/containerized-data-importer/pkg/operator/controller" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
// 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(controller.GetRecordRulesDesc("")) | ||
sort.Sort(metricsList) | ||
writeToFile(metricsList) | ||
} | ||
|
||
func writeToFile(metricsList metricList) { | ||
fmt.Print(opening) | ||
metricsList.writeOut() | ||
fmt.Print(footer) | ||
} | ||
|
||
type metric struct { | ||
name string | ||
description string | ||
} | ||
|
||
func recordRulesDescToMetricList(mdl []controller.RecordRulesDesc) metricList { | ||
res := make([]metric, len(mdl)) | ||
for i, md := range mdl { | ||
res[i] = metricDescriptionToMetric(md) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func metricDescriptionToMetric(rrd controller.RecordRulesDesc) metric { | ||
return metric{ | ||
name: rrd.Name, | ||
description: rrd.Description, | ||
} | ||
} | ||
|
||
func (m metric) writeOut() { | ||
fmt.Println("###", m.name) | ||
fmt.Println(m.description) | ||
} | ||
|
||
type metricList []metric | ||
|
||
// 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].name | ||
} | ||
|
||
// 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, metric{name: name, description: description}) | ||
} | ||
|
||
func (m metricList) writeOut() { | ||
for _, met := range m { | ||
met.writeOut() | ||
} | ||
} |