Skip to content

Commit 6141abc

Browse files
authored
Merge pull request #1301 from lilic/optimize-filter-labels
Adjust and refactor allowing labels to work for kubernetes labels metrics
2 parents 7e45630 + a551501 commit 6141abc

61 files changed

Lines changed: 503 additions & 688 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ linters:
1818
linters-settings:
1919
goimports:
2020
local-prefixes: k8s.io/kube-state-metrics
21+
gocyclo:
22+
# temporary until we refactor the pod function
23+
min-complexity: 128
2124

2225
issues:
2326
exclude-use-default: false

docs/cli-arguments.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,34 @@ spec:
2525
```txt
2626
$ kube-state-metrics -h
2727
Usage of ./kube-state-metrics:
28-
--add_dir_header If true, adds the file directory to the header of the log messages
29-
--alsologtostderr log to standard error as well as files
30-
--apiserver string The URL of the apiserver to use as a master
31-
--enable-gzip-encoding Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.
32-
-h, --help Print Help text
33-
--host string Host to expose metrics on. (default "0.0.0.0")
34-
--kubeconfig string Absolute path to the kubeconfig file
35-
--labels-allow-list string list of metric names and labels you would like to allow, metric_name=[label1,labeln...],metric_name[]...
36-
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
37-
--log_dir string If non-empty, write log files in this directory
38-
--log_file string If non-empty, use this log file
39-
--log_file_max_size uint Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
40-
--logtostderr log to standard error instead of files (default true)
41-
--metric-allowlist string Comma-separated list of metrics to be exposed. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
42-
--metric-denylist string Comma-separated list of metrics not to be enabled. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
43-
--namespaces string Comma-separated list of namespaces to be enabled. Defaults to ""
44-
--pod string Name of the pod that contains the kube-state-metrics container. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
45-
--pod-namespace string Name of the namespace of the pod specified by --pod. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
46-
--port int Port to expose metrics on. (default 8080)
47-
--resources string Comma-separated list of Resources to be enabled. Defaults to "certificatesigningrequests,configmaps,cronjobs,daemonsets,deployments,endpoints,horizontalpodautoscalers,ingresses,jobs,leases,limitranges,mutatingwebhookconfigurations,namespaces,networkpolicies,nodes,persistentvolumeclaims,persistentvolumes,poddisruptionbudgets,pods,replicasets,replicationcontrollers,resourcequotas,secrets,services,statefulsets,storageclasses,validatingwebhookconfigurations,volumeattachments"
48-
--shard int32 The instances shard nominal (zero indexed) within the total number of shards. (default 0)
49-
--skip_headers If true, avoid header prefixes in the log messages
50-
--skip_log_headers If true, avoid headers when opening log files
51-
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
52-
--telemetry-host string Host to expose kube-state-metrics self metrics on. (default "0.0.0.0")
53-
--telemetry-port int Port to expose kube-state-metrics self metrics on. (default 8081)
54-
--total-shards int The total number of shards. Sharding is disabled when total shards is set to 1. (default 1)
55-
-v, --v Level number for the log level verbosity
56-
--version kube-state-metrics build version information
57-
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
28+
--add_dir_header If true, adds the file directory to the header of the log messages
29+
--alsologtostderr log to standard error as well as files
30+
--apiserver string The URL of the apiserver to use as a master
31+
--enable-gzip-encoding Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.
32+
-h, --help Print Help text
33+
--host string Host to expose metrics on. (default "0.0.0.0")
34+
--kubeconfig string Absolute path to the kubeconfig file
35+
--labels-metric-allow-list string Allows to pass a list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional labels provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=["k8s-label-1","k8s-label-n",...],pods=["app"],...)'
36+
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
37+
--log_dir string If non-empty, write log files in this directory
38+
--log_file string If non-empty, use this log file
39+
--log_file_max_size uint Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
40+
--logtostderr log to standard error instead of files (default true)
41+
--metric-allowlist string Comma-separated list of metrics to be exposed. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
42+
--metric-denylist string Comma-separated list of metrics not to be enabled. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
43+
--namespaces string Comma-separated list of namespaces to be enabled. Defaults to ""
44+
--pod string Name of the pod that contains the kube-state-metrics container. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
45+
--pod-namespace string Name of the namespace of the pod specified by --pod. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
46+
--port int Port to expose metrics on. (default 8080)
47+
--resources string Comma-separated list of Resources to be enabled. Defaults to "certificatesigningrequests,configmaps,cronjobs,daemonsets,deployments,endpoints,horizontalpodautoscalers,ingresses,jobs,leases,limitranges,mutatingwebhookconfigurations,namespaces,networkpolicies,nodes,persistentvolumeclaims,persistentvolumes,poddisruptionbudgets,pods,replicasets,replicationcontrollers,resourcequotas,secrets,services,statefulsets,storageclasses,validatingwebhookconfigurations,volumeattachments"
48+
--shard int32 The instances shard nominal (zero indexed) within the total number of shards. (default 0)
49+
--skip_headers If true, avoid header prefixes in the log messages
50+
--skip_log_headers If true, avoid headers when opening log files
51+
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
52+
--telemetry-host string Host to expose kube-state-metrics self metrics on. (default "0.0.0.0")
53+
--telemetry-port int Port to expose kube-state-metrics self metrics on. (default 8081)
54+
--total-shards int The total number of shards. Sharding is disabled when total shards is set to 1. (default 1)
55+
-v, --v Level number for the log level verbosity
56+
--version kube-state-metrics build version information
57+
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
5858
```

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/google/go-jsonnet v0.14.0
1111
github.com/jsonnet-bundler/jsonnet-bundler v0.4.1-0.20200708074244-ada055a225fa
1212
github.com/mattn/go-colorable v0.1.7 // indirect
13+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
1314
github.com/oklog/run v1.1.0
1415
github.com/pkg/errors v0.9.1
1516
github.com/prometheus/client_golang v1.7.1
@@ -20,11 +21,11 @@ require (
2021
github.com/spf13/pflag v1.0.5
2122
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
2223
golang.org/x/sys v0.0.0-20200915084602-288bc346aa39 // indirect
23-
golang.org/x/tools v0.0.0-20200305205014-bc073721adb6
24-
k8s.io/api v0.19.2
25-
k8s.io/apimachinery v0.19.2
24+
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054
25+
k8s.io/api v0.19.3
26+
k8s.io/apimachinery v0.19.3
2627
k8s.io/autoscaler/vertical-pod-autoscaler v0.0.0-20200727194258-b7922d74509c
27-
k8s.io/client-go v0.19.2
28+
k8s.io/client-go v0.19.3
2829
k8s.io/klog/v2 v2.2.0
2930
)
3031

