Commit Graph

77 Commits

Author SHA1 Message Date
yshngg 141c1f05bc changes for continuing to run when file doesnt exist 2025-08-19 09:45:35 -07:00
Rashmi Chandrashekar 921147623e support overrides 2025-08-05 19:30:00 -07:00
Manuel Rüger a5789613f1 feat: Add AuthFilter
This adds an Authentication/Authorization filter through Kubernetes'
TokenReview / SubjectAccessReview resources.

The client config for kube-state-metrics needs a clusterrole for

* apiGroups: authentication.k8s.io, resources: tokenreviews, verbs: create
* apiGroups: authorization.k8s.io, resources: subjectaccessreviews, verbs: create

The Prometheus client needs a clusterrole for

* nonResourceURLs: "/metrics", verbs: get
2025-06-23 14:17:52 +02:00
Manuel Rüger 4519b2848b feat: Introduce object limits
This change allows user-controlled limits on how many objects KSM will
list from the API. This is helpful to prevent resource exhaustion on
KSM, in case the API creates too many resources.

The object limit it set globally and applied per resource watched.
2025-05-31 23:29:41 +02:00
Pranshu Srivastava 8b631bbff4
feat: Use `dlclark/regexp2` over standard library's package
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
2025-03-18 18:57:25 +05:30
Manuel Rüger 0a86b24b08 chore: Memory align structs
pkg/metric_generator/generator.go:32:22: 16 bytes saved: struct with 96 pointer bytes could be 80
pkg/metrics_store/metrics_store.go:31:19: 40 bytes saved: struct with 64 pointer bytes could be 24
pkg/options/options.go:42:14: 24 bytes saved: struct of size 384 could be 360
internal/store/builder.go:67:14: 8 bytes saved: struct of size 200 could be 192
internal/store/pod.go:1351:16: 8 bytes saved: struct with 16 pointer bytes could be 8
internal/store/pod.go:1477:20: 8 bytes saved: struct with 16 pointer bytes could be 8
internal/store/testutils.go:32:30: 16 bytes saved: struct with 136 pointer bytes could be 120
pkg/metricshandler/metrics_handler.go:46:21: 8 bytes saved: struct of size 104 could be 96
internal/discovery/types.go:39:19: 32 bytes saved: struct with 88 pointer bytes could be 56
pkg/customresourcestate/config.go:51:15: 16 bytes saved: struct with 112 pointer bytes could be 96
pkg/customresourcestate/config.go:134:16: 8 bytes saved: struct with 88 pointer bytes could be 80
pkg/customresourcestate/config.go:150:13: 8 bytes saved: struct with 40 pointer bytes could be 32
pkg/customresourcestate/config_metrics_types.go:29:18: 8 bytes saved: struct with 64 pointer bytes could be 56
pkg/customresourcestate/config_metrics_types.go:42:17: 8 bytes saved: struct with 40 pointer bytes could be 32
pkg/customresourcestate/registry_factory.go:125:21: 8 bytes saved: struct with 40 pointer bytes could be 32
pkg/customresourcestate/registry_factory.go:212:20: 16 bytes saved: struct with 88 pointer bytes could be 72
pkg/customresourcestate/registry_factory.go:377:23: 8 bytes saved: struct with 104 pointer bytes could be 96
pkg/customresourcestate/registry_factory.go:497:21: 8 bytes saved: struct with 64 pointer bytes could be 56
pkg/customresourcestate/registry_factory.go:549:13: 8 bytes saved: struct with 24 pointer bytes could be 16
2024-08-08 19:03:28 +02:00
Catherine Fang aeb9e355b5 Fix Nodetype 2024-07-24 10:01:05 -04:00
Catherine Fang eda1984438 Rename --enable-unscheduled-pods-fetching to --track-unscheduled-pods 2024-07-23 20:21:17 -04:00
Catherine Fang 19a0544f44 update doc 2024-07-23 20:20:18 -04:00
Catherine Fang 85f8a2c4cc rename to --enable-unscheduled-pods-fetching 2024-07-23 20:19:09 -04:00
Catherine Fang 49e1170f67 rename to --fetch-unscheduled-pods 2024-07-23 20:18:53 -04:00
CatherineF-dev b27845d535 use --enable-no-node-scrape
Co-authored-by: Alex Kennedy <alexzanderkennedy@gmail.com>
2024-07-23 20:18:35 -04:00
SuperQ eea0524d54
Add automatic detection of memory limits
Add automatic detection of container and system memory limits to control
the Go `GOMEMLIMIT` garbage collector feature. This helps reduced OOMs
by triggering GC when the process approaches system limits.

