Skip to content

Commit

Permalink
Merge branch 'main' into pod_ready_time
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanrolds committed Dec 22, 2022
2 parents f36b8e6 + f1288f9 commit c3c0862
Show file tree
Hide file tree
Showing 92 changed files with 2,682 additions and 978 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ assignees: ''

<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks!
If the matter is security related, please disclose it privately see https://github.com/kubernetes/kube-state-metrics/blob/master/SECURITY.md
If the matter is security related, please disclose it privately see https://github.com/kubernetes/kube-state-metrics/blob/main/SECURITY.md
-->

**What happened**:
Expand Down
40 changes: 20 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: continuous-integration
on:
push:
branches:
- master
- main
- release*
tags:
- v1.*
- v2.*
pull_request:
branches:
- master
- main
- release*

permissions:
Expand All @@ -21,21 +21,21 @@ env:
E2E_SETUP_KUBECTL: yes
SUDO: sudo
GO_VERSION: "^1.19"
GOLANGCI_LINT_VERSION: "v1.48.0"
GOLANGCI_LINT_VERSION: "v1.50.1"

jobs:
ci-go-lint:
name: ci-go-lint
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand All @@ -52,13 +52,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand All @@ -74,13 +74,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand All @@ -96,13 +96,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand All @@ -118,13 +118,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand All @@ -140,7 +140,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup promtool
run: |
Expand All @@ -155,13 +155,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand All @@ -177,13 +177,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand All @@ -199,13 +199,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup environment
run: |
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: govulncheck

on:
schedule:
# Run every Monday
- cron: '0 0 * * 1'

env:
GO_VERSION: "^1.19"

jobs:
ci-security-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout code
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Install govulncheck binary
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
- name: Run security checks
run: |
govulncheck -v ./...
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
- gocyclo
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
Expand All @@ -28,3 +29,10 @@ issues:
- path: _test\.go
linters:
- promlinter
# TODO(mrueg) Improve error handling
- text: "G104:"
linters:
- gosec
- text: "package-comments:"
linters:
- revive
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
## v2.7.0 / 2022-11-25

Note: Experimental VerticalPodAutoscaler metrics are considered deprecated in this release and will be removed in v2.9.0.
Please use CustomResourceStateMetrics to gather metrics from VPA resources. See: #1718

Note: Experimental CustomResourceState changed their naming convention for better usability.
The name of the CRD used to be interpolated into the name of the metric which made it impossible to aggregate a CRD across different versions.
This was changed to have the GVK information represented as labels:
kube_myteam_io_v1_Foo_uptime -> kube_crd_uptime{group="myteam.io", kind="Foo", version="v1"}
See: #1847

* [CHANGE] Deprecate VerticalPodAutoscaler metrics #1835 @rexagod
* [CHANGE] Recommend kube-scheduler metrics for container resource limits and requests #1849 @rexagod
* [FEATURE] Add experimental kube_pod_container_status_last_terminated_exitcode metric #1752 @ssabo
* [FEATURE] Introduce custom-resources-only flag #1813 @bavarianbidi
* [FEATURE] Allow allowlist filtering by wildcard key #1823 @rexagod
* [FEATURE] Add ContainerResourceSourceType to hpa spec and target metrics #1831 @whitebear009
* [FEATURE] Represent group, version and kind of a resource as labels #1850 @rexagod
* [FEATURE] Sharding metrics per node via fieldSelector #1864 @CatherineF-dev
* [FEATURE] Add experimental StatefulSet retention policy metrics #1876 @mattcary
* [FEATURE] Allow labelFromKey field for all applicable metric types #1880 @rexagod
* [FEATURE] Introduce Viper, allow hot-reload on config change #1827 @rexagod
* [FEATURE] Introduce Cobra, allow configuration via environment variables #1834 @rexagod
* [FEATURE] Add experimental kube_node_deletion_timestamp metric #1890 @rexagod
* [FEATURE] Support autoscaling/v2 resources for HorizontalPodAutoscaler #1906 @JoaoBraveCoding
* [FEATURE] Add IngressClass metrics #1905 @kaitoii11
* [ENHANCEMENT] Import Kubernetes metrics stability framework #1844 @CatherineF-dev
* [ENHANCEMENT] Promote kube_pod_container_status_waiting_reason and kube_deployment_status_replicas_ready to stable #1821 @CatherineF-dev
* [ENHANCEMENT] Build with Kubernetes 1.25 and go 1.19 #1819 @mrueg
* [BUGFIX] Handle singular labels in allowlist #1826 @rexagod
* [BUGFIX] Do not expose ingress path metric when service is nil #1841 @evir35
* [BUGFIX] Allow lease metrics to be exported across all namespaces #1845 @lantingchiang

