Commit Graph

112 Commits

Author SHA1 Message Date
Lili Cosic 4093cb34de Adjust klog to klog/v2 2020-10-05 15:29:12 +02:00
Quentin Bisson 7250bc2b5c
Update go module path to k8s.io/kube-state-metrics/v2
Signed-off-by: Quentin Bisson <quentin@giantswarm.io>
2020-09-21 10:58:08 +02:00
Ben Ye 4d8d85f467 use promauto to register metrics
Signed-off-by: Ben Ye <yb532204897@gmail.com>
2020-09-13 19:07:47 -04:00
Lili Cosic 801690bd95 main.go: Add http request metric for kube-state-metrics main /metrics 2020-09-08 15:15:56 +02:00
Joel Whittaker-Smith 908f87b2cd apply boundaries to metrics and allow via flag what labels to include
Signed-off-by: Joel Whittaker-Smith <jdws.dev@gmail.com>
2020-08-26 12:42:30 +02:00
Mathis Raguin 8f78129e66
main: make all contexts child of a root context
Signed-off-by: Mathis Raguin <mathis@cri.epita.fr>
2020-07-27 14:44:46 +02:00
Mathis Raguin f323cdb944
main: move context to local scope
Signed-off-by: Mathis Raguin <mathis@cri.epita.fr>
2020-07-27 11:35:14 +02:00
Mathis Raguin 8bb033103d
main: fix linting
Signed-off-by: Mathis Raguin <mathis@cri.epita.fr>
2020-07-27 11:34:16 +02:00
Mathis Raguin 556ee3a8d6
main: use own context for each group and a timeout
Signed-off-by: Mathis Raguin <mathis@cri.epita.fr>
2020-07-27 11:19:50 +02:00
Mathis Raguin 3b6a93a35d
main: error handling in run group 2020-07-24 18:07:15 +02:00
Mathis Raguin e38b7aaefe
main: graceful shutdown
Signed-off-by: Mathis Raguin <mathis@cri.epita.fr>
2020-07-24 17:59:17 +02:00
Mathis Raguin 56ce7ed701
main: move to run groups
The current implementation can be improved by handling Graceful
Shutdowns of the HTTP Servers.

Signed-off-by: Mathis Raguin <mathis@cri.epita.fr>
2020-07-24 17:25:18 +02:00
Alexander-Carpenter 69fe7da267 Rename collector to resource 2020-02-05 19:43:23 -06:00
yeya24 da2dadcd3e remove deprecated metrics
Signed-off-by: yeya24 <yb532204897@gmail.com>

remove deprecated options