Signed-off-by: SuperQ <superq@gmail.com>
2024-07-16 12:09:22 +02:00
pokom 28dbd26540 Create variables for default values of new flags 2024-06-07 13:14:57 -04:00
pokom b4f032ecfd Add additional flags for IdleTimeouts 2024-06-06 13:11:00 -04:00
pokom e97933bcb9 fix(server): Add read and write timeouts
There are a few documented scenarios where `kube-state-metrics` will
lock up(#995, #1028). I believe a much simpler solution to ensure
`kube-state-metrics` doesn't lock up and require a restart to server
`/metrics` requests is to add default read and write timeouts and to
allow them to be configurable. At Grafana, we've experienced a few
scenarios where `kube-state-metrics` running in larger clusters falls
behind and starts getting scraped multiple times. When this occurs,
`kube-state-metrics` becomes completely unresponsive and requires a
reboot. This is somewhat easily reproduceable(I'll provide a script in
an issue) and causes other critical workloads(KEDA, VPA) to fail in
weird ways.

Adds two flags:
- `server-read-timeout`
- `server-write-timeout`

Updates the metrics http server to set the `ReadTimeout` and
`WriteTimeout` to the configured values.
2024-06-05 14:18:43 -04:00
Manuel Rüger fd2a1f83f3 chore: Build with go 1.22 2024-04-05 00:20:04 +02:00
蓝宝石的傻话 d33929e543 examples generated from libsonnet
Signed-off-by: 蓝宝石的傻话 <mickey_zzc@163.com>
2023-10-12 23:20:38 +08:00
mickeyzzc 539f57d75d simplified configuration
Signed-off-by: mickeyzzc <mickey_zzc@163.com>
2023-10-12 21:00:10 +08:00
mickeyzzc 82f567907e pods support no node scraping
Signed-off-by: mickeyzzc <mickey_zzc@163.com>
2023-10-11 13:47:05 +08:00
Damien Grisonnet 6f7269858d options: update labels/annotations allowlist doc
Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>
2023-08-23 11:42:31 +02:00
Benjamin Jorand ca7bc253b0 clean broken --version flag 2023-01-23 13:24:01 +01:00
Manuel Rüger ee891760b8 Add metrics for config file changes
This uses code pieces from prometheus/alertmanager in https://github.com/prometheus/alertmanager/blob/main/config/coordinator.go#LL56C26-L56C26
licensed under Apache-2.0.

kube_state_metrics_config_hash{type="config", filename="config.yml"} 4.0061079457904e+13
kube_state_metrics_config_last_reload_success_timestamp_seconds{type="config", filename="config.yml"} 1.6697483049487052e+09
kube_state_metrics_config_last_reload_successful{type="config",
filename="config.yml"} 1

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
2022-12-02 15:41:57 +01:00
Pranshu Srivastava f8360a8903
Add end-to-end testing to verify hot-reloading
Add end-to-end testing to verify hot-reloading for event-based changes
stemming from the config file. Also,
* sent in a doc fix that was missed
earlier:
https://github.com/kubernetes/kube-state-metrics/pull/1890/files#diff-380eca5a922c0ddbf67f04daefc6823e7ef0e197434d3a826d39c7063cdfa6d6R15,
* updated fsnotify and viper dependencies (v1.6.0 and v1.14.0
  respectively).

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
2022-11-16 20:26:22 +05:30
Pranshu Srivastava 9860f46776
Implement hot-reloading based on config changes
Reload KSM on-the-fly when a change is detected in the configuration.

Meta changes (will squash)
2022-11-16 20:26:12 +05:30
Pranshu Srivastava 5888a7eb37
Add --config flag
--config flag defines the path to the kube-state-metrics options config file.
2022-11-16 20:26:12 +05:30
Pranshu Srivastava b926fd968e
Incorporate Cobra
s/pflags/cobra/g:
* Use spf13/cobra to handle all flags and sub-commands.
* Remove all spf13/pflag usage, and fallback to the in-build flag
  package if, and when needed.
* Add completion support.

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
2022-11-10 18:25:12 +05:30
Kubernetes Prow Robot c0a03ad6bb
Merge pull request #1813 from bavarianbidi/crd_only_mode
introduce custom-resources-only flag ...
2022-11-08 03:44:20 -08:00
Kubernetes Prow Robot d5bd2c8274
Merge pull request #1823 from rexagod/1815
Support filtering label allowlist by "*"
2022-11-08 03:42:22 -08:00
Pranshu Srivastava d982bbc9c9
Support filtering label allowlist by "*"
Support filtering label allowlist by "*", which will expand to the
enabled resources, while infering their values based on its value(s).

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
2022-11-07 23:59:36 +05:30
Mario Constanti 53af11625c introduce custom-resources-only flag ...
... to only monitor all known custom-resource configurations instead of
listing each of them explicitly

Signed-off-by: Mario Constanti <mario@constanti.de>
2022-11-07 07:31:41 +01:00
Catherine Fang 43c6073234 Refactoring 2022-11-04 15:07:37 -04:00
Catherine Fang f9d29ba761 Refactoring 2022-11-04 08:44:00 -04:00
Catherine Fang 87a7793c7f Clean 2022-11-04 08:44:00 -04:00
Catherine Fang 2c0c8d2e51 Sharding per node 2022-11-04 08:44:00 -04:00
Manuel Rüger 6b7027ff41 Harden and add gosec linter
Remediate:
G104: Errors unhandled.
G109: Potential Integer overflow made by strconv.Atoi result conversion to int16/32
G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server
G304: Potential file inclusion via variable
G601: Implicit memory aliasing in for loop.

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
2022-10-20 20:44:46 +02:00
noah 99d86bb5a5
another exp note
Co-authored-by: Manuel Rüger <manuel@rueg.eu>
2022-06-01 20:33:43 -05:00
noah 6ec0332bd5
note experimental status
Co-authored-by: Manuel Rüger <manuel@rueg.eu>
2022-06-01 10:11:27 -05:00
Noah Perks Sloan a9ec8a6209 fix: remove dots in flag names 2022-06-01 09:21:05 -05:00
Noah Perks Sloan d0aa4a3bdd refactor: inline config as a flag
This is more flexible than the env variable, as a configuration can still set an env variable and use substitution in the args. e.g.,

```yaml
args:
 - --custom-resource-state.config
 - $(KSM_CUSTOM_RESOURCE_STATE_CONFIG)
env:
 ...
```
2022-06-01 09:12:48 -05:00
Noah Perks Sloan 4b704fd90e fix: use a flag for the configuration file 2022-05-31 16:11:49 -05:00
Julian van den Berkmortel da04a73f68
Add the opt-in metric family filter to expose or not to a metric family from the store (#1574) 2021-12-01 22:08:52 +01:00
Min Wang 77418c7dba
Add namespace denied list 2021-10-19 11:20:17 -07:00
Sylvain Rabot 0e45534441
Merge remote-tracking branch 'origin/master' into annotations 2021-08-19 16:31:20 +02:00
Lan Liang 78775b02eb rename use-api-server-cache to use-apiserver-cache in flags 2021-08-18 12:58:01 +08:00
Lan Liang 185687e6ad Change useApiServerCache to useAPIServerCache 2021-08-16 22:16:24 +08:00
Lan Liang 3bbd8d5a88 Add arg use-api-server-cache to set resourceVersion=0 for ListWatch 2021-08-13 13:12:36 +08:00
Sylvain Rabot 65bc62af5c
Add kube_*_annotations metrics
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-04-29 16:04:16 +02:00
Mikulas (Mike) Dite 70d039b140 Add wildcard option to labels-metric-allow-list 2021-03-30 14:26:12 +01:00
Manuel Rüger 8160f327b0 Merge branch 'release-2.0' into merge-release-2.0 2021-03-26 23:54:14 +01:00