go.sum

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
209209
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
210210
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
211211
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
212+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
213+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
212214
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
213215
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
214216
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -271,6 +273,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
271273
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
272274
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
273275
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
276+
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
274277
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
275278
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
276279
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@@ -405,8 +408,8 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn
405408
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
406409
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
407410
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
408-
golang.org/x/tools v0.0.0-20200305205014-bc073721adb6 h1:V/kH9fbTtfqZLJU7djyPh+n4yWxBZVU6H5npu6UeY54=
409-
golang.org/x/tools v0.0.0-20200305205014-bc073721adb6/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
411+
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054 h1:HHeAlu5H9b71C+Fx0K+1dGgVFN1DM1/wz4aoGOA5qS8=
412+
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
410413
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
411414
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
412415
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
@@ -476,16 +479,16 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
476479
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
477480
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
478481
k8s.io/api v0.18.3/go.mod h1:UOaMwERbqJMfeeeHc8XJKawj4P9TgDRnViIqqBeH2QA=
479-
k8s.io/api v0.19.2 h1:q+/krnHWKsL7OBZg/rxnycsl9569Pud76UJ77MvKXms=
480-
k8s.io/api v0.19.2/go.mod h1:IQpK0zFQ1xc5iNIQPqzgoOwuFugaYHK4iCknlAQP9nI=
482+
k8s.io/api v0.19.3 h1:GN6ntFnv44Vptj/b+OnMW7FmzkpDoIDLZRvKX3XH9aU=
483+
k8s.io/api v0.19.3/go.mod h1:VF+5FT1B74Pw3KxMdKyinLo+zynBaMBiAfGMuldcNDs=
481484
k8s.io/apimachinery v0.18.3/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
482-
k8s.io/apimachinery v0.19.2 h1:5Gy9vQpAGTKHPVOh5c4plE274X8D/6cuEiTO2zve7tc=
483-
k8s.io/apimachinery v0.19.2/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
485+
k8s.io/apimachinery v0.19.3 h1:bpIQXlKjB4cB/oNpnNnV+BybGPR7iP5oYpsOTEJ4hgc=
486+
k8s.io/apimachinery v0.19.3/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
484487
k8s.io/autoscaler/vertical-pod-autoscaler v0.0.0-20200727194258-b7922d74509c h1:y/FLIxopomJplrOAqT157NJNWqHJP9QbTcYXGEYGJmk=
485488
k8s.io/autoscaler/vertical-pod-autoscaler v0.0.0-20200727194258-b7922d74509c/go.mod h1:PwWTGRRCxefhAezrDbG/tRYSAW7etHjjMPAr8fXKVAA=
486489
k8s.io/client-go v0.18.3/go.mod h1:4a/dpQEvzAhT1BbuWW09qvIaGw6Gbu1gZYiQZIi1DMw=
487-
k8s.io/client-go v0.19.2 h1:gMJuU3xJZs86L1oQ99R4EViAADUPMHHtS9jFshasHSc=
488-
k8s.io/client-go v0.19.2/go.mod h1:S5wPhCqyDNAlzM9CnEdgTGV4OqhsW3jGO1UM1epwfJA=
490+
k8s.io/client-go v0.19.3 h1:ctqR1nQ52NUs6LpI0w+a5U+xjYwflFwA13OJKcicMxg=
491+
k8s.io/client-go v0.19.3/go.mod h1:+eEMktZM+MG0KO+PTkci8xnbCZHvj9TqR6Q1XDUIJOM=
489492
k8s.io/code-generator v0.18.3/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c=
490493
k8s.io/component-base v0.18.3/go.mod h1:bp5GzGR0aGkYEfTj+eTY0AN/vXTgkJdQXjNTTVUaa3k=
491494
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=

0 commit comments

Comments
 (0)