## v2.6.0 / 2022-08-26
* [FEATURE] Add local storage labels to kube_persistentvolume_info #1814 @nabokihms
* [FEATURE] Add support for StateSet and Info metrics for Custom-Resource State #1777 @chrischdi
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
OS ?= $(shell uname -s | tr A-Z a-z)
ALL_ARCH = amd64 arm arm64 ppc64le s390x
PKG = github.com/prometheus/common
PROMETHEUS_VERSION = 2.37.0
GO_VERSION = 1.19.2
PROMETHEUS_VERSION = 2.40.6
GO_VERSION = 1.19.4
IMAGE = $(REGISTRY)/kube-state-metrics
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
USER ?= $(shell id -u -n)
Expand Down Expand Up @@ -78,7 +78,7 @@ shellcheck:
# the two.
test-benchmark-compare:
@git fetch
./tests/compare_benchmarks.sh master
./tests/compare_benchmarks.sh main
./tests/compare_benchmarks.sh ${LATEST_RELEASE_BRANCH}

all: all-container
Expand Down
3 changes: 3 additions & 0 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
reviewers:
- CatherineF-dev
- dgrisonnet
- fpetkovski
- logicalhan
- mrueg
- rexagod
approvers:
- dgrisonnet
- fpetkovski
Expand Down
54 changes: 49 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Overview

