Merge pull request #118986 from logicalhan/beta-metric

promote sli metrics to beta
This commit is contained in:
Kubernetes Prow Robot 2023-06-29 14:51:45 -07:00 committed by GitHub
commit a736049349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 74 additions and 12 deletions

View File

@ -37,7 +37,7 @@ var (
Namespace: "kubernetes", Namespace: "kubernetes",
Name: "healthcheck", Name: "healthcheck",
Help: "This metric records the result of a single healthcheck.", Help: "This metric records the result of a single healthcheck.",
StabilityLevel: k8smetrics.ALPHA, StabilityLevel: k8smetrics.BETA,
}, },
[]string{"name", "type"}, []string{"name", "type"},
) )
@ -48,7 +48,7 @@ var (
Namespace: "kubernetes", Namespace: "kubernetes",
Name: "healthchecks_total", Name: "healthchecks_total",
Help: "This metric records the results of all healthcheck.", Help: "This metric records the results of all healthcheck.",
StabilityLevel: k8smetrics.ALPHA, StabilityLevel: k8smetrics.BETA,
}, },
[]string{"name", "type", "status"}, []string{"name", "type", "status"},
) )

View File

@ -37,10 +37,10 @@ func TestObserveHealthcheck(t *testing.T) {
initialState := Error initialState := Error
healthcheckName := "healthcheck-a" healthcheckName := "healthcheck-a"
initialOutput := ` initialOutput := `
# HELP kubernetes_healthcheck [ALPHA] This metric records the result of a single healthcheck. # HELP kubernetes_healthcheck [BETA] This metric records the result of a single healthcheck.
# TYPE kubernetes_healthcheck gauge # TYPE kubernetes_healthcheck gauge
kubernetes_healthcheck{name="healthcheck-a",type="healthz"} 0 kubernetes_healthcheck{name="healthcheck-a",type="healthz"} 0
# HELP kubernetes_healthchecks_total [ALPHA] This metric records the results of all healthcheck. # HELP kubernetes_healthchecks_total [BETA] This metric records the results of all healthcheck.
# TYPE kubernetes_healthchecks_total counter # TYPE kubernetes_healthchecks_total counter
kubernetes_healthchecks_total{name="healthcheck-a",status="error",type="healthz"} 1 kubernetes_healthchecks_total{name="healthcheck-a",status="error",type="healthz"} 1
` `
@ -57,10 +57,10 @@ func TestObserveHealthcheck(t *testing.T) {
hcType: "healthz", hcType: "healthz",
hcStatus: Success, hcStatus: Success,
want: ` want: `
# HELP kubernetes_healthcheck [ALPHA] This metric records the result of a single healthcheck. # HELP kubernetes_healthcheck [BETA] This metric records the result of a single healthcheck.
# TYPE kubernetes_healthcheck gauge # TYPE kubernetes_healthcheck gauge
kubernetes_healthcheck{name="healthcheck-a",type="healthz"} 1 kubernetes_healthcheck{name="healthcheck-a",type="healthz"} 1
# HELP kubernetes_healthchecks_total [ALPHA] This metric records the results of all healthcheck. # HELP kubernetes_healthchecks_total [BETA] This metric records the results of all healthcheck.
# TYPE kubernetes_healthchecks_total counter # TYPE kubernetes_healthchecks_total counter
kubernetes_healthchecks_total{name="healthcheck-a",status="error",type="healthz"} 1 kubernetes_healthchecks_total{name="healthcheck-a",status="error",type="healthz"} 1
kubernetes_healthchecks_total{name="healthcheck-a",status="success",type="healthz"} 1 kubernetes_healthchecks_total{name="healthcheck-a",status="success",type="healthz"} 1

View File

@ -25,7 +25,7 @@ import (
const ( const (
errNotDirectCall = "Opts for STABLE metric was not directly passed to new metric function" errNotDirectCall = "Opts for STABLE metric was not directly passed to new metric function"
errPositionalArguments = "Positional arguments are not supported" errPositionalArguments = "Positional arguments are not supported"
errStabilityLevel = "StabilityLevel should be passed STABLE, ALPHA or removed" errStabilityLevel = "StabilityLevel should be passed STABLE, BETA, ALPHA or removed"
errInvalidNewMetricCall = "Invalid new metric call, please ensure code compiles" errInvalidNewMetricCall = "Invalid new metric call, please ensure code compiles"
errNonStringAttribute = "Non string attribute is not supported" errNonStringAttribute = "Non string attribute is not supported"
errBadVariableAttribute = "Metric attribute was not correctly set. Please use only global consts in same file" errBadVariableAttribute = "Metric attribute was not correctly set. Please use only global consts in same file"

View File

@ -55,7 +55,7 @@ func main() {
fmt.Fprintf(os.Stderr, "USAGE: %s <DIR or FILE or '-'> [...]\n", os.Args[0]) fmt.Fprintf(os.Stderr, "USAGE: %s <DIR or FILE or '-'> [...]\n", os.Args[0])
os.Exit(64) os.Exit(64)
} }
stableMetricNames := map[string]struct{}{}
stableMetrics := []metric{} stableMetrics := []metric{}
errors := []error{} errors := []error{}
@ -66,7 +66,12 @@ func main() {
continue continue
} }
ms, es := searchPathForStableMetrics(arg) ms, es := searchPathForStableMetrics(arg)
stableMetrics = append(stableMetrics, ms...) for _, m := range ms {
if _, ok := stableMetricNames[m.Name]; !ok {
stableMetrics = append(stableMetrics, m)
}
stableMetricNames[m.Name] = struct{}{}
}
errors = append(errors, es...) errors = append(errors, es...)
} }
if addStdin { if addStdin {

View File

@ -601,7 +601,7 @@ var _ = metrics.NewCounter(
`}, `},
{ {
testName: "Fail on metric with stability set to function return", testName: "Fail on metric with stability set to function return",
err: fmt.Errorf("testdata/metric.go:9:20: StabilityLevel should be passed STABLE, ALPHA or removed"), err: fmt.Errorf("testdata/metric.go:9:20: %s", errStabilityLevel),
src: ` src: `
package test package test
import "k8s.io/component-base/metrics" import "k8s.io/component-base/metrics"
@ -616,7 +616,7 @@ var _ = metrics.NewCounter(
`}, `},
{ {
testName: "error for passing stability as string", testName: "error for passing stability as string",
err: fmt.Errorf("testdata/metric.go:6:20: StabilityLevel should be passed STABLE, ALPHA or removed"), err: fmt.Errorf("testdata/metric.go:6:20: %s", errStabilityLevel),
src: ` src: `
package test package test
import "k8s.io/component-base/metrics" import "k8s.io/component-base/metrics"
@ -628,7 +628,7 @@ var _ = metrics.NewCounter(
`}, `},
{ {
testName: "error for passing stability as variable", testName: "error for passing stability as variable",
err: fmt.Errorf("testdata/metric.go:7:20: StabilityLevel should be passed STABLE, ALPHA or removed"), err: fmt.Errorf("testdata/metric.go:7:20: %s", errStabilityLevel),
src: ` src: `
package test package test
import "k8s.io/component-base/metrics" import "k8s.io/component-base/metrics"

View File

@ -132,6 +132,27 @@ var (
}, },
testLabels, testLabels,
) )
// healthcheck is a Prometheus Gauge metrics used for recording the results of a k8s healthcheck.
healthcheck = metrics.NewGaugeVec(
&metrics.GaugeOpts{
Namespace: "kubernetes",
Name: "healthcheck",
Help: "This metric records the result of a single healthcheck.",
StabilityLevel: metrics.BETA,
},
[]string{"name", "type"},
)
// healthchecksTotal is a Prometheus Counter metrics used for counting the results of a k8s healthcheck.
healthchecksTotal = metrics.NewCounterVec(
&metrics.CounterOpts{
Namespace: "kubernetes",
Name: "healthchecks_total",
Help: "This metric records the results of all healthcheck.",
StabilityLevel: metrics.BETA,
},
[]string{"name", "type", "status"},
)
// PodWorkerDuration is a Histogram that tracks the duration (in seconds) in takes to sync a single pod. // PodWorkerDuration is a Histogram that tracks the duration (in seconds) in takes to sync a single pod.
// Broken down by the operation type. // Broken down by the operation type.
SummaryMaxAge = metrics.NewSummary( SummaryMaxAge = metrics.NewSummary(
@ -567,6 +588,8 @@ func Register(collectors ...metrics.StableCollector) {
legacyregistry.MustRegister(NodeName) legacyregistry.MustRegister(NodeName)
legacyregistry.MustRegister(PodWorkerDuration) legacyregistry.MustRegister(PodWorkerDuration)
legacyregistry.MustRegister(PodStartDuration) legacyregistry.MustRegister(PodStartDuration)
legacyregistry.MustRegister(healthcheck)
legacyregistry.MustRegister(healthchecksTotal)
legacyregistry.MustRegister(CgroupManagerDuration) legacyregistry.MustRegister(CgroupManagerDuration)
legacyregistry.MustRegister(PodWorkerStartDuration) legacyregistry.MustRegister(PodWorkerStartDuration)
legacyregistry.MustRegister(ContainersPerPodCount) legacyregistry.MustRegister(ContainersPerPodCount)

View File

@ -409,3 +409,20 @@
stabilityLevel: STABLE stabilityLevel: STABLE
labels: labels:
- resource - resource
- name: healthcheck
namespace: kubernetes
help: This metric records the result of a single healthcheck.
type: Gauge
stabilityLevel: BETA
labels:
- name
- type
- name: healthchecks_total
namespace: kubernetes
help: This metric records the results of all healthcheck.
type: Counter
stabilityLevel: BETA
labels:
- name
- status
- type

View File

@ -192,6 +192,23 @@
labels: labels:
- namespace - namespace
- persistentvolumeclaim - persistentvolumeclaim
- name: healthcheck
namespace: kubernetes
help: This metric records the result of a single healthcheck.
type: Gauge
stabilityLevel: BETA
labels:
- name
- type
- name: healthchecks_total
namespace: kubernetes
help: This metric records the results of all healthcheck.
type: Counter
stabilityLevel: BETA
labels:
- name
- status
- type
- name: priority_level_seat_utilization - name: priority_level_seat_utilization
subsystem: subsystem subsystem: subsystem
namespace: namespace namespace: namespace