update documentation for metrics with deprecated version and version of k8s

Change-Id: Ia04d21f6644e7fc498304c0035d6f1ae58766a91
This commit is contained in:
Han Kang 2022-11-03 14:54:26 -07:00
parent 7a46516369
commit dfff6e4364
6 changed files with 825 additions and 470 deletions

View File

@ -37,3 +37,16 @@ To update the documented list of metrics for k8s/website, please run:
```console
./test/instrumentation/update-documentation.sh
```
Then you need to copy the output to the appropriate website directory. Please
define the directory in which the website repo lives in an env variable like so:
```shell
export WEBSITE_ROOT=<path to website root>
```
And then from the root of the k8s/k8s repository, please run this command:
```shell
cp ./test/instrumentation/documentation/documentation.md $WEBSITE_ROOT/content/en/docs/reference/instrumentation/metrics.md
```

View File

@ -287,31 +287,11 @@ func (c *metricDecoder) decodeMetricVecForTimingRatioHistogram(call *ast.CallExp
func (c *metricDecoder) decodeLabelsFromArray(exprs []ast.Expr) ([]string, error) {
retval := []string{}
for _, e := range exprs {
id, ok := e.(*ast.Ident)
if !ok {
if bl, ok := e.(*ast.BasicLit); ok {
v, err := stringValue(bl)
if err != nil {
return nil, err
}
retval = append(retval, v)
continue
}
return nil, newDecodeErrorf(e, errInvalidNewMetricCall)
v, err := c.decodeString(e)
if err != nil || v == nil {
return nil, newDecodeErrorf(e, errNonStringAttribute)
}
variableExpr, found := c.variables[id.Name]
if !found {
return nil, newDecodeErrorf(e, "couldn't find variable for labels")
}
bl, ok := variableExpr.(*ast.BasicLit)
if !ok {
return nil, newDecodeErrorf(e, "couldn't interpret variable for labels")
}
v, err := stringValue(bl)
if err != nil {
return nil, err
}
retval = append(retval, v)
retval = append(retval, *v)
}
return retval, nil
@ -652,9 +632,7 @@ func (c *metricDecoder) decodeInt64(expr ast.Expr) (int64, error) {
return i, err2
}
}
}
case *ast.CallExpr:
_, ok := v.Fun.(*ast.SelectorExpr)
if !ok {

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@ import (
"text/template"
"time"
flag "github.com/spf13/pflag"
"gopkg.in/yaml.v2"
"k8s.io/component-base/metrics"
@ -47,9 +48,10 @@ description: >-
Details of the metric data that Kubernetes components export.
---
## Metrics (v{{.GeneratedVersion}})
## Metrics (auto-generated {{.GeneratedDate.Format "2006 Jan 02"}})
<!-- (auto-generated {{.GeneratedDate.Format "2006 Jan 02"}}) -->
<!-- (auto-generated v{{.GeneratedVersion}}) -->
This page details the metrics that different Kubernetes components export. You can query the metrics endpoint for these
components using an HTTP scrape, and fetch the current metrics data in Prometheus format.
@ -64,6 +66,7 @@ components using an HTTP scrape, and fetch the current metrics data in Prometheu
<th class="metric_help">Help</th>
<th class="metric_labels">Labels</th>
<th class="metric_const_labels">Const Labels</th>
<th class="metric_deprecated_version">Deprecated Version</th>
</tr>
</thead>
<tbody>
@ -72,8 +75,9 @@ components using an HTTP scrape, and fetch the current metrics data in Prometheu
<td class="metric_stability_level" data-stability="{{$metric.StabilityLevel | ToLower}}">{{$metric.StabilityLevel}}</td>
<td class="metric_type" data-type="{{$metric.Type | ToLower}}">{{$metric.Type}}</td>
<td class="metric_description">{{$metric.Help}}</td>
{{if not $metric.Labels }}<td class="metric_labels_varying">None</td>{{else }}<td class="metric_labels_varying">{{range $label := $metric.Labels}}<div class="metric_label">{{$label}}</div>{{end}}</td>{{end}}
{{if not $metric.ConstLabels }}<td class="metric_labels_constant">None</td>{{else }}<td class="metric_labels_constant">{{$metric.ConstLabels}}</td>{{end}}</tr>{{end}}
{{if not $metric.Labels }}<td class="metric_labels_varying"></td>{{else }}<td class="metric_labels_varying">{{range $label := $metric.Labels}}<div class="metric_label">{{$label}}</div>{{end}}</td>{{end}}
{{if not $metric.ConstLabels }}<td class="metric_labels_constant"></td>{{else }}<td class="metric_labels_constant">{{range $key, $value := $metric.ConstLabels}}<div class="metric_label">{{$key}}:{{$value}}</div>{{end}}</td>{{end}}
{{if not $metric.DeprecatedVersion }}<td class="metric_deprecated_version"></td>{{else }}<td class="metric_deprecated_version">{{$metric.DeprecatedVersion}}</td>{{end}}</tr>{{end}}
</tbody>
</table>
@ -88,6 +92,7 @@ components using an HTTP scrape, and fetch the current metrics data in Prometheu
<th class="metric_help">Help</th>
<th class="metric_labels">Labels</th>
<th class="metric_const_labels">Const Labels</th>
<th class="metric_deprecated_version">Deprecated Version</th>
</tr>
</thead>
<tbody>
@ -96,20 +101,28 @@ components using an HTTP scrape, and fetch the current metrics data in Prometheu
<td class="metric_stability_level" data-stability="{{$metric.StabilityLevel | ToLower}}">{{$metric.StabilityLevel}}</td>
<td class="metric_type" data-type="{{$metric.Type | ToLower}}">{{$metric.Type}}</td>
<td class="metric_description">{{$metric.Help}}</td>
{{if not $metric.Labels }}<td class="metric_labels_varying">None</td>{{else }}<td class="metric_labels_varying">{{range $label := $metric.Labels}}<div class="metric_label">{{$label}}</div>{{end}}</td>{{end}}
{{if not $metric.ConstLabels }}<td class="metric_labels_constant">None</td>{{else }}<td class="metric_labels_constant">{{$metric.ConstLabels}}</td>{{end}}</tr>{{end}}
{{if not $metric.Labels }}<td class="metric_labels_varying"></td>{{else }}<td class="metric_labels_varying">{{range $label := $metric.Labels}}<div class="metric_label">{{$label}}</div>{{end}}</td>{{end}}
{{if not $metric.ConstLabels }}<td class="metric_labels_constant"></td>{{else }}<td class="metric_labels_constant">{{range $key, $value := $metric.ConstLabels}}<div class="metric_label">{{$key}}:{{$value}}</div>{{end}}</td>{{end}}
{{if not $metric.DeprecatedVersion }}<td class="metric_deprecated_version"></td>{{else }}<td class="metric_deprecated_version">{{$metric.DeprecatedVersion}}</td>{{end}}</tr>{{end}}
</tbody>
</table>
`
)
type templateData struct {
AlphaMetrics []metric
StableMetrics []metric
GeneratedDate time.Time
AlphaMetrics []metric
StableMetrics []metric
GeneratedDate time.Time
GeneratedVersion string
}
func main() {
var major string
var minor string
flag.StringVar(&major, "major", "", "k8s major version")
flag.StringVar(&minor, "minor", "", "k8s minor version")
println(major, minor)
flag.Parse()
dat, err := os.ReadFile("test/instrumentation/documentation/documentation-list.yaml")
if err == nil {
var parsedMetrics []metric
@ -131,9 +144,10 @@ func main() {
}
sortedMetrics := byStabilityLevel(parsedMetrics)
data := templateData{
AlphaMetrics: sortedMetrics["ALPHA"],
StableMetrics: sortedMetrics["STABLE"],
GeneratedDate: time.Now(),
AlphaMetrics: sortedMetrics["ALPHA"],
StableMetrics: sortedMetrics["STABLE"],
GeneratedDate: time.Now(),
GeneratedVersion: fmt.Sprintf("%v.%v", major, parseMinor(minor)),
}
err = t.Execute(&tpl, data)
if err != nil {
@ -192,3 +206,7 @@ func byStabilityLevel(ms []metric) map[string][]metric {
}
return res
}
func parseMinor(m string) string {
return strings.Trim(m, `+`)
}

View File

@ -121,7 +121,9 @@ kube::update::documentation::list() {
kube::update::documentation() {
stability_check_setup
temp_file=$(mktemp)
doUpdateDocs=$(go run "test/instrumentation/documentation/main.go" -- 1>"${temp_file}")
arg1=$1
arg2=$2
doUpdateDocs=$(go run "test/instrumentation/documentation/main.go" --major $arg1 --minor $arg2 -- 1>"${temp_file}")
if ! $doUpdateDocs; then
echo "${red}!!! updating documentation has failed! ${reset}" >&2
exit 1

View File

@ -24,6 +24,12 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
source "${KUBE_ROOT}/test/instrumentation/stability-utils.sh"
source "${KUBE_ROOT}/hack/lib/version.sh"
# extract version env variables so we can pass them in
kube::version::get_version_vars
# update the documented list of metrics
kube::update::documentation::list
kube::update::documentation
# now write the actual documentation file
kube::update::documentation $KUBE_GIT_MAJOR $KUBE_GIT_MINOR