mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
refactor static analysis code for stability framework
Change-Id: I4049f16063264603fb61cbeb0cdb4010267fc19c
This commit is contained in:
parent
91dbd82cde
commit
78704ae47d
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
@ -165,23 +164,15 @@ func (c *metricDecoder) decodeDesc(ce *ast.CallExpr) (metric, error) {
|
||||
func (c *metricDecoder) decodeString(expr ast.Expr) (*string, error) {
|
||||
switch e := expr.(type) {
|
||||
case *ast.BasicLit:
|
||||
s, err := stringValue(e)
|
||||
return &s, err
|
||||
case *ast.Ident:
|
||||
variableExpr, found := c.variables[e.Name]
|
||||
if !found {
|
||||
return nil, fmt.Errorf("can't decode string")
|
||||
value, err := stringValue(e)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bl, ok := variableExpr.(*ast.BasicLit)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can't decode string")
|
||||
}
|
||||
v, err := stringValue(bl)
|
||||
return &v, err
|
||||
return &value, nil
|
||||
case *ast.CallExpr:
|
||||
firstArg, secondArg, thirdArg, err := c.decodeBuildFQNameArguments(e)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
se, ok := e.Fun.(*ast.SelectorExpr)
|
||||
if ok {
|
||||
@ -192,22 +183,70 @@ func (c *metricDecoder) decodeString(expr ast.Expr) (*string, error) {
|
||||
return &n, nil
|
||||
}
|
||||
}
|
||||
case *ast.SelectorExpr:
|
||||
s, ok := e.X.(*ast.Ident)
|
||||
if !ok {
|
||||
return nil, newDecodeErrorf(e, errExprNotIdent, e.X)
|
||||
}
|
||||
variableExpr, found := c.variables[strings.Join([]string{s.Name, e.Sel.Name}, ".")]
|
||||
case *ast.Ident:
|
||||
variableExpr, found := c.variables[e.Name]
|
||||
if !found {
|
||||
return nil, newDecodeErrorf(e, errBadImportedVariableAttribute)
|
||||
return nil, newDecodeErrorf(expr, errBadVariableAttribute)
|
||||
}
|
||||
bl, ok := variableExpr.(*ast.BasicLit)
|
||||
if !ok {
|
||||
return nil, newDecodeErrorf(e, errNonStringAttribute)
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value, err := stringValue(bl)
|
||||
if err != nil {
|
||||
return nil, newDecodeErrorf(e, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return &value, nil
|
||||
case *ast.SelectorExpr:
|
||||
s, ok := e.X.(*ast.Ident)
|
||||
if !ok {
|
||||
return nil, newDecodeErrorf(expr, errExprNotIdent, e.X)
|
||||
}
|
||||
variableExpr, found := c.variables[strings.Join([]string{s.Name, e.Sel.Name}, ".")]
|
||||
if !found {
|
||||
return nil, newDecodeErrorf(expr, errBadImportedVariableAttribute)
|
||||
}
|
||||
bl, ok := variableExpr.(*ast.BasicLit)
|
||||
if !ok {
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value, err := stringValue(bl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &value, nil
|
||||
case *ast.BinaryExpr:
|
||||
var binaryExpr *ast.BinaryExpr
|
||||
binaryExpr = e
|
||||
var okay bool
|
||||
var value string
|
||||
okay = true
|
||||
|
||||
for okay {
|
||||
yV, okay := binaryExpr.Y.(*ast.BasicLit)
|
||||
if !okay {
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
yVal, err := stringValue(yV)
|
||||
if err != nil {
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value = fmt.Sprintf("%s%s", yVal, value)
|
||||
x, okay := binaryExpr.X.(*ast.BinaryExpr)
|
||||
if !okay {
|
||||
// should be basicLit
|
||||
xV, okay := binaryExpr.X.(*ast.BasicLit)
|
||||
if !okay {
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
xVal, err := stringValue(xV)
|
||||
if err != nil {
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value = fmt.Sprintf("%s%s", xVal, value)
|
||||
break
|
||||
}
|
||||
binaryExpr = x
|
||||
}
|
||||
return &value, nil
|
||||
}
|
||||
@ -297,36 +336,7 @@ func (c *metricDecoder) decodeLabels(expr ast.Expr) ([]string, error) {
|
||||
cl = cl2
|
||||
}
|
||||
}
|
||||
labels := make([]string, len(cl.Elts))
|
||||
for i, el := range cl.Elts {
|
||||
v, ok := el.(*ast.Ident)
|
||||
if ok {
|
||||
variableExpr, found := c.variables[v.Name]
|
||||
if !found {
|
||||
return nil, newDecodeErrorf(expr, errBadVariableAttribute)
|
||||
}
|
||||
bl, ok := variableExpr.(*ast.BasicLit)
|
||||
if !ok {
|
||||
return nil, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value, err := stringValue(bl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
labels[i] = value
|
||||
continue
|
||||
}
|
||||
bl, ok := el.(*ast.BasicLit)
|
||||
if !ok {
|
||||
return nil, errors.New(errLabels)
|
||||
}
|
||||
value, err := stringValue(bl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
labels[i] = value
|
||||
}
|
||||
return labels, nil
|
||||
return c.decodeLabelsFromArray(cl.Elts)
|
||||
}
|
||||
|
||||
func (c *metricDecoder) decodeOpts(expr ast.Expr) (metric, error) {
|
||||
@ -353,77 +363,11 @@ func (c *metricDecoder) decodeOpts(expr ast.Expr) (metric, error) {
|
||||
case "Namespace", "Subsystem", "Name", "Help", "DeprecatedVersion":
|
||||
var value string
|
||||
var err error
|
||||
switch v := kv.Value.(type) {
|
||||
case *ast.BasicLit:
|
||||
value, err = stringValue(v)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
case *ast.Ident:
|
||||
variableExpr, found := c.variables[v.Name]
|
||||
if !found {
|
||||
return m, newDecodeErrorf(expr, errBadVariableAttribute)
|
||||
}
|
||||
bl, ok := variableExpr.(*ast.BasicLit)
|
||||
if !ok {
|
||||
return m, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value, err = stringValue(bl)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
case *ast.SelectorExpr:
|
||||
s, ok := v.X.(*ast.Ident)
|
||||
if !ok {
|
||||
return m, newDecodeErrorf(expr, errExprNotIdent, v.X)
|
||||
}
|
||||
variableExpr, found := c.variables[strings.Join([]string{s.Name, v.Sel.Name}, ".")]
|
||||
if !found {
|
||||
return m, newDecodeErrorf(expr, errBadImportedVariableAttribute)
|
||||
}
|
||||
bl, ok := variableExpr.(*ast.BasicLit)
|
||||
if !ok {
|
||||
return m, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value, err = stringValue(bl)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
case *ast.BinaryExpr:
|
||||
var binaryExpr *ast.BinaryExpr
|
||||
binaryExpr = v
|
||||
var okay bool
|
||||
okay = true
|
||||
|
||||
for okay {
|
||||
yV, okay := binaryExpr.Y.(*ast.BasicLit)
|
||||
if !okay {
|
||||
return m, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
yVal, err := stringValue(yV)
|
||||
if err != nil {
|
||||
return m, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value = fmt.Sprintf("%s%s", yVal, value)
|
||||
x, okay := binaryExpr.X.(*ast.BinaryExpr)
|
||||
if !okay {
|
||||
// should be basicLit
|
||||
xV, okay := binaryExpr.X.(*ast.BasicLit)
|
||||
if !okay {
|
||||
return m, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
xVal, err := stringValue(xV)
|
||||
if err != nil {
|
||||
return m, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
}
|
||||
value = fmt.Sprintf("%s%s", xVal, value)
|
||||
break
|
||||
}
|
||||
binaryExpr = x
|
||||
}
|
||||
default:
|
||||
return m, newDecodeErrorf(expr, errNonStringAttribute)
|
||||
s, err := c.decodeString(kv.Value)
|
||||
if err != nil {
|
||||
return m, newDecodeErrorf(expr, err.Error())
|
||||
}
|
||||
value = *s
|
||||
switch key {
|
||||
case "Namespace":
|
||||
m.Namespace = value
|
||||
|
@ -1363,6 +1363,11 @@
|
||||
help: Cumulative proxy rules Endpoint changes
|
||||
type: Counter
|
||||
stabilityLevel: ALPHA
|
||||
- name: sync_proxy_rules_iptables_partial_restore_failures_total
|
||||
subsystem: kubeproxy
|
||||
help: Cumulative proxy iptables partial restore failures
|
||||
type: Counter
|
||||
stabilityLevel: ALPHA
|
||||
- name: sync_proxy_rules_iptables_restore_failures_total
|
||||
subsystem: kubeproxy
|
||||
help: Cumulative proxy iptables restore failures
|
||||
@ -2247,6 +2252,16 @@
|
||||
- protocol
|
||||
- stage
|
||||
- transport
|
||||
- name: dial_start_total
|
||||
subsystem: egress_dialer
|
||||
namespace: apiserver
|
||||
help: Dial starts, labeled by the protocol (http-connect or grpc) and transport
|
||||
(tcp or uds).
|
||||
type: Counter
|
||||
stabilityLevel: ALPHA
|
||||
labels:
|
||||
- protocol
|
||||
- transport
|
||||
- name: request_aborts_total
|
||||
subsystem: apiserver
|
||||
help: Number of requests which apiserver aborted possibly due to a timeout, for
|
||||
|
@ -6,7 +6,7 @@ description: >-
|
||||
---
|
||||
|
||||
|
||||
## Metrics (auto-generated 2022 Nov 01)
|
||||
## Metrics (auto-generated 2022 Nov 02)
|
||||
|
||||
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.
|
||||
@ -344,6 +344,12 @@ components using an HTTP scrape, and fetch the current metrics data in Prometheu
|
||||
<td class="metric_description">Dial failure count, labeled by the protocol (http-connect or grpc), transport (tcp or uds), and stage (connect or proxy). The stage indicates at which stage the dial failed</td>
|
||||
<td class="metric_labels_varying"><div class="metric_label">protocol</div><div class="metric_label">stage</div><div class="metric_label">transport</div></td>
|
||||
<td class="metric_labels_constant">None</td></tr>
|
||||
<tr class="metric"><td class="metric_name">apiserver_egress_dialer_dial_start_total</td>
|
||||
<td class="metric_stability_level" data-stability="alpha">ALPHA</td>
|
||||
<td class="metric_type" data-type="counter">Counter</td>
|
||||
<td class="metric_description">Dial starts, labeled by the protocol (http-connect or grpc) and transport (tcp or uds).</td>
|
||||
<td class="metric_labels_varying"><div class="metric_label">protocol</div><div class="metric_label">transport</div></td>
|
||||
<td class="metric_labels_constant">None</td></tr>
|
||||
<tr class="metric"><td class="metric_name">apiserver_envelope_encryption_dek_cache_fill_percent</td>
|
||||
<td class="metric_stability_level" data-stability="alpha">ALPHA</td>
|
||||
<td class="metric_type" data-type="gauge">Gauge</td>
|
||||
@ -1478,6 +1484,12 @@ components using an HTTP scrape, and fetch the current metrics data in Prometheu
|
||||
<td class="metric_description">Cumulative proxy rules Endpoint changes</td>
|
||||
<td class="metric_labels_varying">None</td>
|
||||
<td class="metric_labels_constant">None</td></tr>
|
||||
<tr class="metric"><td class="metric_name">kubeproxy_sync_proxy_rules_iptables_partial_restore_failures_total</td>
|
||||
<td class="metric_stability_level" data-stability="alpha">ALPHA</td>
|
||||
<td class="metric_type" data-type="counter">Counter</td>
|
||||
<td class="metric_description">Cumulative proxy iptables partial restore failures</td>
|
||||
<td class="metric_labels_varying">None</td>
|
||||
<td class="metric_labels_constant">None</td></tr>
|
||||
<tr class="metric"><td class="metric_name">kubeproxy_sync_proxy_rules_iptables_restore_failures_total</td>
|
||||
<td class="metric_stability_level" data-stability="alpha">ALPHA</td>
|
||||
<td class="metric_type" data-type="counter">Counter</td>
|
||||
|
Loading…
Reference in New Issue
Block a user