[![Build Status](https://github.com/kubernetes/kube-state-metrics/workflows/continuous-integration/badge.svg)](https://github.com/kubernetes/kube-state-metrics/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/kubernetes/kube-state-metrics)](https://goreportcard.com/report/github.com/kubernetes/kube-state-metrics) [![GoDoc](https://godoc.org/github.com/kubernetes/kube-state-metrics?status.svg)](https://godoc.org/github.com/kubernetes/kube-state-metrics)
[![Go Report Card](https://goreportcard.com/badge/github.com/kubernetes/kube-state-metrics)](https://goreportcard.com/report/github.com/kubernetes/kube-state-metrics)
[![Go Reference](https://pkg.go.dev/badge/github.com/kubernetes/kube-state-metrics.svg)](https://pkg.go.dev/github.com/kubernetes/kube-state-metrics)
[![govulncheck](https://github.com/kubernetes/kube-state-metrics/actions/workflows/govulncheck.yml/badge.svg)](https://github.com/kubernetes/kube-state-metrics/actions/workflows/govulncheck.yml)

kube-state-metrics (KSM) is a simple service that listens to the Kubernetes API
server and generates metrics about the state of the objects. (See examples in
Expand Down Expand Up @@ -45,6 +47,7 @@ are deleted they are no longer visible on the `/metrics` endpoint.
- [Resource recommendation](#resource-recommendation)
- [Horizontal sharding](#horizontal-sharding)
- [Automated sharding](#automated-sharding)
- [Daemonset sharding for pod metrics](#daemonset-sharding-pod-metrics)
- [Setup](#setup)
- [Building the Docker container](#building-the-docker-container)
- [Usage](#usage)
Expand All @@ -71,11 +74,11 @@ Generally, it is recommended to use the latest release of kube-state-metrics. If

| kube-state-metrics | Kubernetes client-go Version |
|--------------------|:----------------------------:|
| **v2.3.0** | v1.23 |
| **v2.4.2** | v1.23 |
| **v2.5.0** | v1.24 |
| **v2.6.0** | v1.24 |
| **master** | v1.25 |
| **v2.7.0** | v1.25 |
| **main** | v1.26 |


#### Resource group version compatibility
Expand All @@ -87,7 +90,7 @@ release.
#### Container Image

The latest container image can be found at:
* `registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.6.0` (arch: `amd64`, `arm`, `arm64`, `ppc64le` and `s390x`)
* `registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.7.0` (arch: `amd64`, `arm`, `arm64`, `ppc64le` and `s390x`)

### Metrics Documentation

Expand Down Expand Up @@ -153,7 +156,7 @@ http_request_duration_seconds_count{handler="metrics",method="get"} 30

kube-state-metrics also exposes build and configuration metrics:
```
kube_state_metrics_build_info{branch="master",goversion="go1.15.3",revision="6c9d775d",version="v2.0.0-beta"} 1
kube_state_metrics_build_info{branch="main",goversion="go1.15.3",revision="6c9d775d",version="v2.0.0-beta"} 1
kube_state_metrics_shard_ordinal{shard_ordinal="0"} 0
kube_state_metrics_total_shards 1
```
Expand All @@ -163,6 +166,17 @@ please check the blog post [here](https://www.robustperception.io/exposing-the-s
Sharding metrics expose `--shard` and `--total-shards` flags and can be used to validate
run-time configuration, see [`/examples/prometheus-alerting-rules`](./examples/prometheus-alerting-rules).

kube-state-metrics also exposes metrics about it config file and the Custom Resource State config file:

```
kube_state_metrics_config_hash{filename="crs.yml",type="customresourceconfig"} 2.38272279311849e+14
kube_state_metrics_config_hash{filename="config.yml",type="config"} 2.65285922340846e+14
kube_state_metrics_last_config_reload_success_timestamp_seconds{filename="crs.yml",type="customresourceconfig"} 1.6704882592037103e+09
kube_state_metrics_last_config_reload_success_timestamp_seconds{filename="config.yml",type="config"} 1.6704882592035313e+09
kube_state_metrics_last_config_reload_successful{filename="crs.yml",type="customresourceconfig"} 1
kube_state_metrics_last_config_reload_successful{filename="config.yml",type="config"} 1
```

### Scaling kube-state-metrics

#### Resource recommendation
Expand Down Expand Up @@ -235,6 +249,36 @@ This way of deploying shards is useful when you want to manage KSM shards throug

The downside of using an auto-sharded setup comes from the rollout strategy supported by `StatefulSet`s. When managed by a `StatefulSet`, pods are replaced one at a time with each pod first getting terminated and then recreated. Besides such rollouts being slower, they will also lead to short downtime for each shard. If a Prometheus scrape happens during a rollout, it can miss some of the metrics exported by kube-state-metrics.

### Daemonset sharding for pod metrics

For pod metrics, they can be sharded per node with the following flag:
* `--node`

Each kube-state-metrics pod uses FieldSelector (spec.nodeName) to watch/list pod metrics only on the same node.

A daemonset kube-state-metrics example:
```
apiVersion: apps/v1
kind: DaemonSet
spec:
template:
spec:
containers:
- image: registry.k8s.io/kube-state-metrics/kube-state-metrics:IMAGE_TAG
name: kube-state-metrics
args:
- --resource=pods
- --node=$(NODE_NAME)
env:
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
```

Other metrics can be sharded via [Horizontal sharding](#horizontal-sharding).

### Setup

Install this project to your `$GOPATH` using `go get`:
Expand Down
Loading

0 comments on commit c3c0862

Please sign in to comment.