Signed-off-by: yeya24 <yb532204897@gmail.com>
2020-02-05 08:48:23 -05:00
Thibault Le Reste cb655340d6 Rename black-/whitelist to allow/deny-list 2020-02-03 17:05:11 +01:00
cedric lamoriniere 369470d6ea builder.WithGenerateStoreFunc() is now mandatory
This commit introduces the fact that build.WithGenerateStoreFunc()
needs to be used for configuring properly the `Builder` (like any other
`With...` method.

* rename: `WithCustomGenerateStoreFunc` to `WithGenerateStoreFunc`.
* remove buildStorFunc defaulting in `NewBuilder()` function
* add `DefaultGenerateStoreFunc()` method in `BuilderInterface`
* update `Builder initialisation` in `main.go`

Signed-off-by: cedric lamoriniere <cedric.lamoriniere@datadoghq.com>
2020-01-08 13:45:05 +01:00
Frederic Branczyk f3d41de450
Add auto detecting of sharding
main_test.go: Add model based test for sharding

In order to ensure a sharded system behaves equal to an unsharded
system, a model based test has been introduced. It scrapes an unsharded
setup and compares its output with the union of a sharded setup
therefore ensuring semantic equality.
2019-08-30 22:45:35 +02:00
Frederic Branczyk 84d61f9a93
Introduce sharding 2019-08-30 13:51:30 +02:00
Tariq Ibrahim 51def15afa
use MustRegister instead of Register 2019-08-29 13:53:10 -07:00
Lili Cosic 177916445a Address PR comments 2019-08-29 10:21:07 +02:00
Lili Cosic 21b1f61285 *: Add list/watch success/error count total metrics
When kube-state-metrics does not have the correct roles to list or watch
 on a resource, it just logs this error but not actually error out. This
is a problem as the pod never restars and it is hard to catch any
problems as other resource metrics continue to be created correctly. We
only see this error in the noisy kube-state-metrics logs.

This registers two metrics `kube_state_metrics_watch_total` and
`kube_state_metrics_list_total`. With the following labels:
"result" label is the type of action count relates to, error or success.
"resource" label contains the resource <apiVersion.Kind>.

This way we can do a rate alert when kube-state-metrics error rate is
too high.

Example of the metrics:
kube_state_metrics_list_total{resource="*v1.Namespace",result="success"} 1
kube_state_metrics_list_total{resource="*v1.Node",result="error"} 52
kube_state_metrics_watch_total{resource="*v1beta1.Ingress",result="success"} 1
2019-08-28 13:29:07 +02:00
tariqibrahim 44319dbb0d vendor: remove unnecessary dependencies from the project. 2019-07-21 14:59:22 -07:00
Kubernetes Prow Robot 0ffcc30a0f
Merge pull request #791 from monzo/vertical-pod-autoscaler-metrics
store: add metrics for VerticalPodAutoscaler objects
2019-06-20 06:02:49 -07:00
Miles Bryant 67ef5ecc9c
store: add verticalpodautoscaler metrics 2019-06-20 12:24:37 +01:00
Kubernetes Prow Robot 3b1c7c268d
Merge pull request #773 from tariq1890/regex
feat: implement black/white- listing of metrics by regex
2019-06-19 06:48:32 -07:00
Tariq Ibrahim 2a3c696347
feat: implement black/white- listing of metrics by regex 2019-06-19 02:16:52 -07:00
Miles Bryant e1b45de7f6
builder/main: allow collectors not enabled by default
This fixes an issue where it was impossible to specify a collector that
was available but not selected by default.

Instead of checking whether chosen collectors are valid at flag parse
time, this moves the check into the builder, where we can reference it
against the availableStores in the builder. As a bonus, the error
message also prints out a list of available collectors:

```
kube-state-metrics --collectors non-existent-collector
I0618 15:23:34.517532   50719 main.go:88] Using collectors non-existent-collector
F0618 15:23:34.519132   50719 main.go:90] Error: collector non-existent-collector does not exist. Available collectors: persistentvolumeclaims,configmaps,limitranges,nodes,namespaces,persistentvolumes,pods,replicasets,services,cronjobs,deployments,ingresses,horizontalpodautoscalers,jobs,poddisruptionbudgets,secrets,certificatesigningrequests,daemonsets,endpoints,storageclasses,replicationcontrollers,resourcequotas,statefulsets
```
2019-06-18 16:28:11 +01:00
Lili Cosic 68aea02d26 Makefile,internal/collector: Rename collector -> store
Since the removal of collector, this introduces both the concept of the
store and the resources instead of collectors that the user passes in.

The user facing logs and flags were not changed as that would be a
regression.
2019-06-11 16:18:53 +02:00
Lili Cosic cbb7762dc5 *: Remove collector package
collector package was an unnecessary wrapper. This replaces the
.Collect with a call to Store.WriteAll every time a collect is needed.
2019-06-11 16:18:52 +02:00
Tariq Ibrahim 9bcb1959a5
return standardized test for health endpoint 2019-05-24 09:51:04 -07:00
tariqibrahim d1c88bd26a use a more idiomatic way of handling error messages 2019-04-14 00:00:51 -07:00
tariqibrahim 169d841e41 update the prometheus_client_golang dependency to the latest version: v0.9.2 2019-03-28 13:13:01 -07:00
tariqibrahim 1d4c741f84 use klog instead of glog 2019-02-19 20:03:04 -08:00
tariqibrahim cd5711c8f4 use cancelable context instead of context.TODO() 2019-02-13 10:13:21 -08:00
tariqibrahim ab128fedf4 correct some typographical mistakes in kube-state-metrics 2019-02-02 21:55:12 -08:00
Lili Cosic 3498aa7e9e *: Move collectors pkg to internal directory
This makes the rest of the packages useful to be used in a standalone
library without importing the kube-state-metrics specific collectors.

* Rename collectors -> collector package

* Rename metrics -> metric package

* Add metricFamily mocking in tests to prevent cyclic dependency.
2019-01-23 10:51:30 +01:00
Andreas Kohn 509a0dbc33
Remove the obsolete metrics code
These stopped getting populated with 234d788a0d, and
cannot be restored easily.

Related-to: #623
2019-01-10 12:08:12 +01:00
Lv Jiawei 8872080fbe Clear TODO comment in builder.go (#5)
Clear comment --- "TODO : What if not ok?". Because the collector's name
has been checked in CollectorSet.Set function. It will exit if collector' name
is not in DefaultCollectors. As a result, all collectors in Build.enabledCollectors
will find its constructor function. So I think it doesn't exist "not ok" situation.

Signed-off-by: MIBc <lvjiawei@cmss.chinamobile.com>
2018-12-14 15:34:07 +08:00
Max Leonard Inden 7a4887ab9a
pkg/collectors: Refactor node collector 2018-11-29 15:43:49 +01:00
Max Leonard Inden 7ac0ab7410
pkg/builder: Make collector order deterministic
Instead of iterating a map of enabled collectors, iterate a sorted
slice to achieve determinism across scrapes.

Having a consistent order in the metrics output enables Proemetheus to
apply optimizations during metric parsing and ingestion.
2018-11-29 15:43:44 +01:00
Max Leonard Inden af714c7a66
pkg/whiteblacklist: Encapsulate white- blacklisting logic into pkg 2018-11-29 15:43:42 +01:00
Max Leonard Inden d1444f8061
pkg/metrics_store: Accept Writer instead of returning metrics on scrape 2018-11-29 15:43:40 +01:00
Max Leonard Inden 581c49d593
pkg/collectors: Reintroduce help text 2018-11-29 15:43:39 +01:00
Max Leonard Inden d44a8bc991
pkg/collectors: Renable white-/blacklisting
Reenable feature to filter the exposition of metric families by their
name. This is now done at startup time, thereby not slowing down the
critical path.
2018-11-29 15:43:36 +01:00
Max Leonard Inden 4cc7e9be49
pkg/options: Add flag to enable gzip encoding for responses
Dependent on the environment users might or might not want to encode the
responses of kube-state-metrics via gzip independent of the
`Accept-Header` that the client (Prometheus) sends.
2018-10-24 16:11:53 +02:00
Max Leonard Inden 234d788a0d
*: Optimize performance & resource utilization via custom metrics store
This patch introduces a custom client go store, MetricsStore. It is
updated by a corresponding reflector. Instead of generating the
Prometheus custom metrics on demand, metrics are generated on new
Kubernetes object arrival.

In addition this patch replaces most of the logic of the Prometheus
client_golang package by its optimized custom logic to render metrics in
text format.

Next to these main changes this patch also includes:

- Documentation/design: Add performance optimization proposal
- tests/e2e.sh: Ignore "no help text" warnings by promtool
- .travis.yml: Run tests in parallel
  As non of the Travis tests depend on each other, there is no reason to
  run them in sequence. Instead this patch makes them run in parallel.
2018-10-16 15:49:16 +02:00
Max Leonard Inden 183c7988fb
main_test.go: Introduce overarching benchmark test
This patch adds a simple go benchmark test, injecting Kubernetes objects
and simulating scrape requests. It uses the Kubernetes client-go fake
client. Alongside comes some refactoring of each collectors structure
using informer factories to be compatible with the fake client.

The patch lays the groundwork to make future performance optimizations
comparable with past versions.

How to run test:
`go test -race -bench  . -memprofile=mem.out -cpuprofile=cpu.out`
2018-08-17 11:52:02 +02:00
Frederic Branczyk c522d44f7b
Allow white- and black-listing metrics to be exposed 2018-07-23 17:36:11 +02:00
Andy Xie e025e06707 adjust client-go User-Agent 2018-06-25 17:02:24 +08:00
Andy Xie 3258e1ed58 prefer protobuf instead of just json format 2018-06-12 16:55:11 +08:00