WorkloadSpread (#7)
* cloneset left the last two metrics * Delete cloneset.md * .md * mod * all cloneset except go.mod * fix: last two * del:cloneset.unavailable * makefile and dockerfile * 1 * fix:cloneset.go:'implied' * fix:dockerfile makefile * del:config * Delete config * fix:解决panic * doc:cloneset.md * advancedstatefulset * statefulset * rename statefulset.md * del:delete chinese description of statefulset.go * fix:dockerfile * fix:statefulsets can't be active resources * fix:statefulsets can't be active resources * feat: complete doc and code of sidecarset * feat: docs and code of workloadSpread; docs: Slightly revised the past document * test * rm cloneset-metrics.md * feat: the code and docs of DaemonSet
This commit is contained in:
parent
30c07bc442
commit
6e0b781725
|
|
@ -17,4 +17,7 @@
|
|||
|
||||
.idea/
|
||||
main
|
||||
config
|
||||
config
|
||||
|
||||
internal/store/cloneset_test.go
|
||||
internal/store/testutils.go
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
# CloneSet Metrics
|
||||
|
||||
| Metric name| Description | Status |
|
||||
| ---------- | ----------- | ----------- |
|
||||
| kruise_cloneset_created | Unix creation timestamp | STABLE |
|
||||
| kruise_cloneset_status_replicas | The number of replicas per cloneset | STABLE |
|
||||
| kruise_cloneset_status_replicas_available | The number of available replicas per cloneset | STABLE |
|
||||
| kruise_cloneset_status_replicas_updated | The number of updated replicas per cloneset | STABLE |
|
||||
| kruise_cloneset_status_observed_generation | The generation observed by the cloneset controller | STABLE |
|
||||
| kruise_cloneset_status_condition | The current status conditions of a cloneset | STABLE |
|
||||
| kruise_cloneset_spec_replicas | Number of desired pods for a cloneset | STABLE |
|
||||
| kruise_cloneset_spec_strategy_rollingupdate_max_unavailable | Maximum number of unavailable replicas during a rolling update of a cloneset | STABLE |
|
||||
| kruise_cloneset_spec_strategy_rollingupdate_max_surge | Maximum number of replicas that can be scheduled above the desired number of replicas during a rolling update of a cloneset | STABLE |
|
||||
| kruise_cloneset_spec_metadata_generation | Sequence number representing a specific generation of the desired state | STABLE |
|
||||
| kruise_cloneset_labels | Kruise labels converted to Prometheus labels | STABLE |
|
||||
| kruise_cloneset_status_replicas_ready | The number of ready replicas per cloneset | STABLE |
|
||||
| kruise_cloneset_status_replicas_updated_ready | The number of update and ready replicas per cloneset | STABLE |
|
||||
| kruise_cloneset_spec_strategy_partition | Desired number or percent of Pods in old revisions | STABLE |
|
||||
| kruise_cloneset_strategy_type | The type of updateStrategy | STABLE |
|
||||
|
|
@ -15,4 +15,5 @@
|
|||
| kruise_cloneset_spec_strategy_rollingupdate_max_unavailable | Maximum number of unavailable replicas during a rolling update of a cloneset | STABLE |
|
||||
| kruise_cloneset_spec_strategy_rollingupdate_max_surge | Maximum number of replicas that can be scheduled above the desired number of replicas during a rolling update of a cloneset | STABLE |
|
||||
| kruise_cloneset_spec_strategy_partition | Desired number or percent of Pods in old revisions | STABLE |
|
||||
| kruise_cloneset_spec_strategy_type | The type of updateStrategy | STABLE || kruise_cloneset_labels | Kruise labels converted to Prometheus labels | STABLE |
|
||||
| kruise_cloneset_spec_strategy_type | The type of updateStrategy | STABLE |
|
||||
| kruise_cloneset_labels | Kruise labels converted to Prometheus labels | STABLE |
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
# DaemonSet Metrics
|
||||
|
||||
| Metric name| Metric type | Status |
|
||||
| ---------- | ----------- | ----------- |
|
||||
| kruise_daemonset_created | Unix creation timestamp | STABLE |
|
||||
| kruise_daemonset_status_condition | The current status conditions of a daemonset | STABLE |
|
||||
| kruise_daemonset_spec_strategy_rollingupdate_max_surge | Maximum number of replicas that can be scheduled above the desired number of replicas during a rolling update of a daemonset | STABLE |
|
||||
| kruise_daemonset_spec_strategy_partition | Desired number or percent of Pods in old revisions | STABLE |
|
||||
| kruise_daemonset_spec_strategy_type | The type of updateStrategy | STABLE |
|
||||
| kruise_daemonset_status_current_number_scheduled | The number of nodes running at least one daemon pod and are supposed to | STABLE |
|
||||
| kruise_daemonset_status_desired_number_scheduled | The number of nodes that should be running the daemon pod | STABLE |
|
||||
| kruise_daemonset_status_number_available | The number of nodes that should be running the daemon pod and have one or more of the daemon pod running and available | STABLE |
|
||||
| kruise_daemonset_status_number_misscheduled | The number of nodes running a daemon pod but are not supposed to | STABLE |
|
||||
| kruise_daemonset_status_number_ready | The number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready | STABLE |
|
||||
| kruise_daemonset_status_number_unavailable | The number of nodes that should be running the daemon pod and have none of the daemon pod running and available | STABLE |
|
||||
| kruise_daemonset_status_observed_generation | The most recent generation observed by the daemon set controller | STABLE |
|
||||
| kruise_daemonset_status_updated_number_scheduled | The total number of nodes that are running updated daemon pod | STABLE |
|
||||
| kruise_daemonset_metadata_generation | Sequence number representing a specific generation of the desired state | STABLE |
|
||||
| kruise_daemonset_labels | Kruise labels converted to Prometheus labels | STABLE |
|
||||
|
|
@ -8,14 +8,13 @@
|
|||
| kruise_sidecarset_status_replicas_ready | The number of ready replicas per sidecarset | STABLE |
|
||||
| kruise_sidecarset_status_observed_generation | The generation observed by the sidecarset controller | STABLE |
|
||||
| kruise_sidecarset_status_replicas_updated_ready | The number of update and ready replicas per sidecarset | STABLE |
|
||||
|
||||
| kruise_sidecarset_spec_namespcace | The namespace matched pods in | STABLE |
|
||||
| kruise_sidecarset_spec_strategy_rollingupdate_max_unavailable | Maximum number of unavailable replicas during a rolling update of a sidecarset | STABLE |
|
||||
| kruise_sidecarset_spec_strategy_partition | Desired number or percent of Pods in old revisions | STABLE |
|
||||
| kruise_sidecarset_spec_strategy_type | The type of updateStrategy | STABLE |
|
||||
| kruise_sidecarset_spec_metadata_generation | Sequence number representing a specific generation of the desired state | STABLE |
|
||||
| kruise_sidecarset_labels | Kruise labels converted to Prometheus labels | STABLE |
|
||||
| kruise_sidecarset_spec_containers_injectpolicy | | STABLE |
|
||||
| kruise_sidecarset_spec_containers_strategy_type | | STABLE |
|
||||
| kruise_sidecarset_spec_containers_strategy_hotupgradeemptyimage | | STABLE |
|
||||
| kruise_sidecarset_spec_containers_volumepolicy | | STABLE |
|
||||
| kruise_sidecarset_spec_containers_injectpolicy | The rules that injected SidecarContainer into Pod.spec.containers | STABLE |
|
||||
| kruise_sidecarset_spec_containers_strategy_type | The type of containers' upgradeStrategy | STABLE |
|
||||
| kruise_sidecarset_spec_containers_strategy_hotupgradeemptyimage | The consistent of sidecar container | STABLE |
|
||||
| kruise_sidecarset_spec_containers_volumepolicy | The other container's VolumeMounts shared | STABLE |
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
# Workload Spread Metrics
|
||||
|
||||
| Metric name| Description | Status |
|
||||
| ---------- | ----------- | ----------- |
|
||||
| kruise_workloadspread_created | Unix creation timestamp | STABLE |
|
||||
| kruise_workloadspread_status_subset_replicas | The most recently observed number of replicas for subset. | STABLE |
|
||||
| kruise_workloadspread_status_subset_replicas_missing | The number of replicas belong to this subset not be found. | STABLE |
|
||||
| kruise_workloadspread_spec_metadata_generation | Sequence number representing a specific generation of the desired state for the workloadspread. | STABLE |
|
||||
| kruise_workloadspread_spec_subsets_max_replicas | The desired max replicas of this subset. | STABLE |
|
||||
| kruise_workloadspread_spec_strategy_type | The type of updateStrategy | STABLE |
|
||||
| kruise_workloadspread_labels | Kubernetes labels converted to Prometheus labels. | STABLE |
|
||||
2
go.mod
2
go.mod
|
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||
github.com/oklog/run v1.1.0
|
||||
github.com/openkruise/kruise-api v0.9.0-1.18
|
||||
github.com/openkruise/kruise-api v0.10.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/prometheus/common v0.29.0
|
||||
|
|
|
|||
15
go.sum
15
go.sum
|
|
@ -89,7 +89,6 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
|
|||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/evanphx/json-patch v0.0.0-20200808040245-162e5629780b/go.mod h1:NAJj0yf/KaRKURN6nyi7A9IZydMivZEm9oQLWNjfKDc=
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
|
|
@ -208,7 +207,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
|
|||
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
|
|
@ -268,8 +266,8 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
|||
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/openkruise/kruise-api v0.9.0-1.18 h1:yRq5j6ZIMwEk8kA3JMjFYhKizgkYybVJ3JmnL16uiPM=
|
||||
github.com/openkruise/kruise-api v0.9.0-1.18/go.mod h1:9V4wIOAGWOSaP5RJWNDXckkb1rnn7Vee/hPtZHunu8g=
|
||||
github.com/openkruise/kruise-api v0.10.0 h1:06e5QKpIpuN2mjh+UPLkfYoRH/MbUlQs0VTiavB+QV0=
|
||||
github.com/openkruise/kruise-api v0.10.0/go.mod h1:YjDCqMeYwjs/2Be8e/v0/8kqiur87g2g10CBXIBPBgk=
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
|
@ -664,25 +662,25 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.18.2/go.mod h1:SJCWI7OLzhZSvbY7U8zwNl9UA4o1fizoug34OV/2r78=
|
||||
k8s.io/api v0.18.3/go.mod h1:UOaMwERbqJMfeeeHc8XJKawj4P9TgDRnViIqqBeH2QA=
|
||||
k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY=
|
||||
k8s.io/api v0.21.2/go.mod h1:Lv6UGJZ1rlMI1qusN8ruAp9PUBFyBwpEHAdG24vIsiU=
|
||||
k8s.io/api v0.21.3 h1:cblWILbLO8ar+Fj6xdDGr603HRsf8Wu9E9rngJeprZQ=
|
||||
k8s.io/api v0.21.3/go.mod h1:hUgeYHUbBp23Ue4qdX9tR8/ANi/g3ehylAqDn9NWVOg=
|
||||
k8s.io/apimachinery v0.18.2/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
|
||||
k8s.io/apimachinery v0.18.3/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
|
||||
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
|
||||
k8s.io/apimachinery v0.21.2/go.mod h1:CdTY8fU/BlvAbJ2z/8kBwimGki5Zp8/fbVuLY8gJumM=
|
||||
k8s.io/apimachinery v0.21.3 h1:3Ju4nvjCngxxMYby0BimUk+pQHPOQp3eCGChk5kfVII=
|
||||
k8s.io/apimachinery v0.21.3/go.mod h1:H/IM+5vH9kZRNJ4l3x/fXP/5bOPJaVP/guptnZPeCFI=
|
||||
k8s.io/autoscaler/vertical-pod-autoscaler v0.9.2 h1:fMFkbjo6ElaL3POE3ctxLuX3aR+bEzpo2q1R5Aq2JhE=
|
||||
k8s.io/autoscaler/vertical-pod-autoscaler v0.9.2/go.mod h1:PwWTGRRCxefhAezrDbG/tRYSAW7etHjjMPAr8fXKVAA=
|
||||
k8s.io/client-go v0.18.2/go.mod h1:Xcm5wVGXX9HAA2JJ2sSBUn3tCJ+4SVlCbl2MNNv+CIU=
|
||||
k8s.io/client-go v0.18.3/go.mod h1:4a/dpQEvzAhT1BbuWW09qvIaGw6Gbu1gZYiQZIi1DMw=
|
||||
k8s.io/client-go v0.18.8/go.mod h1:HqFqMllQ5NnQJNwjro9k5zMyfhZlOwpuTLVrxjkYSxU=
|
||||
k8s.io/client-go v0.21.2/go.mod h1:HdJ9iknWpbl3vMGtib6T2PyI/VYxiZfq936WNVHBRrA=
|
||||
k8s.io/client-go v0.21.3 h1:J9nxZTOmvkInRDCzcSNQmPJbDYN/PjlxXT9Mos3HcLg=
|
||||
k8s.io/client-go v0.21.3/go.mod h1:+VPhCgTsaFmGILxR/7E1N0S+ryO010QBeNCv5JwRGYU=
|
||||
k8s.io/code-generator v0.18.2/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
|
||||
k8s.io/code-generator v0.18.3/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
|
||||
k8s.io/code-generator v0.18.8/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
|
||||
k8s.io/component-base v0.18.3/go.mod h1:bp5GzGR0aGkYEfTj+eTY0AN/vXTgkJdQXjNTTVUaa3k=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
|
|
@ -695,6 +693,7 @@ k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
|||
k8s.io/klog/v2 v2.8.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
|
||||
k8s.io/klog/v2 v2.9.0 h1:D7HV+n1V57XeZ0m6tdRkfknthUaM06VFbWldOFh8kzM=
|
||||
k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
|
||||
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
|
||||
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
|
||||
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7/go.mod h1:wXW5VT87nVfh/iLV8FpR2uDvrFyomxbtb1KivDbvPTE=
|
||||
k8s.io/kube-state-metrics/v2 v2.1.1-0.20210723141916-58869f0c5e2e h1:RiARgy0quCcibG6tYJfax+KL+MIUbMQV/KIG1O8nmzg=
|
||||
|
|
|
|||
|
|
@ -183,9 +183,11 @@ func (b *Builder) Build() []metricsstore.MetricsWriter {
|
|||
}
|
||||
|
||||
var availableStores = map[string]func(f *Builder) []*metricsstore.MetricsStore{
|
||||
"clonesets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildCloneSetStores() },
|
||||
"statefulsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildStatefulSetStores() },
|
||||
"sidecarsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildSidecarSetStores() },
|
||||
"clonesets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildCloneSetStores() },
|
||||
"statefulsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildStatefulSetStores() },
|
||||
"sidecarsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildSidecarSetStores() },
|
||||
"workloadspreads": func(b *Builder) []*metricsstore.MetricsStore { return b.buildWorkloadSpreadStores() },
|
||||
"daemonsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildDaemonSetStores() },
|
||||
}
|
||||
|
||||
func resourceExists(name string) bool {
|
||||
|
|
@ -223,6 +225,14 @@ func (b *Builder) buildSidecarSetStores() []*metricsstore.MetricsStore {
|
|||
return b.buildKruiseStoresFunc(sidecarSetMetricFamilies(b.allowLabelsList["sidecarsets"]), &appsv1alpha1.SidecarSet{}, createSidecarSetListWatch)
|
||||
}
|
||||
|
||||
func (b *Builder) buildWorkloadSpreadStores() []*metricsstore.MetricsStore {
|
||||
return b.buildKruiseStoresFunc(workloadSpreadMetricFamilies(b.allowLabelsList["workloadspreads"]), &appsv1alpha1.WorkloadSpread{}, createWorkloadSpreadListWatch)
|
||||
}
|
||||
|
||||
func (b *Builder) buildDaemonSetStores() []*metricsstore.MetricsStore {
|
||||
return b.buildKruiseStoresFunc(daemonSetMetricFamilies(b.allowLabelsList["daemonsets"]), &appsv1alpha1.DaemonSet{}, createDaemonSetListWatch)
|
||||
}
|
||||
|
||||
func (b *Builder) buildKruiseStores(
|
||||
metricFamilies []generator.FamilyGenerator,
|
||||
expectedType interface{},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,322 @@
|
|||
/*
|
||||
Copyright 2021 The Kruise Authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/openkruise/kruise-api/apps/v1alpha1"
|
||||
|
||||
kruiseclientset "github.com/openkruise/kruise-api/client/clientset/versioned"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
||||
"k8s.io/kube-state-metrics/v2/pkg/metric"
|
||||
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
|
||||
)
|
||||
|
||||
var (
|
||||
descDaemonSetLabelsName = "kruise_daemonset_labels"
|
||||
descDaemonSetLabelsHelp = "Kruise labels converted to Prometheus labels."
|
||||
descDaemonSetLabelsDefaultLabels = []string{"namespace", "daemonset"}
|
||||
)
|
||||
|
||||
func daemonSetMetricFamilies(allowLabelsList []string) []generator.FamilyGenerator {
|
||||
return []generator.FamilyGenerator{
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_created",
|
||||
"Unix creation timestamp",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
ms := []*metric.Metric{}
|
||||
|
||||
if !ds.CreationTimestamp.IsZero() {
|
||||
ms = append(ms, &metric.Metric{
|
||||
Value: float64(ds.CreationTimestamp.Unix()),
|
||||
})
|
||||
}
|
||||
|
||||
return &metric.Family{
|
||||
Metrics: ms,
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_condition",
|
||||
"The current status conditions of a daemonset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
ms := make([]*metric.Metric, len(ds.Status.Conditions)*len(conditionStatuses))
|
||||
|
||||
for i, ds := range ds.Status.Conditions {
|
||||
conditionMetrics := addConditionMetrics(ds.Status)
|
||||
|
||||
for j, m := range conditionMetrics {
|
||||
metric := m
|
||||
|
||||
metric.LabelKeys = []string{"condition", "status"}
|
||||
metric.LabelValues = append([]string{string(ds.Type)}, metric.LabelValues...)
|
||||
ms[i*len(conditionStatuses)+j] = metric
|
||||
}
|
||||
}
|
||||
|
||||
return &metric.Family{
|
||||
Metrics: ms,
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_spec_strategy_rollingupdate_max_surge",
|
||||
"Maximum number of replicas that can be scheduled above the desired number of replicas during a rolling update of a daemonset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
maxSurge, err := intstr.GetValueFromIntOrPercent(ds.Spec.UpdateStrategy.RollingUpdate.MaxSurge, int(ds.Status.DesiredNumberScheduled), true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(maxSurge),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_spec_strategy_partition",
|
||||
"Desired number or percent of Pods in old revisions.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
if ds.Spec.UpdateStrategy.RollingUpdate.Partition == nil {
|
||||
return &metric.Family{}
|
||||
}
|
||||
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
LabelKeys: []string{"partition"},
|
||||
LabelValues: []string{strconv.Itoa(int(*ds.Spec.UpdateStrategy.RollingUpdate.Partition))},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_spec_strategy_type",
|
||||
"The type of updateStrategy.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
LabelKeys: []string{"strategy_type"},
|
||||
LabelValues: []string{string(ds.Spec.UpdateStrategy.Type)},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_current_number_scheduled",
|
||||
"The number of nodes running at least one daemon pod and are supposed to.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.CurrentNumberScheduled),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_desired_number_scheduled",
|
||||
"The number of nodes that should be running the daemon pod.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.DesiredNumberScheduled),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_number_available",
|
||||
"The number of nodes that should be running the daemon pod and have one or more of the daemon pod running and available",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.NumberAvailable),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_number_misscheduled",
|
||||
"The number of nodes running a daemon pod but are not supposed to.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.NumberMisscheduled),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_number_ready",
|
||||
"The number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.NumberReady),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_number_unavailable",
|
||||
"The number of nodes that should be running the daemon pod and have none of the daemon pod running and available",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.NumberUnavailable),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_observed_generation",
|
||||
"The most recent generation observed by the daemon set controller.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.ObservedGeneration),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_status_updated_number_scheduled",
|
||||
"The total number of nodes that are running updated daemon pod",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.Status.UpdatedNumberScheduled),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_daemonset_metadata_generation",
|
||||
"Sequence number representing a specific generation of the desired state.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ds.ObjectMeta.Generation),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
descDaemonSetLabelsName,
|
||||
descDaemonSetLabelsHelp,
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapDaemonSetFunc(func(ds *v1alpha1.DaemonSet) *metric.Family {
|
||||
labelKeys, labelValues := createLabelKeysValues(ds.Labels, allowLabelsList)
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
LabelKeys: labelKeys,
|
||||
LabelValues: labelValues,
|
||||
Value: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func wrapDaemonSetFunc(f func(*v1alpha1.DaemonSet) *metric.Family) func(interface{}) *metric.Family {
|
||||
return func(obj interface{}) *metric.Family {
|
||||
daemonset := obj.(*v1alpha1.DaemonSet)
|
||||
|
||||
metricFamily := f(daemonset)
|
||||
|
||||
for _, m := range metricFamily.Metrics {
|
||||
m.LabelKeys = append(descDaemonSetLabelsDefaultLabels, m.LabelKeys...)
|
||||
m.LabelValues = append([]string{daemonset.Namespace, daemonset.Name}, m.LabelValues...)
|
||||
}
|
||||
|
||||
return metricFamily
|
||||
}
|
||||
}
|
||||
|
||||
func createDaemonSetListWatch(kruiseClient kruiseclientset.Interface, ns string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{
|
||||
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
|
||||
return kruiseClient.AppsV1alpha1().DaemonSets(ns).List(context.TODO(), opts)
|
||||
},
|
||||
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
return kruiseClient.AppsV1alpha1().DaemonSets(ns).Watch(context.TODO(), opts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -238,7 +238,7 @@ func sidecarSetMetricFamilies(allowLabelsList []string) []generator.FamilyGenera
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_sidecarset_spec_containers_injectpolicy",
|
||||
"",
|
||||
"The rules that injected SidecarContainer into Pod.spec.containers.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapSidecarSetFunc(func(sc *v1alpha1.SidecarSet) *metric.Family {
|
||||
|
|
@ -256,7 +256,7 @@ func sidecarSetMetricFamilies(allowLabelsList []string) []generator.FamilyGenera
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_sidecarset_spec_containers_strategy_type",
|
||||
"",
|
||||
"The type of containers' upgradeStrategy.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapSidecarSetFunc(func(sc *v1alpha1.SidecarSet) *metric.Family {
|
||||
|
|
@ -274,7 +274,7 @@ func sidecarSetMetricFamilies(allowLabelsList []string) []generator.FamilyGenera
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_sidecarset_spec_containers_strategy_hotupgradeemptyimage",
|
||||
"",
|
||||
"The consistent of sidecar container.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapSidecarSetFunc(func(sc *v1alpha1.SidecarSet) *metric.Family {
|
||||
|
|
@ -291,8 +291,8 @@ func sidecarSetMetricFamilies(allowLabelsList []string) []generator.FamilyGenera
|
|||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_sidecarset_containers_volumepolicy",
|
||||
"",
|
||||
"kruise_sidecarset_spec_containers_volumepolicy",
|
||||
"The other container's VolumeMounts shared.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapSidecarSetFunc(func(sc *v1alpha1.SidecarSet) *metric.Family {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func statefulSetMetricFamilies(allowLabelsList []string) []generator.FamilyGener
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_statefulset_status_replicas",
|
||||
"The number of replicas per statefulset",
|
||||
"The number of replicas per statefulset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapStatefulSetFunc(func(s *v1beta1.StatefulSet) *metric.Family {
|
||||
|
|
@ -73,7 +73,7 @@ func statefulSetMetricFamilies(allowLabelsList []string) []generator.FamilyGener
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_statefulset_status_replicas_available",
|
||||
"The number of available replicas per statefulset",
|
||||
"The number of available replicas per statefulset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapStatefulSetFunc(func(s *v1beta1.StatefulSet) *metric.Family {
|
||||
|
|
@ -88,7 +88,7 @@ func statefulSetMetricFamilies(allowLabelsList []string) []generator.FamilyGener
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_statefulset_status_replicas_current",
|
||||
"The number of current replicas per statefulset",
|
||||
"The number of current replicas per statefulset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapStatefulSetFunc(func(s *v1beta1.StatefulSet) *metric.Family {
|
||||
|
|
@ -103,7 +103,7 @@ func statefulSetMetricFamilies(allowLabelsList []string) []generator.FamilyGener
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_statefulset_status_replicas_ready",
|
||||
"The number of ready replicas per statefulset",
|
||||
"The number of ready replicas per statefulset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapStatefulSetFunc(func(s *v1beta1.StatefulSet) *metric.Family {
|
||||
|
|
@ -118,7 +118,7 @@ func statefulSetMetricFamilies(allowLabelsList []string) []generator.FamilyGener
|
|||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_statefulset_status_replicas_updated",
|
||||
"The number of updated replicas per statefulset",
|
||||
"The number of updated replicas per statefulset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapStatefulSetFunc(func(s *v1beta1.StatefulSet) *metric.Family {
|
||||
|
|
@ -326,6 +326,7 @@ func statefulSetMetricFamilies(allowLabelsList []string) []generator.FamilyGener
|
|||
),
|
||||
}
|
||||
}
|
||||
|
||||
func wrapStatefulSetFunc(f func(*v1beta1.StatefulSet) *metric.Family) func(interface{}) *metric.Family {
|
||||
return func(obj interface{}) *metric.Family {
|
||||
statefulset := obj.(*v1beta1.StatefulSet)
|
||||
|
|
|
|||
|
|
@ -20,11 +20,9 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
|
||||
"k8s.io/kube-state-metrics/v2/pkg/metric"
|
||||
"k8s.io/kube-state-metrics/v2/pkg/options"
|
||||
|
|
@ -36,20 +34,6 @@ var (
|
|||
conditionStatuses = []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionUnknown}
|
||||
)
|
||||
|
||||
func resourceVersionMetric(rv string) []*metric.Metric {
|
||||
v, err := strconv.ParseFloat(rv, 64)
|
||||
if err != nil {
|
||||
return []*metric.Metric{}
|
||||
}
|
||||
|
||||
return []*metric.Metric{
|
||||
{
|
||||
Value: v,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func boolFloat64(b bool) float64 {
|
||||
if b {
|
||||
return 1
|
||||
|
|
@ -143,35 +127,6 @@ func labelConflictSuffix(label string, count int) string {
|
|||
return fmt.Sprintf("%s_conflict%d", label, count)
|
||||
}
|
||||
|
||||
func isHugePageResourceName(name v1.ResourceName) bool {
|
||||
return strings.HasPrefix(string(name), v1.ResourceHugePagesPrefix)
|
||||
}
|
||||
|
||||
func isAttachableVolumeResourceName(name v1.ResourceName) bool {
|
||||
return strings.HasPrefix(string(name), v1.ResourceAttachableVolumesPrefix)
|
||||
}
|
||||
|
||||
func isExtendedResourceName(name v1.ResourceName) bool {
|
||||
if isNativeResource(name) || strings.HasPrefix(string(name), v1.DefaultResourceRequestsPrefix) {
|
||||
return false
|
||||
}
|
||||
// Ensure it satisfies the rules in IsQualifiedName() after converted into quota resource name
|
||||
nameForQuota := fmt.Sprintf("%s%s", v1.DefaultResourceRequestsPrefix, string(name))
|
||||
if errs := validation.IsQualifiedName(nameForQuota); len(errs) != 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isNativeResource(name v1.ResourceName) bool {
|
||||
return !strings.Contains(string(name), "/") ||
|
||||
isPrefixedNativeResource(name)
|
||||
}
|
||||
|
||||
func isPrefixedNativeResource(name v1.ResourceName) bool {
|
||||
return strings.Contains(string(name), v1.ResourceDefaultNamespacePrefix)
|
||||
}
|
||||
|
||||
// createLabelKeysValues takes in passed kubernetes labels and allowed list in kubernetes label format
|
||||
// it returns only those allowed labels that exist in the list converting them to Prometheus labels.
|
||||
func createLabelKeysValues(allKubeLabels map[string]string, allowList []string) ([]string, []string) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
Copyright 2021 The Kruise Authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/openkruise/kruise-api/apps/v1alpha1"
|
||||
|
||||
kruiseclientset "github.com/openkruise/kruise-api/client/clientset/versioned"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
||||
"k8s.io/kube-state-metrics/v2/pkg/metric"
|
||||
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
|
||||
)
|
||||
|
||||
var (
|
||||
descWorkloadSpreadLabelsName = "kruise_workloadspread_labels"
|
||||
descWorkloadSpreadLabelsHelp = "Kruise labels converted to Prometheus labels."
|
||||
descWorkloadSpreadLabelsDefaultLabels = []string{"namespace", "workloadspread"}
|
||||
)
|
||||
|
||||
func workloadSpreadMetricFamilies(allowLabelsList []string) []generator.FamilyGenerator {
|
||||
return []generator.FamilyGenerator{
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_workloadspread_created",
|
||||
"Unix creation timestamp",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapWorkloadSpreadFunc(func(ws *v1alpha1.WorkloadSpread) *metric.Family {
|
||||
ms := []*metric.Metric{}
|
||||
|
||||
if !ws.CreationTimestamp.IsZero() {
|
||||
ms = append(ms, &metric.Metric{
|
||||
Value: float64(ws.CreationTimestamp.Unix()),
|
||||
})
|
||||
}
|
||||
|
||||
return &metric.Family{
|
||||
Metrics: ms,
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_workloadspread_status_subset_replicas",
|
||||
"The most recently observed number of replicas for subset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapWorkloadSpreadFunc(func(ws *v1alpha1.WorkloadSpread) *metric.Family {
|
||||
ms := []*metric.Metric{}
|
||||
for _, subset := range ws.Status.SubsetStatuses {
|
||||
ms = append(ms, &metric.Metric{
|
||||
LabelKeys: []string{"replicas"},
|
||||
LabelValues: []string{string(subset.Replicas)},
|
||||
})
|
||||
}
|
||||
return &metric.Family{
|
||||
Metrics: ms,
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_workloadspread_status_subset_replicas_missing",
|
||||
"The number of replicas belong to this subset not be found.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapWorkloadSpreadFunc(func(ws *v1alpha1.WorkloadSpread) *metric.Family {
|
||||
ms := []*metric.Metric{}
|
||||
for _, subset := range ws.Status.SubsetStatuses {
|
||||
ms = append(ms, &metric.Metric{
|
||||
LabelKeys: []string{"missingreplicas"},
|
||||
LabelValues: []string{string(subset.MissingReplicas)},
|
||||
})
|
||||
}
|
||||
return &metric.Family{
|
||||
Metrics: ms,
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_workloadspread_metadata_generation",
|
||||
"Sequence number representing a specific generation of the desired state for the workloadspread.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapWorkloadSpreadFunc(func(ws *v1alpha1.WorkloadSpread) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
Value: float64(ws.ObjectMeta.Generation),
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_workloadspread_spec_subsets_max_replicas",
|
||||
"The desired max replicas of this subset.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapWorkloadSpreadFunc(func(ws *v1alpha1.WorkloadSpread) *metric.Family {
|
||||
ms := []*metric.Metric{}
|
||||
for _, subset := range ws.Spec.Subsets {
|
||||
ms = append(ms, &metric.Metric{
|
||||
LabelKeys: []string{"maxreplicas"},
|
||||
LabelValues: []string{subset.MaxReplicas.StrVal},
|
||||
})
|
||||
}
|
||||
return &metric.Family{
|
||||
Metrics: ms,
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
descWorkloadSpreadLabelsName,
|
||||
descWorkloadSpreadLabelsHelp,
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapWorkloadSpreadFunc(func(ws *v1alpha1.WorkloadSpread) *metric.Family {
|
||||
labelKeys, labelValues := createLabelKeysValues(ws.Labels, allowLabelsList)
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
LabelKeys: labelKeys,
|
||||
LabelValues: labelValues,
|
||||
Value: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGenerator(
|
||||
"kruise_workloadspread_spec_strategy_type",
|
||||
"The type of updateStrategy.",
|
||||
metric.Gauge,
|
||||
"",
|
||||
wrapWorkloadSpreadFunc(func(ws *v1alpha1.WorkloadSpread) *metric.Family {
|
||||
return &metric.Family{
|
||||
Metrics: []*metric.Metric{
|
||||
{
|
||||
LabelKeys: []string{"strategy_type"},
|
||||
LabelValues: []string{string(ws.Spec.ScheduleStrategy.Type)},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func wrapWorkloadSpreadFunc(f func(*v1alpha1.WorkloadSpread) *metric.Family) func(interface{}) *metric.Family {
|
||||
return func(obj interface{}) *metric.Family {
|
||||
workloadspread := obj.(*v1alpha1.WorkloadSpread)
|
||||
|
||||
metricFamily := f(workloadspread)
|
||||
|
||||
for _, m := range metricFamily.Metrics {
|
||||
m.LabelKeys = append(descWorkloadSpreadLabelsDefaultLabels, m.LabelKeys...)
|
||||
m.LabelValues = append([]string{workloadspread.Namespace, workloadspread.Name}, m.LabelValues...)
|
||||
}
|
||||
|
||||
return metricFamily
|
||||
}
|
||||
}
|
||||
|
||||
func createWorkloadSpreadListWatch(kruiseClient kruiseclientset.Interface, ns string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{
|
||||
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
|
||||
return kruiseClient.AppsV1alpha1().WorkloadSpreads(ns).List(context.TODO(), opts)
|
||||
},
|
||||
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
return kruiseClient.AppsV1alpha1().WorkloadSpreads(ns).Watch(context.TODO(), opts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -18,8 +18,10 @@ import "k8s.io/kube-state-metrics/v2/pkg/options"
|
|||
var (
|
||||
// DefaultResources represents the default set of resources in kube-state-metrics.
|
||||
DefaultResources = options.ResourceSet{
|
||||
"clonesets": struct{}{},
|
||||
"statefulsets": struct{}{},
|
||||
"sidecarsets": struct{}{},
|
||||
"clonesets": struct{}{},
|
||||
"statefulsets": struct{}{},
|
||||
"sidecarsets": struct{}{},
|
||||
"workloadspreads": struct{}{},
|
||||
"daemonsets": struct{}{},
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue