Commit Graph

108 Commits

Author SHA1 Message Date
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
蓝宝石的傻话 d1f04c2479 Add code comments
Signed-off-by: 蓝宝石的傻话 <mickey_zzc@163.com>
2023-10-20 23:10:16 +08:00
蓝宝石的傻话 5fc87fac85 add test
Signed-off-by: 蓝宝石的傻话 <mickey_zzc@163.com>
2023-10-13 00:08:54 +08: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
Manuel Rüger 6071db7f49 build: Fix lint 2023-08-25 12:50:58 +02: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
CatherineF-dev 813496de4f Update README.md
Co-authored-by: Manuel Rüger <manuel@rueg.eu>
2022-11-04 13:12:53 -04:00
Catherine Fang f9d29ba761 Refactoring 2022-11-04 08:44:00 -04:00
Catherine Fang d523f8e0e4 Move merging fieldselectors into app/server.go and replace namespaceFitler with fieldSelectorFilter 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
Manuel Rüger 93e79fc9d8 Remove RBAC resources from default exposed metric set
These resources might create a lot of metrics,
so we won't enable them by default for now.

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
2022-08-23 18:44:55 +02:00
Kubernetes Prow Robot 3532203e8f
Merge pull request #1799 from kaitoii11/rolebinding
Add support for rolebindings
2022-08-18 12:22:12 -07:00
John ebb8b10551
Apply suggestions from code review
Co-authored-by: JUN YANG <yang.jun22@zte.com.cn>
2022-08-13 21:44:46 +02:00
John d5486a7d87
Apply suggestions from code review
Co-authored-by: JUN YANG <yang.jun22@zte.com.cn>
2022-08-13 21:44:23 +02:00
John 62beea063a
Apply suggestions from code review
Co-authored-by: JUN YANG <yang.jun22@zte.com.cn>
2022-08-13 21:44:00 +02:00
dmpe f406c1aa1d feat(logging): migrate to structured logging
Signed-off-by: dmpe <John Malc> <cincenko@outlook.com>
2022-08-13 14:18:56 +02:00
Kaito Ii 2cd6aaa8aa fix filename and sort order 2022-08-09 23:17:20 +09:00
Kaito Ii 51df8fe763 add rolebinding metrics 2022-08-07 01:32:57 +09:00
Kaito Ii 3c9908d0b3 add role and cluster role
Signed-off-by: Kaito Ii <kaitoii1111@gmail.com>
2022-06-30 20:55:25 +09:00
Julian van den Berkmortel 6a24f639f8
Add support for the ServiceAccount resource (Ref: #1717) 2022-06-29 23:58:01 +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
Kubernetes Prow Robot 57533e4d60
Merge pull request #1706 from sthaha/test-newline-in-metricset
Assert that newlines in coma separated arguments are ignored
2022-03-09 06:14:12 -08:00
Sunil Thaha c309956a6f
Assert that newlines in coma separated arguments are ignored
This test is added to ensure that ksm can be invoked as follows and that
this is a "documented" feature.
```
<ksm> --metric-denylist="
    ^kube_.+_created$,
    ^kube_.+_metadata_resource_version$,
    ^kube_pod_completion_time$,
    ^kube_pod_status_scheduled$
  "
```
See: Usage in kube-prometheus jsonnet for example [1]

[1]: 9cf6111562/jsonnet/kube-prometheus/addons/ksm-lite.libsonnet (L18)

Signed-off-by: Sunil Thaha <sthaha@redhat.com>
2022-03-09 14:12:25 +10: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 853ad1028a
adddress comments 2021-10-19 11:20:18 -07:00
Min Wang bde6d151ef
fix linter check 2021-10-19 11:20:18 -07:00
Min Wang c6ec339eea
address comments 2021-10-19 11:20:18 -07:00
Min Wang 6f7b4b1b76
add more test cases 2021-10-19 11:20:17 -07:00