72
vendor/k8s.io/component-base/cli/flag/ciphersuites_flag.go
generated
vendored
72
vendor/k8s.io/component-base/cli/flag/ciphersuites_flag.go
generated
vendored
@@ -25,32 +25,61 @@ import (
|
||||
|
||||
// ciphers maps strings into tls package cipher constants in
|
||||
// https://golang.org/pkg/crypto/tls/#pkg-constants
|
||||
// to be replaced by tls.CipherSuites() when the project migrates to go1.14.
|
||||
var ciphers = map[string]uint16{
|
||||
"TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA,
|
||||
"TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
|
||||
"TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA,
|
||||
"TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA,
|
||||
"TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
|
||||
"TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
|
||||
"TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
|
||||
"TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
|
||||
"TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA,
|
||||
"TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
|
||||
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
||||
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
|
||||
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
|
||||
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
|
||||
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
||||
"TLS_AES_128_GCM_SHA256": tls.TLS_AES_128_GCM_SHA256,
|
||||
"TLS_CHACHA20_POLY1305_SHA256": tls.TLS_CHACHA20_POLY1305_SHA256,
|
||||
"TLS_AES_256_GCM_SHA384": tls.TLS_AES_256_GCM_SHA384,
|
||||
}
|
||||
|
||||
func TLSCipherPossibleValues() []string {
|
||||
// to be replaced by tls.InsecureCipherSuites() when the project migrates to go1.14.
|
||||
var insecureCiphers = map[string]uint16{
|
||||
"TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA,
|
||||
"TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
|
||||
"TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
|
||||
"TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA,
|
||||
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
|
||||
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
|
||||
}
|
||||
|
||||
// InsecureTLSCiphers returns the cipher suites implemented by crypto/tls which have
|
||||
// security issues.
|
||||
func InsecureTLSCiphers() map[string]uint16 {
|
||||
cipherKeys := make(map[string]uint16, len(insecureCiphers))
|
||||
for k, v := range insecureCiphers {
|
||||
cipherKeys[k] = v
|
||||
}
|
||||
return cipherKeys
|
||||
}
|
||||
|
||||
// InsecureTLSCipherNames returns a list of cipher suite names implemented by crypto/tls
|
||||
// which have security issues.
|
||||
func InsecureTLSCipherNames() []string {
|
||||
cipherKeys := sets.NewString()
|
||||
for key := range insecureCiphers {
|
||||
cipherKeys.Insert(key)
|
||||
}
|
||||
return cipherKeys.List()
|
||||
}
|
||||
|
||||
// PreferredTLSCipherNames returns a list of cipher suite names implemented by crypto/tls.
|
||||
func PreferredTLSCipherNames() []string {
|
||||
cipherKeys := sets.NewString()
|
||||
for key := range ciphers {
|
||||
cipherKeys.Insert(key)
|
||||
@@ -58,13 +87,37 @@ func TLSCipherPossibleValues() []string {
|
||||
return cipherKeys.List()
|
||||
}
|
||||
|
||||
func allCiphers() map[string]uint16 {
|
||||
acceptedCiphers := make(map[string]uint16, len(ciphers)+len(insecureCiphers))
|
||||
for k, v := range ciphers {
|
||||
acceptedCiphers[k] = v
|
||||
}
|
||||
for k, v := range insecureCiphers {
|
||||
acceptedCiphers[k] = v
|
||||
}
|
||||
return acceptedCiphers
|
||||
}
|
||||
|
||||
// TLSCipherPossibleValues returns all acceptable cipher suite names.
|
||||
// This is a combination of both InsecureTLSCipherNames() and PreferredTLSCipherNames().
|
||||
func TLSCipherPossibleValues() []string {
|
||||
cipherKeys := sets.NewString()
|
||||
acceptedCiphers := allCiphers()
|
||||
for key := range acceptedCiphers {
|
||||
cipherKeys.Insert(key)
|
||||
}
|
||||
return cipherKeys.List()
|
||||
}
|
||||
|
||||
// TLSCipherSuites returns a list of cipher suite IDs from the cipher suite names passed.
|
||||
func TLSCipherSuites(cipherNames []string) ([]uint16, error) {
|
||||
if len(cipherNames) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
ciphersIntSlice := make([]uint16, 0)
|
||||
possibleCiphers := allCiphers()
|
||||
for _, cipher := range cipherNames {
|
||||
intValue, ok := ciphers[cipher]
|
||||
intValue, ok := possibleCiphers[cipher]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Cipher suite %s not supported or doesn't exist", cipher)
|
||||
}
|
||||
@@ -80,6 +133,7 @@ var versions = map[string]uint16{
|
||||
"VersionTLS13": tls.VersionTLS13,
|
||||
}
|
||||
|
||||
// TLSPossibleVersions returns all acceptable values for TLS Version.
|
||||
func TLSPossibleVersions() []string {
|
||||
versionsKeys := sets.NewString()
|
||||
for key := range versions {
|
||||
@@ -88,6 +142,7 @@ func TLSPossibleVersions() []string {
|
||||
return versionsKeys.List()
|
||||
}
|
||||
|
||||
// TLSVersion returns the TLS Version ID for the version name passed.
|
||||
func TLSVersion(versionName string) (uint16, error) {
|
||||
if len(versionName) == 0 {
|
||||
return DefaultTLSVersion(), nil
|
||||
@@ -98,6 +153,7 @@ func TLSVersion(versionName string) (uint16, error) {
|
||||
return 0, fmt.Errorf("unknown tls version %q", versionName)
|
||||
}
|
||||
|
||||
// DefaultTLSVersion defines the default TLS Version.
|
||||
func DefaultTLSVersion() uint16 {
|
||||
// Can't use SSLv3 because of POODLE and BEAST
|
||||
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
|
||||
|
||||
29
vendor/k8s.io/component-base/cli/flag/ciphersuites_flag_114.go
generated
vendored
Normal file
29
vendor/k8s.io/component-base/cli/flag/ciphersuites_flag_114.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// +build go1.14
|
||||
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flag
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// support official IANA names as well on go1.14
|
||||
ciphers["TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"] = tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
|
||||
ciphers["TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"] = tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
|
||||
}
|
||||
9
vendor/k8s.io/component-base/cli/flag/flags.go
generated
vendored
9
vendor/k8s.io/component-base/cli/flag/flags.go
generated
vendored
@@ -21,7 +21,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// WordSepNormalizeFunc changes all flags that contain "_" separators
|
||||
@@ -52,3 +52,10 @@ func InitFlags() {
|
||||
klog.V(2).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
|
||||
})
|
||||
}
|
||||
|
||||
// PrintFlags logs the flags in the flagset
|
||||
func PrintFlags(flags *pflag.FlagSet) {
|
||||
flags.VisitAll(func(flag *pflag.Flag) {
|
||||
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
|
||||
})
|
||||
}
|
||||
|
||||
2
vendor/k8s.io/component-base/cli/flag/namedcertkey_flag.go
generated
vendored
2
vendor/k8s.io/component-base/cli/flag/namedcertkey_flag.go
generated
vendored
@@ -75,7 +75,7 @@ type NamedCertKeyArray struct {
|
||||
changed bool
|
||||
}
|
||||
|
||||
var _ flag.Value = &NamedCertKey{}
|
||||
var _ flag.Value = &NamedCertKeyArray{}
|
||||
|
||||
// NewNamedKeyCertArray creates a new NamedCertKeyArray with the internal value
|
||||
// pointing to p.
|
||||
|
||||
9
vendor/k8s.io/component-base/cli/flag/sectioned.go
generated
vendored
9
vendor/k8s.io/component-base/cli/flag/sectioned.go
generated
vendored
@@ -31,6 +31,8 @@ type NamedFlagSets struct {
|
||||
Order []string
|
||||
// FlagSets stores the flag sets by name.
|
||||
FlagSets map[string]*pflag.FlagSet
|
||||
// NormalizeNameFunc is the normalize function which used to initialize FlagSets created by NamedFlagSets.
|
||||
NormalizeNameFunc func(f *pflag.FlagSet, name string) pflag.NormalizedName
|
||||
}
|
||||
|
||||
// FlagSet returns the flag set with the given name and adds it to the
|
||||
@@ -40,7 +42,12 @@ func (nfs *NamedFlagSets) FlagSet(name string) *pflag.FlagSet {
|
||||
nfs.FlagSets = map[string]*pflag.FlagSet{}
|
||||
}
|
||||
if _, ok := nfs.FlagSets[name]; !ok {
|
||||
nfs.FlagSets[name] = pflag.NewFlagSet(name, pflag.ExitOnError)
|
||||
flagSet := pflag.NewFlagSet(name, pflag.ExitOnError)
|
||||
flagSet.SetNormalizeFunc(pflag.CommandLine.GetNormalizeFunc())
|
||||
if nfs.NormalizeNameFunc != nil {
|
||||
flagSet.SetNormalizeFunc(nfs.NormalizeNameFunc)
|
||||
}
|
||||
nfs.FlagSets[name] = flagSet
|
||||
nfs.Order = append(nfs.Order, name)
|
||||
}
|
||||
return nfs.FlagSets[name]
|
||||
|
||||
59
vendor/k8s.io/component-base/cli/flag/string_slice_flag.go
generated
vendored
Normal file
59
vendor/k8s.io/component-base/cli/flag/string_slice_flag.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flag
|
||||
|
||||
import (
|
||||
goflag "flag"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// StringSlice implements goflag.Value and plfag.Value,
|
||||
// and allows set to be invoked repeatedly to accumulate values.
|
||||
type StringSlice struct {
|
||||
value *[]string
|
||||
changed bool
|
||||
}
|
||||
|
||||
func NewStringSlice(s *[]string) *StringSlice {
|
||||
return &StringSlice{value: s}
|
||||
}
|
||||
|
||||
var _ goflag.Value = &StringSlice{}
|
||||
var _ pflag.Value = &StringSlice{}
|
||||
|
||||
func (s *StringSlice) String() string {
|
||||
if s == nil || s.value == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.Join(*s.value, " ")
|
||||
}
|
||||
|
||||
func (s *StringSlice) Set(val string) error {
|
||||
if s.value == nil || !s.changed {
|
||||
v := make([]string, 0)
|
||||
s.value = &v
|
||||
}
|
||||
*s.value = append(*s.value, val)
|
||||
s.changed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (StringSlice) Type() string {
|
||||
return "sliceString"
|
||||
}
|
||||
14
vendor/k8s.io/component-base/config/OWNERS
generated
vendored
Normal file
14
vendor/k8s.io/component-base/config/OWNERS
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
# Disable inheritance as this is an api owners file
|
||||
options:
|
||||
no_parent_owners: true
|
||||
approvers:
|
||||
- api-approvers
|
||||
reviewers:
|
||||
- api-reviewers
|
||||
- luxas
|
||||
- mtaufen
|
||||
- sttts
|
||||
labels:
|
||||
- kind/api-change
|
||||
19
vendor/k8s.io/component-base/config/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/component-base/config/doc.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// +k8s:deepcopy-gen=package
|
||||
|
||||
package config // import "k8s.io/component-base/config"
|
||||
91
vendor/k8s.io/component-base/config/types.go
generated
vendored
Normal file
91
vendor/k8s.io/component-base/config/types.go
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// ClientConnectionConfiguration contains details for constructing a client.
|
||||
type ClientConnectionConfiguration struct {
|
||||
// kubeconfig is the path to a KubeConfig file.
|
||||
Kubeconfig string
|
||||
// acceptContentTypes defines the Accept header sent by clients when connecting to a server, overriding the
|
||||
// default value of 'application/json'. This field will control all connections to the server used by a particular
|
||||
// client.
|
||||
AcceptContentTypes string
|
||||
// contentType is the content type used when sending data to the server from this client.
|
||||
ContentType string
|
||||
// qps controls the number of queries per second allowed for this connection.
|
||||
QPS float32
|
||||
// burst allows extra queries to accumulate when a client is exceeding its rate.
|
||||
Burst int32
|
||||
}
|
||||
|
||||
// LeaderElectionConfiguration defines the configuration of leader election
|
||||
// clients for components that can run with leader election enabled.
|
||||
type LeaderElectionConfiguration struct {
|
||||
// leaderElect enables a leader election client to gain leadership
|
||||
// before executing the main loop. Enable this when running replicated
|
||||
// components for high availability.
|
||||
LeaderElect bool
|
||||
// leaseDuration is the duration that non-leader candidates will wait
|
||||
// after observing a leadership renewal until attempting to acquire
|
||||
// leadership of a led but unrenewed leader slot. This is effectively the
|
||||
// maximum duration that a leader can be stopped before it is replaced
|
||||
// by another candidate. This is only applicable if leader election is
|
||||
// enabled.
|
||||
LeaseDuration metav1.Duration
|
||||
// renewDeadline is the interval between attempts by the acting master to
|
||||
// renew a leadership slot before it stops leading. This must be less
|
||||
// than or equal to the lease duration. This is only applicable if leader
|
||||
// election is enabled.
|
||||
RenewDeadline metav1.Duration
|
||||
// retryPeriod is the duration the clients should wait between attempting
|
||||
// acquisition and renewal of a leadership. This is only applicable if
|
||||
// leader election is enabled.
|
||||
RetryPeriod metav1.Duration
|
||||
// resourceLock indicates the resource object type that will be used to lock
|
||||
// during leader election cycles.
|
||||
ResourceLock string
|
||||
// resourceName indicates the name of resource object that will be used to lock
|
||||
// during leader election cycles.
|
||||
ResourceName string
|
||||
// resourceNamespace indicates the namespace of resource object that will be used to lock
|
||||
// during leader election cycles.
|
||||
ResourceNamespace string
|
||||
}
|
||||
|
||||
// DebuggingConfiguration holds configuration for Debugging related features.
|
||||
type DebuggingConfiguration struct {
|
||||
// enableProfiling enables profiling via web interface host:port/debug/pprof/
|
||||
EnableProfiling bool
|
||||
// enableContentionProfiling enables lock contention profiling, if
|
||||
// enableProfiling is true.
|
||||
EnableContentionProfiling bool
|
||||
}
|
||||
|
||||
// LoggingConfiguration contains logging options
|
||||
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information.
|
||||
type LoggingConfiguration struct {
|
||||
// Format Flag specifies the structure of log messages.
|
||||
// default value of format is `text`
|
||||
Format string
|
||||
// [Experimental] When enabled prevents logging of fields tagged as sensitive (passwords, keys, tokens).
|
||||
// Runtime log sanitization may introduce significant computation overhead and therefore should not be enabled in production.`)
|
||||
Sanitization bool
|
||||
}
|
||||
61
vendor/k8s.io/component-base/config/v1alpha1/conversion.go
generated
vendored
Normal file
61
vendor/k8s.io/component-base/config/v1alpha1/conversion.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/component-base/config"
|
||||
)
|
||||
|
||||
// Important! The public back-and-forth conversion functions for the types in this generic
|
||||
// package with ComponentConfig types need to be manually exposed like this in order for
|
||||
// other packages that reference this package to be able to call these conversion functions
|
||||
// in an autogenerated manner.
|
||||
// TODO: Fix the bug in conversion-gen so it automatically discovers these Convert_* functions
|
||||
// in autogenerated code as well.
|
||||
|
||||
func Convert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(in *ClientConnectionConfiguration, out *config.ClientConnectionConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(in, out, s)
|
||||
}
|
||||
|
||||
func Convert_config_ClientConnectionConfiguration_To_v1alpha1_ClientConnectionConfiguration(in *config.ClientConnectionConfiguration, out *ClientConnectionConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_config_ClientConnectionConfiguration_To_v1alpha1_ClientConnectionConfiguration(in, out, s)
|
||||
}
|
||||
|
||||
func Convert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(in *DebuggingConfiguration, out *config.DebuggingConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(in, out, s)
|
||||
}
|
||||
|
||||
func Convert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(in *config.DebuggingConfiguration, out *DebuggingConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(in, out, s)
|
||||
}
|
||||
|
||||
func Convert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionConfiguration(in *LeaderElectionConfiguration, out *config.LeaderElectionConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionConfiguration(in, out, s)
|
||||
}
|
||||
|
||||
func Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(in *config.LeaderElectionConfiguration, out *LeaderElectionConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(in, out, s)
|
||||
}
|
||||
|
||||
func Convert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in *LoggingConfiguration, out *config.LoggingConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in, out, s)
|
||||
}
|
||||
|
||||
func Convert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in *config.LoggingConfiguration, out *LoggingConfiguration, s conversion.Scope) error {
|
||||
return autoConvert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in, out, s)
|
||||
}
|
||||
113
vendor/k8s.io/component-base/config/v1alpha1/defaults.go
generated
vendored
Normal file
113
vendor/k8s.io/component-base/config/v1alpha1/defaults.go
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
// RecommendedDefaultLeaderElectionConfiguration defaults a pointer to a
|
||||
// LeaderElectionConfiguration struct. This will set the recommended default
|
||||
// values, but they may be subject to change between API versions. This function
|
||||
// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
|
||||
// function to allow consumers of this type to set whatever defaults for their
|
||||
// embedded configs. Forcing consumers to use these defaults would be problematic
|
||||
// as defaulting in the scheme is done as part of the conversion, and there would
|
||||
// be no easy way to opt-out. Instead, if you want to use this defaulting method
|
||||
// run it in your wrapper struct of this type in its `SetDefaults_` method.
|
||||
func RecommendedDefaultLeaderElectionConfiguration(obj *LeaderElectionConfiguration) {
|
||||
zero := metav1.Duration{}
|
||||
if obj.LeaseDuration == zero {
|
||||
obj.LeaseDuration = metav1.Duration{Duration: 15 * time.Second}
|
||||
}
|
||||
if obj.RenewDeadline == zero {
|
||||
obj.RenewDeadline = metav1.Duration{Duration: 10 * time.Second}
|
||||
}
|
||||
if obj.RetryPeriod == zero {
|
||||
obj.RetryPeriod = metav1.Duration{Duration: 2 * time.Second}
|
||||
}
|
||||
if obj.ResourceLock == "" {
|
||||
// TODO(#80289): Figure out how to migrate to LeaseLock at this point.
|
||||
// This will most probably require going through EndpointsLease first.
|
||||
obj.ResourceLock = EndpointsResourceLock
|
||||
}
|
||||
if obj.LeaderElect == nil {
|
||||
obj.LeaderElect = utilpointer.BoolPtr(true)
|
||||
}
|
||||
}
|
||||
|
||||
// RecommendedDefaultClientConnectionConfiguration defaults a pointer to a
|
||||
// ClientConnectionConfiguration struct. This will set the recommended default
|
||||
// values, but they may be subject to change between API versions. This function
|
||||
// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
|
||||
// function to allow consumers of this type to set whatever defaults for their
|
||||
// embedded configs. Forcing consumers to use these defaults would be problematic
|
||||
// as defaulting in the scheme is done as part of the conversion, and there would
|
||||
// be no easy way to opt-out. Instead, if you want to use this defaulting method
|
||||
// run it in your wrapper struct of this type in its `SetDefaults_` method.
|
||||
func RecommendedDefaultClientConnectionConfiguration(obj *ClientConnectionConfiguration) {
|
||||
if len(obj.ContentType) == 0 {
|
||||
obj.ContentType = "application/vnd.kubernetes.protobuf"
|
||||
}
|
||||
if obj.QPS == 0.0 {
|
||||
obj.QPS = 50.0
|
||||
}
|
||||
if obj.Burst == 0 {
|
||||
obj.Burst = 100
|
||||
}
|
||||
}
|
||||
|
||||
// RecommendedDebuggingConfiguration defaults profiling and debugging configuration.
|
||||
// This will set the recommended default
|
||||
// values, but they may be subject to change between API versions. This function
|
||||
// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
|
||||
// function to allow consumers of this type to set whatever defaults for their
|
||||
// embedded configs. Forcing consumers to use these defaults would be problematic
|
||||
// as defaulting in the scheme is done as part of the conversion, and there would
|
||||
// be no easy way to opt-out. Instead, if you want to use this defaulting method
|
||||
// run it in your wrapper struct of this type in its `SetDefaults_` method.
|
||||
func RecommendedDebuggingConfiguration(obj *DebuggingConfiguration) {
|
||||
if obj.EnableProfiling == nil {
|
||||
obj.EnableProfiling = utilpointer.BoolPtr(true) // profile debugging is cheap to have exposed and standard on kube binaries
|
||||
}
|
||||
}
|
||||
|
||||
// NewRecommendedDebuggingConfiguration returns the current recommended DebuggingConfiguration.
|
||||
// This may change between releases as recommendations shift.
|
||||
func NewRecommendedDebuggingConfiguration() *DebuggingConfiguration {
|
||||
ret := &DebuggingConfiguration{}
|
||||
RecommendedDebuggingConfiguration(ret)
|
||||
return ret
|
||||
}
|
||||
|
||||
// RecommendedLoggingConfiguration defaults logging configuration.
|
||||
// This will set the recommended default
|
||||
// values, but they may be subject to change between API versions. This function
|
||||
// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
|
||||
// function to allow consumers of this type to set whatever defaults for their
|
||||
// embedded configs. Forcing consumers to use these defaults would be problematic
|
||||
// as defaulting in the scheme is done as part of the conversion, and there would
|
||||
// be no easy way to opt-out. Instead, if you want to use this defaulting method
|
||||
// run it in your wrapper struct of this type in its `SetDefaults_` method.
|
||||
func RecommendedLoggingConfiguration(obj *LoggingConfiguration) {
|
||||
if obj.Format == "" {
|
||||
obj.Format = "text"
|
||||
}
|
||||
}
|
||||
20
vendor/k8s.io/component-base/config/v1alpha1/doc.go
generated
vendored
Normal file
20
vendor/k8s.io/component-base/config/v1alpha1/doc.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// +k8s:deepcopy-gen=package
|
||||
// +k8s:conversion-gen=k8s.io/component-base/config
|
||||
|
||||
package v1alpha1 // import "k8s.io/component-base/config/v1alpha1"
|
||||
31
vendor/k8s.io/component-base/config/v1alpha1/register.go
generated
vendored
Normal file
31
vendor/k8s.io/component-base/config/v1alpha1/register.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
var (
|
||||
// SchemeBuilder is the scheme builder with scheme init functions to run for this API package
|
||||
SchemeBuilder runtime.SchemeBuilder
|
||||
// localSchemeBuilder extends the SchemeBuilder instance with the external types. In this package,
|
||||
// defaulting and conversion init funcs are registered as well.
|
||||
localSchemeBuilder = &SchemeBuilder
|
||||
// AddToScheme is a global function that registers this API group & version to a scheme
|
||||
AddToScheme = localSchemeBuilder.AddToScheme
|
||||
)
|
||||
93
vendor/k8s.io/component-base/config/v1alpha1/types.go
generated
vendored
Normal file
93
vendor/k8s.io/component-base/config/v1alpha1/types.go
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const EndpointsResourceLock = "endpoints"
|
||||
|
||||
// LeaderElectionConfiguration defines the configuration of leader election
|
||||
// clients for components that can run with leader election enabled.
|
||||
type LeaderElectionConfiguration struct {
|
||||
// leaderElect enables a leader election client to gain leadership
|
||||
// before executing the main loop. Enable this when running replicated
|
||||
// components for high availability.
|
||||
LeaderElect *bool `json:"leaderElect"`
|
||||
// leaseDuration is the duration that non-leader candidates will wait
|
||||
// after observing a leadership renewal until attempting to acquire
|
||||
// leadership of a led but unrenewed leader slot. This is effectively the
|
||||
// maximum duration that a leader can be stopped before it is replaced
|
||||
// by another candidate. This is only applicable if leader election is
|
||||
// enabled.
|
||||
LeaseDuration metav1.Duration `json:"leaseDuration"`
|
||||
// renewDeadline is the interval between attempts by the acting master to
|
||||
// renew a leadership slot before it stops leading. This must be less
|
||||
// than or equal to the lease duration. This is only applicable if leader
|
||||
// election is enabled.
|
||||
RenewDeadline metav1.Duration `json:"renewDeadline"`
|
||||
// retryPeriod is the duration the clients should wait between attempting
|
||||
// acquisition and renewal of a leadership. This is only applicable if
|
||||
// leader election is enabled.
|
||||
RetryPeriod metav1.Duration `json:"retryPeriod"`
|
||||
// resourceLock indicates the resource object type that will be used to lock
|
||||
// during leader election cycles.
|
||||
ResourceLock string `json:"resourceLock"`
|
||||
// resourceName indicates the name of resource object that will be used to lock
|
||||
// during leader election cycles.
|
||||
ResourceName string `json:"resourceName"`
|
||||
// resourceName indicates the namespace of resource object that will be used to lock
|
||||
// during leader election cycles.
|
||||
ResourceNamespace string `json:"resourceNamespace"`
|
||||
}
|
||||
|
||||
// DebuggingConfiguration holds configuration for Debugging related features.
|
||||
type DebuggingConfiguration struct {
|
||||
// enableProfiling enables profiling via web interface host:port/debug/pprof/
|
||||
EnableProfiling *bool `json:"enableProfiling,omitempty"`
|
||||
// enableContentionProfiling enables lock contention profiling, if
|
||||
// enableProfiling is true.
|
||||
EnableContentionProfiling *bool `json:"enableContentionProfiling,omitempty"`
|
||||
}
|
||||
|
||||
// ClientConnectionConfiguration contains details for constructing a client.
|
||||
type ClientConnectionConfiguration struct {
|
||||
// kubeconfig is the path to a KubeConfig file.
|
||||
Kubeconfig string `json:"kubeconfig"`
|
||||
// acceptContentTypes defines the Accept header sent by clients when connecting to a server, overriding the
|
||||
// default value of 'application/json'. This field will control all connections to the server used by a particular
|
||||
// client.
|
||||
AcceptContentTypes string `json:"acceptContentTypes"`
|
||||
// contentType is the content type used when sending data to the server from this client.
|
||||
ContentType string `json:"contentType"`
|
||||
// qps controls the number of queries per second allowed for this connection.
|
||||
QPS float32 `json:"qps"`
|
||||
// burst allows extra queries to accumulate when a client is exceeding its rate.
|
||||
Burst int32 `json:"burst"`
|
||||
}
|
||||
|
||||
// LoggingConfiguration contains logging options
|
||||
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information.
|
||||
type LoggingConfiguration struct {
|
||||
// Format Flag specifies the structure of log messages.
|
||||
// default value of format is `text`
|
||||
Format string `json:"format,omitempty"`
|
||||
// [Experimental] When enabled prevents logging of fields tagged as sensitive (passwords, keys, tokens).
|
||||
// Runtime log sanitization may introduce significant computation overhead and therefore should not be enabled in production.`)
|
||||
Sanitization bool `json:"sanitization,omitempty"`
|
||||
}
|
||||
154
vendor/k8s.io/component-base/config/v1alpha1/zz_generated.conversion.go
generated
vendored
Normal file
154
vendor/k8s.io/component-base/config/v1alpha1/zz_generated.conversion.go
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by conversion-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
config "k8s.io/component-base/config"
|
||||
)
|
||||
|
||||
func init() {
|
||||
localSchemeBuilder.Register(RegisterConversions)
|
||||
}
|
||||
|
||||
// RegisterConversions adds conversion functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
func RegisterConversions(s *runtime.Scheme) error {
|
||||
if err := s.AddConversionFunc((*config.ClientConnectionConfiguration)(nil), (*ClientConnectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_config_ClientConnectionConfiguration_To_v1alpha1_ClientConnectionConfiguration(a.(*config.ClientConnectionConfiguration), b.(*ClientConnectionConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*config.DebuggingConfiguration)(nil), (*DebuggingConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(a.(*config.DebuggingConfiguration), b.(*DebuggingConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*config.LeaderElectionConfiguration)(nil), (*LeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(a.(*config.LeaderElectionConfiguration), b.(*LeaderElectionConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*config.LoggingConfiguration)(nil), (*LoggingConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(a.(*config.LoggingConfiguration), b.(*LoggingConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*ClientConnectionConfiguration)(nil), (*config.ClientConnectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(a.(*ClientConnectionConfiguration), b.(*config.ClientConnectionConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*DebuggingConfiguration)(nil), (*config.DebuggingConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(a.(*DebuggingConfiguration), b.(*config.DebuggingConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*LeaderElectionConfiguration)(nil), (*config.LeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionConfiguration(a.(*LeaderElectionConfiguration), b.(*config.LeaderElectionConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*LoggingConfiguration)(nil), (*config.LoggingConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(a.(*LoggingConfiguration), b.(*config.LoggingConfiguration), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(in *ClientConnectionConfiguration, out *config.ClientConnectionConfiguration, s conversion.Scope) error {
|
||||
out.Kubeconfig = in.Kubeconfig
|
||||
out.AcceptContentTypes = in.AcceptContentTypes
|
||||
out.ContentType = in.ContentType
|
||||
out.QPS = in.QPS
|
||||
out.Burst = in.Burst
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_config_ClientConnectionConfiguration_To_v1alpha1_ClientConnectionConfiguration(in *config.ClientConnectionConfiguration, out *ClientConnectionConfiguration, s conversion.Scope) error {
|
||||
out.Kubeconfig = in.Kubeconfig
|
||||
out.AcceptContentTypes = in.AcceptContentTypes
|
||||
out.ContentType = in.ContentType
|
||||
out.QPS = in.QPS
|
||||
out.Burst = in.Burst
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(in *DebuggingConfiguration, out *config.DebuggingConfiguration, s conversion.Scope) error {
|
||||
if err := v1.Convert_Pointer_bool_To_bool(&in.EnableProfiling, &out.EnableProfiling, s); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v1.Convert_Pointer_bool_To_bool(&in.EnableContentionProfiling, &out.EnableContentionProfiling, s); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(in *config.DebuggingConfiguration, out *DebuggingConfiguration, s conversion.Scope) error {
|
||||
if err := v1.Convert_bool_To_Pointer_bool(&in.EnableProfiling, &out.EnableProfiling, s); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v1.Convert_bool_To_Pointer_bool(&in.EnableContentionProfiling, &out.EnableContentionProfiling, s); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionConfiguration(in *LeaderElectionConfiguration, out *config.LeaderElectionConfiguration, s conversion.Scope) error {
|
||||
if err := v1.Convert_Pointer_bool_To_bool(&in.LeaderElect, &out.LeaderElect, s); err != nil {
|
||||
return err
|
||||
}
|
||||
out.LeaseDuration = in.LeaseDuration
|
||||
out.RenewDeadline = in.RenewDeadline
|
||||
out.RetryPeriod = in.RetryPeriod
|
||||
out.ResourceLock = in.ResourceLock
|
||||
out.ResourceName = in.ResourceName
|
||||
out.ResourceNamespace = in.ResourceNamespace
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(in *config.LeaderElectionConfiguration, out *LeaderElectionConfiguration, s conversion.Scope) error {
|
||||
if err := v1.Convert_bool_To_Pointer_bool(&in.LeaderElect, &out.LeaderElect, s); err != nil {
|
||||
return err
|
||||
}
|
||||
out.LeaseDuration = in.LeaseDuration
|
||||
out.RenewDeadline = in.RenewDeadline
|
||||
out.RetryPeriod = in.RetryPeriod
|
||||
out.ResourceLock = in.ResourceLock
|
||||
out.ResourceName = in.ResourceName
|
||||
out.ResourceNamespace = in.ResourceNamespace
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in *LoggingConfiguration, out *config.LoggingConfiguration, s conversion.Scope) error {
|
||||
out.Format = in.Format
|
||||
out.Sanitization = in.Sanitization
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in *config.LoggingConfiguration, out *LoggingConfiguration, s conversion.Scope) error {
|
||||
out.Format = in.Format
|
||||
out.Sanitization = in.Sanitization
|
||||
return nil
|
||||
}
|
||||
103
vendor/k8s.io/component-base/config/v1alpha1/zz_generated.deepcopy.go
generated
vendored
Normal file
103
vendor/k8s.io/component-base/config/v1alpha1/zz_generated.deepcopy.go
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClientConnectionConfiguration) DeepCopyInto(out *ClientConnectionConfiguration) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClientConnectionConfiguration.
|
||||
func (in *ClientConnectionConfiguration) DeepCopy() *ClientConnectionConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ClientConnectionConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *DebuggingConfiguration) DeepCopyInto(out *DebuggingConfiguration) {
|
||||
*out = *in
|
||||
if in.EnableProfiling != nil {
|
||||
in, out := &in.EnableProfiling, &out.EnableProfiling
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
if in.EnableContentionProfiling != nil {
|
||||
in, out := &in.EnableContentionProfiling, &out.EnableContentionProfiling
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DebuggingConfiguration.
|
||||
func (in *DebuggingConfiguration) DeepCopy() *DebuggingConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(DebuggingConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *LeaderElectionConfiguration) DeepCopyInto(out *LeaderElectionConfiguration) {
|
||||
*out = *in
|
||||
if in.LeaderElect != nil {
|
||||
in, out := &in.LeaderElect, &out.LeaderElect
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
out.LeaseDuration = in.LeaseDuration
|
||||
out.RenewDeadline = in.RenewDeadline
|
||||
out.RetryPeriod = in.RetryPeriod
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeaderElectionConfiguration.
|
||||
func (in *LeaderElectionConfiguration) DeepCopy() *LeaderElectionConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(LeaderElectionConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *LoggingConfiguration) DeepCopyInto(out *LoggingConfiguration) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfiguration.
|
||||
func (in *LoggingConfiguration) DeepCopy() *LoggingConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(LoggingConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
88
vendor/k8s.io/component-base/config/zz_generated.deepcopy.go
generated
vendored
Normal file
88
vendor/k8s.io/component-base/config/zz_generated.deepcopy.go
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
||||
|
||||
package config
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClientConnectionConfiguration) DeepCopyInto(out *ClientConnectionConfiguration) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClientConnectionConfiguration.
|
||||
func (in *ClientConnectionConfiguration) DeepCopy() *ClientConnectionConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ClientConnectionConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *DebuggingConfiguration) DeepCopyInto(out *DebuggingConfiguration) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DebuggingConfiguration.
|
||||
func (in *DebuggingConfiguration) DeepCopy() *DebuggingConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(DebuggingConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *LeaderElectionConfiguration) DeepCopyInto(out *LeaderElectionConfiguration) {
|
||||
*out = *in
|
||||
out.LeaseDuration = in.LeaseDuration
|
||||
out.RenewDeadline = in.RenewDeadline
|
||||
out.RetryPeriod = in.RetryPeriod
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeaderElectionConfiguration.
|
||||
func (in *LeaderElectionConfiguration) DeepCopy() *LeaderElectionConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(LeaderElectionConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *LoggingConfiguration) DeepCopyInto(out *LoggingConfiguration) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfiguration.
|
||||
func (in *LoggingConfiguration) DeepCopy() *LoggingConfiguration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(LoggingConfiguration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
2
vendor/k8s.io/component-base/featuregate/feature_gate.go
generated
vendored
2
vendor/k8s.io/component-base/featuregate/feature_gate.go
generated
vendored
@@ -27,7 +27,7 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/naming"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type Feature string
|
||||
|
||||
8
vendor/k8s.io/component-base/logs/OWNERS
generated
vendored
Normal file
8
vendor/k8s.io/component-base/logs/OWNERS
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
approvers:
|
||||
- sig-instrumentation-approvers
|
||||
reviewers:
|
||||
- sig-instrumentation-reviewers
|
||||
labels:
|
||||
- sig/instrumentation
|
||||
99
vendor/k8s.io/component-base/logs/datapol/datapol.go
generated
vendored
Normal file
99
vendor/k8s.io/component-base/logs/datapol/datapol.go
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package datapol contains functions to determine if objects contain sensitive
|
||||
// data to e.g. make decisions on whether to log them or not.
|
||||
package datapol
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// Verify returns a list of the datatypes contained in the argument that can be
|
||||
// considered sensitive w.r.t. to logging
|
||||
func Verify(value interface{}) []string {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
//TODO maybe export a metric
|
||||
klog.Warningf("Error while inspecting arguments for sensitive data: %v", r)
|
||||
}
|
||||
}()
|
||||
t := reflect.ValueOf(value)
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
return datatypes(t)
|
||||
}
|
||||
|
||||
func datatypes(v reflect.Value) []string {
|
||||
if types := byType(v.Type()); len(types) > 0 {
|
||||
// Slices, and maps can be nil or empty, only the nil case is zero
|
||||
switch v.Kind() {
|
||||
case reflect.Slice, reflect.Map:
|
||||
if !v.IsZero() && v.Len() > 0 {
|
||||
return types
|
||||
}
|
||||
default:
|
||||
if !v.IsZero() {
|
||||
return types
|
||||
}
|
||||
}
|
||||
}
|
||||
switch v.Kind() {
|
||||
case reflect.Interface:
|
||||
return datatypes(v.Elem())
|
||||
case reflect.Slice, reflect.Array:
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
if types := datatypes(v.Index(i)); len(types) > 0 {
|
||||
return types
|
||||
}
|
||||
}
|
||||
case reflect.Map:
|
||||
mapIter := v.MapRange()
|
||||
for mapIter.Next() {
|
||||
k := mapIter.Key()
|
||||
v := mapIter.Value()
|
||||
if types := datatypes(k); len(types) > 0 {
|
||||
return types
|
||||
}
|
||||
if types := datatypes(v); len(types) > 0 {
|
||||
return types
|
||||
}
|
||||
}
|
||||
case reflect.Struct:
|
||||
t := v.Type()
|
||||
numField := t.NumField()
|
||||
|
||||
for i := 0; i < numField; i++ {
|
||||
f := t.Field(i)
|
||||
if f.Type.Kind() == reflect.Ptr {
|
||||
continue
|
||||
}
|
||||
if reason, ok := f.Tag.Lookup("datapolicy"); ok {
|
||||
if !v.Field(i).IsZero() {
|
||||
return strings.Split(reason, ",")
|
||||
}
|
||||
}
|
||||
if types := datatypes(v.Field(i)); len(types) > 0 {
|
||||
return types
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
49
vendor/k8s.io/component-base/logs/datapol/externaltypes.go
generated
vendored
Normal file
49
vendor/k8s.io/component-base/logs/datapol/externaltypes.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package datapol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
httpHeader = "net/http.Header"
|
||||
httpCookie = "net/http.Cookie"
|
||||
x509Certificate = "crypto/x509.Certificate"
|
||||
)
|
||||
|
||||
// GlobalDatapolicyMapping returns the list of sensitive datatypes are embedded
|
||||
// in types not native to Kubernetes.
|
||||
func GlobalDatapolicyMapping(v interface{}) []string {
|
||||
return byType(reflect.TypeOf(v))
|
||||
}
|
||||
|
||||
func byType(t reflect.Type) []string {
|
||||
// Use string representation of the type to prevent taking a depency on the actual type.
|
||||
switch fmt.Sprintf("%s.%s", t.PkgPath(), t.Name()) {
|
||||
case httpHeader:
|
||||
return []string{"password", "token"}
|
||||
case httpCookie:
|
||||
return []string{"token"}
|
||||
case x509Certificate:
|
||||
return []string{"security-key"}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
178
vendor/k8s.io/component-base/logs/json/json.go
generated
vendored
Normal file
178
vendor/k8s.io/component-base/logs/json/json.go
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package logs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// Inspired from https://github.com/go-logr/zapr, some functions is copy from the repo.
|
||||
|
||||
var (
|
||||
// JSONLogger is global json log format logr
|
||||
JSONLogger logr.Logger
|
||||
|
||||
// timeNow stubbed out for testing
|
||||
timeNow = time.Now
|
||||
)
|
||||
|
||||
// zapLogger is a logr.Logger that uses Zap to record log.
|
||||
type zapLogger struct {
|
||||
// NB: this looks very similar to zap.SugaredLogger, but
|
||||
// deals with our desire to have multiple verbosity levels.
|
||||
l *zap.Logger
|
||||
lvl int
|
||||
}
|
||||
|
||||
// implement logr.Logger
|
||||
var _ logr.Logger = &zapLogger{}
|
||||
|
||||
// Enabled should always return true
|
||||
func (l *zapLogger) Enabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Info write message to error level log
|
||||
func (l *zapLogger) Info(msg string, keysAndVals ...interface{}) {
|
||||
entry := zapcore.Entry{
|
||||
Time: timeNow(),
|
||||
Message: msg,
|
||||
}
|
||||
checkedEntry := l.l.Core().Check(entry, nil)
|
||||
checkedEntry.Write(l.handleFields(keysAndVals)...)
|
||||
}
|
||||
|
||||
// dPanic write message to DPanicLevel level log
|
||||
// we need implement this because unit test case need stub time.Now
|
||||
// otherwise the ts field always changed
|
||||
func (l *zapLogger) dPanic(msg string) {
|
||||
entry := zapcore.Entry{
|
||||
Level: zapcore.DPanicLevel,
|
||||
Time: timeNow(),
|
||||
Message: msg,
|
||||
}
|
||||
checkedEntry := l.l.Core().Check(entry, nil)
|
||||
checkedEntry.Write(zap.Int("v", l.lvl))
|
||||
}
|
||||
|
||||
// handleFields converts a bunch of arbitrary key-value pairs into Zap fields. It takes
|
||||
// additional pre-converted Zap fields, for use with automatically attached fields, like
|
||||
// `error`.
|
||||
func (l *zapLogger) handleFields(args []interface{}, additional ...zap.Field) []zap.Field {
|
||||
// a slightly modified version of zap.SugaredLogger.sweetenFields
|
||||
if len(args) == 0 {
|
||||
// fast-return if we have no suggared fields.
|
||||
return append(additional, zap.Int("v", l.lvl))
|
||||
}
|
||||
|
||||
// unlike Zap, we can be pretty sure users aren't passing structured
|
||||
// fields (since logr has no concept of that), so guess that we need a
|
||||
// little less space.
|
||||
fields := make([]zap.Field, 0, len(args)/2+len(additional)+1)
|
||||
fields = append(fields, zap.Int("v", l.lvl))
|
||||
for i := 0; i < len(args)-1; i += 2 {
|
||||
// check just in case for strongly-typed Zap fields, which is illegal (since
|
||||
// it breaks implementation agnosticism), so we can give a better error message.
|
||||
if _, ok := args[i].(zap.Field); ok {
|
||||
l.dPanic("strongly-typed Zap Field passed to logr")
|
||||
break
|
||||
}
|
||||
|
||||
// process a key-value pair,
|
||||
// ensuring that the key is a string
|
||||
key, val := args[i], args[i+1]
|
||||
keyStr, isString := key.(string)
|
||||
if !isString {
|
||||
// if the key isn't a string, stop logging
|
||||
l.dPanic("non-string key argument passed to logging, ignoring all later arguments")
|
||||
break
|
||||
}
|
||||
|
||||
fields = append(fields, zap.Any(keyStr, val))
|
||||
}
|
||||
|
||||
return append(fields, additional...)
|
||||
}
|
||||
|
||||
// Error write log message to error level
|
||||
func (l *zapLogger) Error(err error, msg string, keysAndVals ...interface{}) {
|
||||
entry := zapcore.Entry{
|
||||
Level: zapcore.ErrorLevel,
|
||||
Time: timeNow(),
|
||||
Message: msg,
|
||||
}
|
||||
checkedEntry := l.l.Core().Check(entry, nil)
|
||||
checkedEntry.Write(l.handleFields(keysAndVals, handleError(err))...)
|
||||
}
|
||||
|
||||
// V return info logr.Logger with specified level
|
||||
func (l *zapLogger) V(level int) logr.Logger {
|
||||
return &zapLogger{
|
||||
lvl: l.lvl + level,
|
||||
l: l.l,
|
||||
}
|
||||
}
|
||||
|
||||
// WithValues return logr.Logger with some keys And Values
|
||||
func (l *zapLogger) WithValues(keysAndValues ...interface{}) logr.Logger {
|
||||
l.l = l.l.With(l.handleFields(keysAndValues)...)
|
||||
return l
|
||||
}
|
||||
|
||||
// WithName return logger Named with specified name
|
||||
func (l *zapLogger) WithName(name string) logr.Logger {
|
||||
l.l = l.l.Named(name)
|
||||
return l
|
||||
}
|
||||
|
||||
// encoderConfig config zap encodetime format
|
||||
var encoderConfig = zapcore.EncoderConfig{
|
||||
MessageKey: "msg",
|
||||
|
||||
TimeKey: "ts",
|
||||
EncodeTime: zapcore.EpochMillisTimeEncoder,
|
||||
EncodeDuration: zapcore.StringDurationEncoder,
|
||||
}
|
||||
|
||||
// NewJSONLogger creates a new json logr.Logger using the given Zap Logger to log.
|
||||
func NewJSONLogger(w zapcore.WriteSyncer) logr.Logger {
|
||||
l, _ := zap.NewProduction()
|
||||
if w == nil {
|
||||
w = os.Stdout
|
||||
}
|
||||
log := l.WithOptions(zap.AddCallerSkip(1),
|
||||
zap.WrapCore(
|
||||
func(zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewCore(zapcore.NewJSONEncoder(encoderConfig), zapcore.AddSync(w), zapcore.DebugLevel)
|
||||
}))
|
||||
return &zapLogger{
|
||||
l: log,
|
||||
}
|
||||
}
|
||||
|
||||
func handleError(err error) zap.Field {
|
||||
return zap.NamedError("err", err)
|
||||
}
|
||||
|
||||
func init() {
|
||||
JSONLogger = NewJSONLogger(nil)
|
||||
}
|
||||
2
vendor/k8s.io/component-base/logs/logs.go
generated
vendored
2
vendor/k8s.io/component-base/logs/logs.go
generated
vendored
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
const logFlushFreqFlagName = "log-flush-frequency"
|
||||
|
||||
154
vendor/k8s.io/component-base/logs/options.go
generated
vendored
Normal file
154
vendor/k8s.io/component-base/logs/options.go
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package logs
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/component-base/logs/sanitization"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
logFormatFlagName = "logging-format"
|
||||
defaultLogFormat = "text"
|
||||
)
|
||||
|
||||
// List of logs (k8s.io/klog + k8s.io/component-base/logs) flags supported by all logging formats
|
||||
var supportedLogsFlags = map[string]struct{}{
|
||||
"v": {},
|
||||
// TODO: support vmodule after 1.19 Alpha
|
||||
}
|
||||
|
||||
// Options has klog format parameters
|
||||
type Options struct {
|
||||
LogFormat string
|
||||
LogSanitization bool
|
||||
}
|
||||
|
||||
// NewOptions return new klog options
|
||||
func NewOptions() *Options {
|
||||
return &Options{
|
||||
LogFormat: defaultLogFormat,
|
||||
}
|
||||
}
|
||||
|
||||
// Validate verifies if any unsupported flag is set
|
||||
// for non-default logging format
|
||||
func (o *Options) Validate() []error {
|
||||
errs := []error{}
|
||||
if o.LogFormat != defaultLogFormat {
|
||||
allFlags := unsupportedLoggingFlags(hyphensToUnderscores)
|
||||
for _, fname := range allFlags {
|
||||
if flagIsSet(fname, hyphensToUnderscores) {
|
||||
errs = append(errs, fmt.Errorf("non-default logging format doesn't honor flag: %s", fname))
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, err := o.Get(); err != nil {
|
||||
errs = append(errs, fmt.Errorf("unsupported log format: %s", o.LogFormat))
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// hyphensToUnderscores replaces hyphens with underscores
|
||||
// we should always use underscores instead of hyphens when validate flags
|
||||
func hyphensToUnderscores(s string) string {
|
||||
return strings.Replace(s, "-", "_", -1)
|
||||
}
|
||||
|
||||
func flagIsSet(name string, normalizeFunc func(name string) string) bool {
|
||||
f := flag.Lookup(name)
|
||||
if f != nil {
|
||||
return f.DefValue != f.Value.String()
|
||||
}
|
||||
if normalizeFunc != nil {
|
||||
f = flag.Lookup(normalizeFunc(name))
|
||||
if f != nil {
|
||||
return f.DefValue != f.Value.String()
|
||||
}
|
||||
}
|
||||
pf := pflag.Lookup(name)
|
||||
if pf != nil {
|
||||
return pf.DefValue != pf.Value.String()
|
||||
}
|
||||
panic("failed to lookup unsupported log flag")
|
||||
}
|
||||
|
||||
// AddFlags add logging-format flag
|
||||
func (o *Options) AddFlags(fs *pflag.FlagSet) {
|
||||
normalizeFunc := func(name string) string {
|
||||
f := fs.GetNormalizeFunc()
|
||||
return string(f(fs, name))
|
||||
}
|
||||
|
||||
unsupportedFlags := fmt.Sprintf("--%s", strings.Join(unsupportedLoggingFlags(normalizeFunc), ", --"))
|
||||
formats := fmt.Sprintf(`"%s"`, strings.Join(logRegistry.List(), `", "`))
|
||||
fs.StringVar(&o.LogFormat, logFormatFlagName, defaultLogFormat, fmt.Sprintf("Sets the log format. Permitted formats: %s.\nNon-default formats don't honor these flags: %s.\nNon-default choices are currently alpha and subject to change without warning.", formats, unsupportedFlags))
|
||||
|
||||
// No new log formats should be added after generation is of flag options
|
||||
logRegistry.Freeze()
|
||||
fs.BoolVar(&o.LogSanitization, "experimental-logging-sanitization", o.LogSanitization, `[Experimental] When enabled prevents logging of fields tagged as sensitive (passwords, keys, tokens).
|
||||
Runtime log sanitization may introduce significant computation overhead and therefore should not be enabled in production.`)
|
||||
}
|
||||
|
||||
// Apply set klog logger from LogFormat type
|
||||
func (o *Options) Apply() {
|
||||
// if log format not exists, use nil loggr
|
||||
loggr, _ := o.Get()
|
||||
klog.SetLogger(loggr)
|
||||
if o.LogSanitization {
|
||||
klog.SetLogFilter(&sanitization.SanitizingFilter{})
|
||||
}
|
||||
}
|
||||
|
||||
// Get logger with LogFormat field
|
||||
func (o *Options) Get() (logr.Logger, error) {
|
||||
return logRegistry.Get(o.LogFormat)
|
||||
}
|
||||
|
||||
func unsupportedLoggingFlags(normalizeFunc func(name string) string) []string {
|
||||
allFlags := []string{}
|
||||
|
||||
// k8s.io/klog flags
|
||||
fs := &flag.FlagSet{}
|
||||
klog.InitFlags(fs)
|
||||
fs.VisitAll(func(flag *flag.Flag) {
|
||||
if _, found := supportedLogsFlags[flag.Name]; !found {
|
||||
name := flag.Name
|
||||
if normalizeFunc != nil {
|
||||
name = normalizeFunc(name)
|
||||
}
|
||||
allFlags = append(allFlags, name)
|
||||
}
|
||||
})
|
||||
|
||||
// k8s.io/component-base/logs flags
|
||||
pfs := &pflag.FlagSet{}
|
||||
AddFlags(pfs)
|
||||
pfs.VisitAll(func(flag *pflag.Flag) {
|
||||
if _, found := supportedLogsFlags[flag.Name]; !found {
|
||||
allFlags = append(allFlags, flag.Name)
|
||||
}
|
||||
})
|
||||
return allFlags
|
||||
}
|
||||
106
vendor/k8s.io/component-base/logs/registry.go
generated
vendored
Normal file
106
vendor/k8s.io/component-base/logs/registry.go
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package logs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
json "k8s.io/component-base/logs/json"
|
||||
)
|
||||
|
||||
const (
|
||||
jsonLogFormat = "json"
|
||||
)
|
||||
|
||||
var logRegistry = NewLogFormatRegistry()
|
||||
|
||||
// LogFormatRegistry store klog format registry
|
||||
type LogFormatRegistry struct {
|
||||
registry map[string]logr.Logger
|
||||
frozen bool
|
||||
}
|
||||
|
||||
// NewLogFormatRegistry return new init LogFormatRegistry struct
|
||||
func NewLogFormatRegistry() *LogFormatRegistry {
|
||||
return &LogFormatRegistry{
|
||||
registry: make(map[string]logr.Logger),
|
||||
frozen: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Register new log format registry to global logRegistry
|
||||
func (lfr *LogFormatRegistry) Register(name string, logger logr.Logger) error {
|
||||
if lfr.frozen {
|
||||
return fmt.Errorf("log format is frozen, unable to register log format")
|
||||
}
|
||||
if _, ok := lfr.registry[name]; ok {
|
||||
return fmt.Errorf("log format: %s already exists", name)
|
||||
}
|
||||
lfr.registry[name] = logger
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get specified log format logger
|
||||
func (lfr *LogFormatRegistry) Get(name string) (logr.Logger, error) {
|
||||
re, ok := lfr.registry[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("log format: %s does not exists", name)
|
||||
}
|
||||
return re, nil
|
||||
}
|
||||
|
||||
// Set specified log format logger
|
||||
func (lfr *LogFormatRegistry) Set(name string, logger logr.Logger) error {
|
||||
if lfr.frozen {
|
||||
return fmt.Errorf("log format is frozen, unable to set log format")
|
||||
}
|
||||
|
||||
lfr.registry[name] = logger
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete specified log format logger
|
||||
func (lfr *LogFormatRegistry) Delete(name string) error {
|
||||
if lfr.frozen {
|
||||
return fmt.Errorf("log format is frozen, unable to delete log format")
|
||||
}
|
||||
|
||||
delete(lfr.registry, name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// List names of registered log formats (sorted)
|
||||
func (lfr *LogFormatRegistry) List() []string {
|
||||
formats := make([]string, 0, len(lfr.registry))
|
||||
for f := range lfr.registry {
|
||||
formats = append(formats, f)
|
||||
}
|
||||
sort.Strings(formats)
|
||||
return formats
|
||||
}
|
||||
|
||||
// Freeze freezes the log format registry
|
||||
func (lfr *LogFormatRegistry) Freeze() {
|
||||
lfr.frozen = true
|
||||
}
|
||||
func init() {
|
||||
// Text format is default klog format
|
||||
logRegistry.Register(defaultLogFormat, nil)
|
||||
logRegistry.Register(jsonLogFormat, json.JSONLogger)
|
||||
}
|
||||
69
vendor/k8s.io/component-base/logs/sanitization/sanitization.go
generated
vendored
Normal file
69
vendor/k8s.io/component-base/logs/sanitization/sanitization.go
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package sanitization
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/component-base/logs/datapol"
|
||||
)
|
||||
|
||||
const (
|
||||
datapolMsgFmt = "Log message has been redacted. Log argument #%d contains: %v"
|
||||
datapolMsg = "Log message has been redacted."
|
||||
)
|
||||
|
||||
// SanitizingFilter implements the LogFilter interface from klog with a set of functions that inspects the arguments with the datapol library
|
||||
type SanitizingFilter struct{}
|
||||
|
||||
// Filter is the filter function for the non-formatting logging functions of klog.
|
||||
func (sf *SanitizingFilter) Filter(args []interface{}) []interface{} {
|
||||
for i, v := range args {
|
||||
types := datapol.Verify(v)
|
||||
if len(types) > 0 {
|
||||
return []interface{}{fmt.Sprintf(datapolMsgFmt, i, types)}
|
||||
}
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
// FilterF is the filter function for the formatting logging functions of klog
|
||||
func (sf *SanitizingFilter) FilterF(fmt string, args []interface{}) (string, []interface{}) {
|
||||
for i, v := range args {
|
||||
types := datapol.Verify(v)
|
||||
if len(types) > 0 {
|
||||
return datapolMsgFmt, []interface{}{i, types}
|
||||
}
|
||||
}
|
||||
return fmt, args
|
||||
|
||||
}
|
||||
|
||||
// FilterS is the filter for the structured logging functions of klog.
|
||||
func (sf *SanitizingFilter) FilterS(msg string, keysAndValues []interface{}) (string, []interface{}) {
|
||||
for i, v := range keysAndValues {
|
||||
types := datapol.Verify(v)
|
||||
if len(types) > 0 {
|
||||
if i%2 == 0 {
|
||||
return datapolMsg, []interface{}{"key_index", i, "types", types}
|
||||
}
|
||||
// since we scanned linearly we can safely log the key.
|
||||
return datapolMsg, []interface{}{"key", keysAndValues[i-1], "types", types}
|
||||
}
|
||||
}
|
||||
return msg, keysAndValues
|
||||
}
|
||||
1
vendor/k8s.io/component-base/metrics/OWNERS
generated
vendored
1
vendor/k8s.io/component-base/metrics/OWNERS
generated
vendored
@@ -6,5 +6,6 @@ approvers:
|
||||
- RainbowMango
|
||||
reviewers:
|
||||
- sig-instrumentation-reviewers
|
||||
- YoyinZyc
|
||||
labels:
|
||||
- sig/instrumentation
|
||||
|
||||
20
vendor/k8s.io/component-base/metrics/collector.go
generated
vendored
20
vendor/k8s.io/component-base/metrics/collector.go
generated
vendored
@@ -49,10 +49,10 @@ type StableCollector interface {
|
||||
// is a convenient assistant for custom collectors.
|
||||
// It is recommend that inherit BaseStableCollector when implementing custom collectors.
|
||||
type BaseStableCollector struct {
|
||||
descriptors map[string]*Desc // stores all descriptors by pair<fqName, Desc>, these are collected from DescribeWithStability().
|
||||
registrable map[string]*Desc // stores registrable descriptors by pair<fqName, Desc>, is a subset of descriptors.
|
||||
hidden map[string]*Desc // stores hidden descriptors by pair<fqName, Desc>, is a subset of descriptors.
|
||||
self StableCollector
|
||||
descriptors map[string]*Desc // stores all descriptors by pair<fqName, Desc>, these are collected from DescribeWithStability().
|
||||
registerable map[string]*Desc // stores registerable descriptors by pair<fqName, Desc>, is a subset of descriptors.
|
||||
hidden map[string]*Desc // stores hidden descriptors by pair<fqName, Desc>, is a subset of descriptors.
|
||||
self StableCollector
|
||||
}
|
||||
|
||||
// DescribeWithStability sends all descriptors to the provided channel.
|
||||
@@ -64,7 +64,7 @@ func (bsc *BaseStableCollector) DescribeWithStability(ch chan<- *Desc) {
|
||||
// Describe sends all descriptors to the provided channel.
|
||||
// It intend to be called by prometheus registry.
|
||||
func (bsc *BaseStableCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
for _, d := range bsc.registrable {
|
||||
for _, d := range bsc.registerable {
|
||||
ch <- d.toPrometheusDesc()
|
||||
}
|
||||
}
|
||||
@@ -128,11 +128,11 @@ func (bsc *BaseStableCollector) init(self StableCollector) {
|
||||
}
|
||||
|
||||
func (bsc *BaseStableCollector) trackRegistrableDescriptor(d *Desc) {
|
||||
if bsc.registrable == nil {
|
||||
bsc.registrable = make(map[string]*Desc)
|
||||
if bsc.registerable == nil {
|
||||
bsc.registerable = make(map[string]*Desc)
|
||||
}
|
||||
|
||||
bsc.registrable[d.fqName] = d
|
||||
bsc.registerable[d.fqName] = d
|
||||
}
|
||||
|
||||
func (bsc *BaseStableCollector) trackHiddenDescriptor(d *Desc) {
|
||||
@@ -158,7 +158,7 @@ func (bsc *BaseStableCollector) Create(version *semver.Version, self StableColle
|
||||
}
|
||||
}
|
||||
|
||||
if len(bsc.registrable) > 0 {
|
||||
if len(bsc.registerable) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ func (bsc *BaseStableCollector) ClearState() {
|
||||
}
|
||||
|
||||
bsc.descriptors = nil
|
||||
bsc.registrable = nil
|
||||
bsc.registerable = nil
|
||||
bsc.hidden = nil
|
||||
bsc.self = nil
|
||||
}
|
||||
|
||||
65
vendor/k8s.io/component-base/metrics/counter.go
generated
vendored
65
vendor/k8s.io/component-base/metrics/counter.go
generated
vendored
@@ -17,8 +17,10 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/blang/semver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
)
|
||||
|
||||
// Counter is our internal representation for our wrapping struct around prometheus
|
||||
@@ -30,6 +32,9 @@ type Counter struct {
|
||||
selfCollector
|
||||
}
|
||||
|
||||
// The implementation of the Metric interface is expected by testutil.GetCounterMetricValue.
|
||||
var _ Metric = &Counter{}
|
||||
|
||||
// NewCounter returns an object which satisfies the kubeCollector and CounterMetric interfaces.
|
||||
// However, the object returned will not measure anything unless the collector is first
|
||||
// registered, since the metric is lazily instantiated.
|
||||
@@ -45,6 +50,22 @@ func NewCounter(opts *CounterOpts) *Counter {
|
||||
return kc
|
||||
}
|
||||
|
||||
func (c *Counter) Desc() *prometheus.Desc {
|
||||
return c.metric.Desc()
|
||||
}
|
||||
|
||||
func (c *Counter) Write(to *dto.Metric) error {
|
||||
return c.metric.Write(to)
|
||||
}
|
||||
|
||||
// Reset resets the underlying prometheus Counter to start counting from 0 again
|
||||
func (c *Counter) Reset() {
|
||||
if !c.IsCreated() {
|
||||
return
|
||||
}
|
||||
c.setPrometheusCounter(prometheus.NewCounter(c.CounterOpts.toPromCounterOpts()))
|
||||
}
|
||||
|
||||
// setPrometheusCounter sets the underlying CounterMetric object, i.e. the thing that does the measurement.
|
||||
func (c *Counter) setPrometheusCounter(counter prometheus.Counter) {
|
||||
c.CounterMetric = counter
|
||||
@@ -71,6 +92,11 @@ func (c *Counter) initializeDeprecatedMetric() {
|
||||
c.initializeMetric()
|
||||
}
|
||||
|
||||
// WithContext allows the normal Counter metric to pass in context. The context is no-op now.
|
||||
func (c *Counter) WithContext(ctx context.Context) CounterMetric {
|
||||
return c.CounterMetric
|
||||
}
|
||||
|
||||
// CounterVec is the internal representation of our wrapping struct around prometheus
|
||||
// counterVecs. CounterVec implements both kubeCollector and CounterVecMetric.
|
||||
type CounterVec struct {
|
||||
@@ -86,13 +112,20 @@ type CounterVec struct {
|
||||
func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
fqName := BuildFQName(opts.Namespace, opts.Subsystem, opts.Name)
|
||||
allowListLock.RLock()
|
||||
if allowList, ok := labelValueAllowLists[fqName]; ok {
|
||||
opts.LabelValueAllowLists = allowList
|
||||
}
|
||||
allowListLock.RUnlock()
|
||||
|
||||
cv := &CounterVec{
|
||||
CounterVec: noopCounterVec,
|
||||
CounterOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
}
|
||||
cv.lazyInit(cv, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
cv.lazyInit(cv, fqName)
|
||||
return cv
|
||||
}
|
||||
|
||||
@@ -132,6 +165,9 @@ func (v *CounterVec) WithLabelValues(lvs ...string) CounterMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop // return no-op counter
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainToAllowedList(v.originalLabels, lvs)
|
||||
}
|
||||
return v.CounterVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
@@ -143,6 +179,9 @@ func (v *CounterVec) With(labels map[string]string) CounterMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop // return no-op counter
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainLabelMap(labels)
|
||||
}
|
||||
return v.CounterVec.With(labels)
|
||||
}
|
||||
|
||||
@@ -168,3 +207,27 @@ func (v *CounterVec) Reset() {
|
||||
|
||||
v.CounterVec.Reset()
|
||||
}
|
||||
|
||||
// WithContext returns wrapped CounterVec with context
|
||||
func (v *CounterVec) WithContext(ctx context.Context) *CounterVecWithContext {
|
||||
return &CounterVecWithContext{
|
||||
ctx: ctx,
|
||||
CounterVec: *v,
|
||||
}
|
||||
}
|
||||
|
||||
// CounterVecWithContext is the wrapper of CounterVec with context.
|
||||
type CounterVecWithContext struct {
|
||||
CounterVec
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// WithLabelValues is the wrapper of CounterVec.WithLabelValues.
|
||||
func (vc *CounterVecWithContext) WithLabelValues(lvs ...string) CounterMetric {
|
||||
return vc.CounterVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
// With is the wrapper of CounterVec.With.
|
||||
func (vc *CounterVecWithContext) With(labels map[string]string) CounterMetric {
|
||||
return vc.CounterVec.With(labels)
|
||||
}
|
||||
|
||||
2
vendor/k8s.io/component-base/metrics/desc.go
generated
vendored
2
vendor/k8s.io/component-base/metrics/desc.go
generated
vendored
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/blang/semver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// Desc is a prometheus.Desc extension.
|
||||
|
||||
45
vendor/k8s.io/component-base/metrics/gauge.go
generated
vendored
45
vendor/k8s.io/component-base/metrics/gauge.go
generated
vendored
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/blang/semver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
@@ -73,6 +74,11 @@ func (g *Gauge) initializeDeprecatedMetric() {
|
||||
g.initializeMetric()
|
||||
}
|
||||
|
||||
// WithContext allows the normal Gauge metric to pass in context. The context is no-op now.
|
||||
func (g *Gauge) WithContext(ctx context.Context) GaugeMetric {
|
||||
return g.GaugeMetric
|
||||
}
|
||||
|
||||
// GaugeVec is the internal representation of our wrapping struct around prometheus
|
||||
// gaugeVecs. kubeGaugeVec implements both kubeCollector and KubeGaugeVec.
|
||||
type GaugeVec struct {
|
||||
@@ -88,13 +94,20 @@ type GaugeVec struct {
|
||||
func NewGaugeVec(opts *GaugeOpts, labels []string) *GaugeVec {
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
fqName := BuildFQName(opts.Namespace, opts.Subsystem, opts.Name)
|
||||
allowListLock.RLock()
|
||||
if allowList, ok := labelValueAllowLists[fqName]; ok {
|
||||
opts.LabelValueAllowLists = allowList
|
||||
}
|
||||
allowListLock.RUnlock()
|
||||
|
||||
cv := &GaugeVec{
|
||||
GaugeVec: noopGaugeVec,
|
||||
GaugeOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
}
|
||||
cv.lazyInit(cv, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
cv.lazyInit(cv, fqName)
|
||||
return cv
|
||||
}
|
||||
|
||||
@@ -133,6 +146,9 @@ func (v *GaugeVec) WithLabelValues(lvs ...string) GaugeMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop // return no-op gauge
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainToAllowedList(v.originalLabels, lvs)
|
||||
}
|
||||
return v.GaugeVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
@@ -144,6 +160,9 @@ func (v *GaugeVec) With(labels map[string]string) GaugeMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop // return no-op gauge
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainLabelMap(labels)
|
||||
}
|
||||
return v.GaugeVec.With(labels)
|
||||
}
|
||||
|
||||
@@ -191,3 +210,27 @@ func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc {
|
||||
|
||||
return newGaugeFunc(opts, function, v)
|
||||
}
|
||||
|
||||
// WithContext returns wrapped GaugeVec with context
|
||||
func (v *GaugeVec) WithContext(ctx context.Context) *GaugeVecWithContext {
|
||||
return &GaugeVecWithContext{
|
||||
ctx: ctx,
|
||||
GaugeVec: *v,
|
||||
}
|
||||
}
|
||||
|
||||
// GaugeVecWithContext is the wrapper of GaugeVec with context.
|
||||
type GaugeVecWithContext struct {
|
||||
GaugeVec
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// WithLabelValues is the wrapper of GaugeVec.WithLabelValues.
|
||||
func (vc *GaugeVecWithContext) WithLabelValues(lvs ...string) GaugeMetric {
|
||||
return vc.GaugeVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
// With is the wrapper of GaugeVec.With.
|
||||
func (vc *GaugeVecWithContext) With(labels map[string]string) GaugeMetric {
|
||||
return vc.GaugeVec.With(labels)
|
||||
}
|
||||
|
||||
45
vendor/k8s.io/component-base/metrics/histogram.go
generated
vendored
45
vendor/k8s.io/component-base/metrics/histogram.go
generated
vendored
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/blang/semver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@@ -83,6 +84,11 @@ func (h *Histogram) initializeDeprecatedMetric() {
|
||||
h.initializeMetric()
|
||||
}
|
||||
|
||||
// WithContext allows the normal Histogram metric to pass in context. The context is no-op now.
|
||||
func (h *Histogram) WithContext(ctx context.Context) ObserverMetric {
|
||||
return h.ObserverMetric
|
||||
}
|
||||
|
||||
// HistogramVec is the internal representation of our wrapping struct around prometheus
|
||||
// histogramVecs.
|
||||
type HistogramVec struct {
|
||||
@@ -98,13 +104,20 @@ type HistogramVec struct {
|
||||
func NewHistogramVec(opts *HistogramOpts, labels []string) *HistogramVec {
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
fqName := BuildFQName(opts.Namespace, opts.Subsystem, opts.Name)
|
||||
allowListLock.RLock()
|
||||
if allowList, ok := labelValueAllowLists[fqName]; ok {
|
||||
opts.LabelValueAllowLists = allowList
|
||||
}
|
||||
allowListLock.RUnlock()
|
||||
|
||||
v := &HistogramVec{
|
||||
HistogramVec: noopHistogramVec,
|
||||
HistogramOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
}
|
||||
v.lazyInit(v, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
v.lazyInit(v, fqName)
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -139,6 +152,9 @@ func (v *HistogramVec) WithLabelValues(lvs ...string) ObserverMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainToAllowedList(v.originalLabels, lvs)
|
||||
}
|
||||
return v.HistogramVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
@@ -150,6 +166,9 @@ func (v *HistogramVec) With(labels map[string]string) ObserverMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainLabelMap(labels)
|
||||
}
|
||||
return v.HistogramVec.With(labels)
|
||||
}
|
||||
|
||||
@@ -175,3 +194,27 @@ func (v *HistogramVec) Reset() {
|
||||
|
||||
v.HistogramVec.Reset()
|
||||
}
|
||||
|
||||
// WithContext returns wrapped HistogramVec with context
|
||||
func (v *HistogramVec) WithContext(ctx context.Context) *HistogramVecWithContext {
|
||||
return &HistogramVecWithContext{
|
||||
ctx: ctx,
|
||||
HistogramVec: *v,
|
||||
}
|
||||
}
|
||||
|
||||
// HistogramVecWithContext is the wrapper of HistogramVec with context.
|
||||
type HistogramVecWithContext struct {
|
||||
HistogramVec
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// WithLabelValues is the wrapper of HistogramVec.WithLabelValues.
|
||||
func (vc *HistogramVecWithContext) WithLabelValues(lvs ...string) ObserverMetric {
|
||||
return vc.HistogramVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
// With is the wrapper of HistogramVec.With.
|
||||
func (vc *HistogramVecWithContext) With(labels map[string]string) ObserverMetric {
|
||||
return vc.HistogramVec.With(labels)
|
||||
}
|
||||
|
||||
14
vendor/k8s.io/component-base/metrics/http.go
generated
vendored
14
vendor/k8s.io/component-base/metrics/http.go
generated
vendored
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@@ -61,3 +62,16 @@ func (ho *HandlerOpts) toPromhttpHandlerOpts() promhttp.HandlerOpts {
|
||||
func HandlerFor(reg Gatherer, opts HandlerOpts) http.Handler {
|
||||
return promhttp.HandlerFor(reg, opts.toPromhttpHandlerOpts())
|
||||
}
|
||||
|
||||
// HandlerWithReset return an http.Handler with Reset
|
||||
func HandlerWithReset(reg KubeRegistry, opts HandlerOpts) http.Handler {
|
||||
defaultHandler := promhttp.HandlerFor(reg, opts.toPromhttpHandlerOpts())
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodDelete {
|
||||
reg.Reset()
|
||||
io.WriteString(w, "metrics reset\n")
|
||||
return
|
||||
}
|
||||
defaultHandler.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
35
vendor/k8s.io/component-base/metrics/legacyregistry/registry.go
generated
vendored
35
vendor/k8s.io/component-base/metrics/legacyregistry/registry.go
generated
vendored
@@ -29,6 +29,18 @@ var (
|
||||
defaultRegistry = metrics.NewKubeRegistry()
|
||||
// DefaultGatherer exposes the global registry gatherer
|
||||
DefaultGatherer metrics.Gatherer = defaultRegistry
|
||||
// Reset calls reset on the global registry
|
||||
Reset = defaultRegistry.Reset
|
||||
// MustRegister registers registerable metrics but uses the global registry.
|
||||
MustRegister = defaultRegistry.MustRegister
|
||||
// RawMustRegister registers prometheus collectors but uses the global registry, this
|
||||
// bypasses the metric stability framework
|
||||
//
|
||||
// Deprecated
|
||||
RawMustRegister = defaultRegistry.RawMustRegister
|
||||
|
||||
// Register registers a collectable metric but uses the global registry
|
||||
Register = defaultRegistry.Register
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -46,23 +58,12 @@ func Handler() http.Handler {
|
||||
return promhttp.InstrumentMetricHandler(prometheus.DefaultRegisterer, promhttp.HandlerFor(defaultRegistry, promhttp.HandlerOpts{}))
|
||||
}
|
||||
|
||||
// Register registers a collectable metric but uses the global registry
|
||||
func Register(c metrics.Registerable) error {
|
||||
err := defaultRegistry.Register(c)
|
||||
return err
|
||||
}
|
||||
|
||||
// MustRegister registers registerable metrics but uses the global registry.
|
||||
func MustRegister(cs ...metrics.Registerable) {
|
||||
defaultRegistry.MustRegister(cs...)
|
||||
}
|
||||
|
||||
// RawMustRegister registers prometheus collectors but uses the global registry, this
|
||||
// bypasses the metric stability framework
|
||||
//
|
||||
// Deprecated
|
||||
func RawMustRegister(cs ...prometheus.Collector) {
|
||||
defaultRegistry.RawMustRegister(cs...)
|
||||
// HandlerWithReset returns an HTTP handler for the DefaultGatherer but invokes
|
||||
// registry reset if the http method is DELETE.
|
||||
func HandlerWithReset() http.Handler {
|
||||
return promhttp.InstrumentMetricHandler(
|
||||
prometheus.DefaultRegisterer,
|
||||
metrics.HandlerWithReset(defaultRegistry, metrics.HandlerOpts{}))
|
||||
}
|
||||
|
||||
// CustomRegister registers a custom collector but uses the global registry.
|
||||
|
||||
28
vendor/k8s.io/component-base/metrics/metric.go
generated
vendored
28
vendor/k8s.io/component-base/metrics/metric.go
generated
vendored
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -87,10 +87,24 @@ func (r *lazyMetric) lazyInit(self kubeCollector, fqName string) {
|
||||
r.self = self
|
||||
}
|
||||
|
||||
// determineDeprecationStatus figures out whether the lazy metric should be deprecated or not.
|
||||
// preprocessMetric figures out whether the lazy metric should be hidden or not.
|
||||
// This method takes a Version argument which should be the version of the binary in which
|
||||
// this code is currently being executed.
|
||||
func (r *lazyMetric) determineDeprecationStatus(version semver.Version) {
|
||||
// this code is currently being executed. A metric can be hidden under two conditions:
|
||||
// 1. if the metric is deprecated and is outside the grace period (i.e. has been
|
||||
// deprecated for more than one release
|
||||
// 2. if the metric is manually disabled via a CLI flag.
|
||||
//
|
||||
// Disclaimer: disabling a metric via a CLI flag has higher precedence than
|
||||
// deprecation and will override show-hidden-metrics for the explicitly
|
||||
// disabled metric.
|
||||
func (r *lazyMetric) preprocessMetric(version semver.Version) {
|
||||
disabledMetricsLock.RLock()
|
||||
defer disabledMetricsLock.RUnlock()
|
||||
// disabling metrics is higher in precedence than showing hidden metrics
|
||||
if _, ok := disabledMetrics[r.fqName]; ok {
|
||||
r.isHidden = true
|
||||
return
|
||||
}
|
||||
selfVersion := r.self.DeprecatedVersion()
|
||||
if selfVersion == nil {
|
||||
return
|
||||
@@ -99,6 +113,7 @@ func (r *lazyMetric) determineDeprecationStatus(version semver.Version) {
|
||||
if selfVersion.LTE(version) {
|
||||
r.isDeprecated = true
|
||||
}
|
||||
|
||||
if ShouldShowHidden() {
|
||||
klog.Warningf("Hidden metrics (%s) have been manually overridden, showing this very deprecated metric.", r.fqName)
|
||||
return
|
||||
@@ -126,7 +141,7 @@ func (r *lazyMetric) IsDeprecated() bool {
|
||||
// created.
|
||||
func (r *lazyMetric) Create(version *semver.Version) bool {
|
||||
if version != nil {
|
||||
r.determineDeprecationStatus(*version)
|
||||
r.preprocessMetric(*version)
|
||||
}
|
||||
// let's not create if this metric is slated to be hidden
|
||||
if r.IsHidden() {
|
||||
@@ -188,9 +203,6 @@ func (c *selfCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
// no-op vecs for convenience
|
||||
var noopCounterVec = &prometheus.CounterVec{}
|
||||
var noopHistogramVec = &prometheus.HistogramVec{}
|
||||
|
||||
// lint:ignore U1000 Keep it for future use
|
||||
var noopSummaryVec = &prometheus.SummaryVec{}
|
||||
var noopGaugeVec = &prometheus.GaugeVec{}
|
||||
var noopObserverVec = &noopObserverVector{}
|
||||
|
||||
|
||||
125
vendor/k8s.io/component-base/metrics/options.go
generated
vendored
Normal file
125
vendor/k8s.io/component-base/metrics/options.go
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/component-base/version"
|
||||
)
|
||||
|
||||
// Options has all parameters needed for exposing metrics from components
|
||||
type Options struct {
|
||||
ShowHiddenMetricsForVersion string
|
||||
DisabledMetrics []string
|
||||
AllowListMapping map[string]string
|
||||
}
|
||||
|
||||
// NewOptions returns default metrics options
|
||||
func NewOptions() *Options {
|
||||
return &Options{}
|
||||
}
|
||||
|
||||
// Validate validates metrics flags options.
|
||||
func (o *Options) Validate() []error {
|
||||
var errs []error
|
||||
err := validateShowHiddenMetricsVersion(parseVersion(version.Get()), o.ShowHiddenMetricsForVersion)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
if err := validateAllowMetricLabel(o.AllowListMapping); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
if len(errs) == 0 {
|
||||
return nil
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// AddFlags adds flags for exposing component metrics.
|
||||
func (o *Options) AddFlags(fs *pflag.FlagSet) {
|
||||
if o != nil {
|
||||
o = NewOptions()
|
||||
}
|
||||
fs.StringVar(&o.ShowHiddenMetricsForVersion, "show-hidden-metrics-for-version", o.ShowHiddenMetricsForVersion,
|
||||
"The previous version for which you want to show hidden metrics. "+
|
||||
"Only the previous minor version is meaningful, other values will not be allowed. "+
|
||||
"The format is <major>.<minor>, e.g.: '1.16'. "+
|
||||
"The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, "+
|
||||
"rather than being surprised when they are permanently removed in the release after that.")
|
||||
fs.StringSliceVar(&o.DisabledMetrics,
|
||||
"disabled-metrics",
|
||||
o.DisabledMetrics,
|
||||
"This flag provides an escape hatch for misbehaving metrics. "+
|
||||
"You must provide the fully qualified metric name in order to disable it. "+
|
||||
"Disclaimer: disabling metrics is higher in precedence than showing hidden metrics.")
|
||||
fs.StringToStringVar(&o.AllowListMapping, "allow-metric-labels", o.AllowListMapping,
|
||||
"The map from metric-label to value allow-list of this label. The key's format is <MetricName>,<LabelName>. "+
|
||||
"The value's format is <allowed_value>,<allowed_value>..."+
|
||||
"e.g. metric1,label1='v1,v2,v3', metric1,label2='v1,v2,v3' metric2,label1='v1,v2,v3'.")
|
||||
}
|
||||
|
||||
// Apply applies parameters into global configuration of metrics.
|
||||
func (o *Options) Apply() {
|
||||
if o == nil {
|
||||
return
|
||||
}
|
||||
if len(o.ShowHiddenMetricsForVersion) > 0 {
|
||||
SetShowHidden()
|
||||
}
|
||||
// set disabled metrics
|
||||
for _, metricName := range o.DisabledMetrics {
|
||||
SetDisabledMetric(metricName)
|
||||
}
|
||||
if o.AllowListMapping != nil {
|
||||
SetLabelAllowListFromCLI(o.AllowListMapping)
|
||||
}
|
||||
}
|
||||
|
||||
func validateShowHiddenMetricsVersion(currentVersion semver.Version, targetVersionStr string) error {
|
||||
if targetVersionStr == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
validVersionStr := fmt.Sprintf("%d.%d", currentVersion.Major, currentVersion.Minor-1)
|
||||
if targetVersionStr != validVersionStr {
|
||||
return fmt.Errorf("--show-hidden-metrics-for-version must be omitted or have the value '%v'. Only the previous minor version is allowed", validVersionStr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAllowMetricLabel(allowListMapping map[string]string) error {
|
||||
if allowListMapping == nil {
|
||||
return nil
|
||||
}
|
||||
metricNameRegex := `[a-zA-Z_:][a-zA-Z0-9_:]*`
|
||||
labelRegex := `[a-zA-Z_][a-zA-Z0-9_]*`
|
||||
for k := range allowListMapping {
|
||||
reg := regexp.MustCompile(metricNameRegex + `,` + labelRegex)
|
||||
if reg.FindString(k) != k {
|
||||
return fmt.Errorf("--allow-metric-labels must has a list of kv pair with format `metricName:labelName=labelValue, labelValue,...`")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
126
vendor/k8s.io/component-base/metrics/opts.go
generated
vendored
126
vendor/k8s.io/component-base/metrics/opts.go
generated
vendored
@@ -18,10 +18,17 @@ package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
var (
|
||||
labelValueAllowLists = map[string]*MetricLabelAllowList{}
|
||||
allowListLock sync.RWMutex
|
||||
)
|
||||
|
||||
// KubeOpts is superset struct for prometheus.Opts. The prometheus Opts structure
|
||||
@@ -31,15 +38,16 @@ import (
|
||||
// Name must be set to a non-empty string. DeprecatedVersion is defined only
|
||||
// if the metric for which this options applies is, in fact, deprecated.
|
||||
type KubeOpts struct {
|
||||
Namespace string
|
||||
Subsystem string
|
||||
Name string
|
||||
Help string
|
||||
ConstLabels map[string]string
|
||||
DeprecatedVersion string
|
||||
deprecateOnce sync.Once
|
||||
annotateOnce sync.Once
|
||||
StabilityLevel StabilityLevel
|
||||
Namespace string
|
||||
Subsystem string
|
||||
Name string
|
||||
Help string
|
||||
ConstLabels map[string]string
|
||||
DeprecatedVersion string
|
||||
deprecateOnce sync.Once
|
||||
annotateOnce sync.Once
|
||||
StabilityLevel StabilityLevel
|
||||
LabelValueAllowLists *MetricLabelAllowList
|
||||
}
|
||||
|
||||
// BuildFQName joins the given three name components by "_". Empty name
|
||||
@@ -125,7 +133,7 @@ func (o *GaugeOpts) annotateStabilityLevel() {
|
||||
|
||||
// convenience function to allow easy transformation to the prometheus
|
||||
// counterpart. This will do more once we have a proper label abstraction
|
||||
func (o GaugeOpts) toPromGaugeOpts() prometheus.GaugeOpts {
|
||||
func (o *GaugeOpts) toPromGaugeOpts() prometheus.GaugeOpts {
|
||||
return prometheus.GaugeOpts{
|
||||
Namespace: o.Namespace,
|
||||
Subsystem: o.Subsystem,
|
||||
@@ -140,16 +148,17 @@ func (o GaugeOpts) toPromGaugeOpts() prometheus.GaugeOpts {
|
||||
// and can safely be left at their zero value, although it is strongly
|
||||
// encouraged to set a Help string.
|
||||
type HistogramOpts struct {
|
||||
Namespace string
|
||||
Subsystem string
|
||||
Name string
|
||||
Help string
|
||||
ConstLabels map[string]string
|
||||
Buckets []float64
|
||||
DeprecatedVersion string
|
||||
deprecateOnce sync.Once
|
||||
annotateOnce sync.Once
|
||||
StabilityLevel StabilityLevel
|
||||
Namespace string
|
||||
Subsystem string
|
||||
Name string
|
||||
Help string
|
||||
ConstLabels map[string]string
|
||||
Buckets []float64
|
||||
DeprecatedVersion string
|
||||
deprecateOnce sync.Once
|
||||
annotateOnce sync.Once
|
||||
StabilityLevel StabilityLevel
|
||||
LabelValueAllowLists *MetricLabelAllowList
|
||||
}
|
||||
|
||||
// Modify help description on the metric description.
|
||||
@@ -169,7 +178,7 @@ func (o *HistogramOpts) annotateStabilityLevel() {
|
||||
|
||||
// convenience function to allow easy transformation to the prometheus
|
||||
// counterpart. This will do more once we have a proper label abstraction
|
||||
func (o HistogramOpts) toPromHistogramOpts() prometheus.HistogramOpts {
|
||||
func (o *HistogramOpts) toPromHistogramOpts() prometheus.HistogramOpts {
|
||||
return prometheus.HistogramOpts{
|
||||
Namespace: o.Namespace,
|
||||
Subsystem: o.Subsystem,
|
||||
@@ -186,19 +195,20 @@ func (o HistogramOpts) toPromHistogramOpts() prometheus.HistogramOpts {
|
||||
// a help string and to explicitly set the Objectives field to the desired value
|
||||
// as the default value will change in the upcoming v0.10 of the library.
|
||||
type SummaryOpts struct {
|
||||
Namespace string
|
||||
Subsystem string
|
||||
Name string
|
||||
Help string
|
||||
ConstLabels map[string]string
|
||||
Objectives map[float64]float64
|
||||
MaxAge time.Duration
|
||||
AgeBuckets uint32
|
||||
BufCap uint32
|
||||
DeprecatedVersion string
|
||||
deprecateOnce sync.Once
|
||||
annotateOnce sync.Once
|
||||
StabilityLevel StabilityLevel
|
||||
Namespace string
|
||||
Subsystem string
|
||||
Name string
|
||||
Help string
|
||||
ConstLabels map[string]string
|
||||
Objectives map[float64]float64
|
||||
MaxAge time.Duration
|
||||
AgeBuckets uint32
|
||||
BufCap uint32
|
||||
DeprecatedVersion string
|
||||
deprecateOnce sync.Once
|
||||
annotateOnce sync.Once
|
||||
StabilityLevel StabilityLevel
|
||||
LabelValueAllowLists *MetricLabelAllowList
|
||||
}
|
||||
|
||||
// Modify help description on the metric description.
|
||||
@@ -224,7 +234,7 @@ var (
|
||||
|
||||
// convenience function to allow easy transformation to the prometheus
|
||||
// counterpart. This will do more once we have a proper label abstraction
|
||||
func (o SummaryOpts) toPromSummaryOpts() prometheus.SummaryOpts {
|
||||
func (o *SummaryOpts) toPromSummaryOpts() prometheus.SummaryOpts {
|
||||
// we need to retain existing quantile behavior for backwards compatibility,
|
||||
// so let's do what prometheus used to do prior to v1.
|
||||
objectives := o.Objectives
|
||||
@@ -243,3 +253,49 @@ func (o SummaryOpts) toPromSummaryOpts() prometheus.SummaryOpts {
|
||||
BufCap: o.BufCap,
|
||||
}
|
||||
}
|
||||
|
||||
type MetricLabelAllowList struct {
|
||||
labelToAllowList map[string]sets.String
|
||||
}
|
||||
|
||||
func (allowList *MetricLabelAllowList) ConstrainToAllowedList(labelNameList, labelValueList []string) {
|
||||
for index, value := range labelValueList {
|
||||
name := labelNameList[index]
|
||||
if allowValues, ok := allowList.labelToAllowList[name]; ok {
|
||||
if !allowValues.Has(value) {
|
||||
labelValueList[index] = "unexpected"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (allowList *MetricLabelAllowList) ConstrainLabelMap(labels map[string]string) {
|
||||
for name, value := range labels {
|
||||
if allowValues, ok := allowList.labelToAllowList[name]; ok {
|
||||
if !allowValues.Has(value) {
|
||||
labels[name] = "unexpected"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SetLabelAllowListFromCLI(allowListMapping map[string]string) {
|
||||
allowListLock.Lock()
|
||||
defer allowListLock.Unlock()
|
||||
for metricLabelName, labelValues := range allowListMapping {
|
||||
metricName := strings.Split(metricLabelName, ",")[0]
|
||||
labelName := strings.Split(metricLabelName, ",")[1]
|
||||
valueSet := sets.NewString(strings.Split(labelValues, ",")...)
|
||||
|
||||
allowList, ok := labelValueAllowLists[metricName]
|
||||
if ok {
|
||||
allowList.labelToAllowList[labelName] = valueSet
|
||||
} else {
|
||||
labelToAllowList := make(map[string]sets.String)
|
||||
labelToAllowList[labelName] = valueSet
|
||||
labelValueAllowLists[metricName] = &MetricLabelAllowList{
|
||||
labelToAllowList,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
vendor/k8s.io/component-base/metrics/processstarttime.go
generated
vendored
26
vendor/k8s.io/component-base/metrics/processstarttime.go
generated
vendored
@@ -17,12 +17,9 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/procfs"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
var processStartTime = NewGaugeVec(
|
||||
@@ -43,19 +40,12 @@ func RegisterProcessStartTime(registrationFunc func(Registerable) error) error {
|
||||
klog.Errorf("Could not get process start time, %v", err)
|
||||
start = float64(time.Now().Unix())
|
||||
}
|
||||
// processStartTime is a lazy metric which only get initialized after registered.
|
||||
// so we need to register the metric first and then set the value for it
|
||||
if err = registrationFunc(processStartTime); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
processStartTime.WithLabelValues().Set(start)
|
||||
return registrationFunc(processStartTime)
|
||||
}
|
||||
|
||||
func getProcessStart() (float64, error) {
|
||||
pid := os.Getpid()
|
||||
p, err := procfs.NewProc(pid)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if stat, err := p.NewStat(); err == nil {
|
||||
return stat.StartTime()
|
||||
}
|
||||
return 0, err
|
||||
return nil
|
||||
}
|
||||
|
||||
38
vendor/k8s.io/component-base/metrics/processstarttime_others.go
generated
vendored
Normal file
38
vendor/k8s.io/component-base/metrics/processstarttime_others.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// +build !windows
|
||||
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/prometheus/procfs"
|
||||
)
|
||||
|
||||
func getProcessStart() (float64, error) {
|
||||
pid := os.Getpid()
|
||||
p, err := procfs.NewProc(pid)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if stat, err := p.Stat(); err == nil {
|
||||
return stat.StartTime()
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
33
vendor/k8s.io/component-base/metrics/processstarttime_windows.go
generated
vendored
Normal file
33
vendor/k8s.io/component-base/metrics/processstarttime_windows.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func getProcessStart() (float64, error) {
|
||||
processHandle := windows.CurrentProcess()
|
||||
|
||||
var creationTime, exitTime, kernelTime, userTime windows.Filetime
|
||||
if err := windows.GetProcessTimes(processHandle, &creationTime, &exitTime, &kernelTime, &userTime); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return float64(creationTime.Nanoseconds() / 1e9), nil
|
||||
}
|
||||
130
vendor/k8s.io/component-base/metrics/prometheus/workqueue/metrics.go
generated
vendored
Normal file
130
vendor/k8s.io/component-base/metrics/prometheus/workqueue/metrics.go
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package workqueue
|
||||
|
||||
import (
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
k8smetrics "k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
)
|
||||
|
||||
// Package prometheus sets the workqueue DefaultMetricsFactory to produce
|
||||
// prometheus metrics. To use this package, you just have to import it.
|
||||
|
||||
// Metrics subsystem and keys used by the workqueue.
|
||||
const (
|
||||
WorkQueueSubsystem = "workqueue"
|
||||
DepthKey = "depth"
|
||||
AddsKey = "adds_total"
|
||||
QueueLatencyKey = "queue_duration_seconds"
|
||||
WorkDurationKey = "work_duration_seconds"
|
||||
UnfinishedWorkKey = "unfinished_work_seconds"
|
||||
LongestRunningProcessorKey = "longest_running_processor_seconds"
|
||||
RetriesKey = "retries_total"
|
||||
)
|
||||
|
||||
var (
|
||||
depth = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
|
||||
Subsystem: WorkQueueSubsystem,
|
||||
Name: DepthKey,
|
||||
Help: "Current depth of workqueue",
|
||||
}, []string{"name"})
|
||||
|
||||
adds = k8smetrics.NewCounterVec(&k8smetrics.CounterOpts{
|
||||
Subsystem: WorkQueueSubsystem,
|
||||
Name: AddsKey,
|
||||
Help: "Total number of adds handled by workqueue",
|
||||
}, []string{"name"})
|
||||
|
||||
latency = k8smetrics.NewHistogramVec(&k8smetrics.HistogramOpts{
|
||||
Subsystem: WorkQueueSubsystem,
|
||||
Name: QueueLatencyKey,
|
||||
Help: "How long in seconds an item stays in workqueue before being requested.",
|
||||
Buckets: k8smetrics.ExponentialBuckets(10e-9, 10, 10),
|
||||
}, []string{"name"})
|
||||
|
||||
workDuration = k8smetrics.NewHistogramVec(&k8smetrics.HistogramOpts{
|
||||
Subsystem: WorkQueueSubsystem,
|
||||
Name: WorkDurationKey,
|
||||
Help: "How long in seconds processing an item from workqueue takes.",
|
||||
Buckets: k8smetrics.ExponentialBuckets(10e-9, 10, 10),
|
||||
}, []string{"name"})
|
||||
|
||||
unfinished = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
|
||||
Subsystem: WorkQueueSubsystem,
|
||||
Name: UnfinishedWorkKey,
|
||||
Help: "How many seconds of work has done that " +
|
||||
"is in progress and hasn't been observed by work_duration. Large " +
|
||||
"values indicate stuck threads. One can deduce the number of stuck " +
|
||||
"threads by observing the rate at which this increases.",
|
||||
}, []string{"name"})
|
||||
|
||||
longestRunningProcessor = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
|
||||
Subsystem: WorkQueueSubsystem,
|
||||
Name: LongestRunningProcessorKey,
|
||||
Help: "How many seconds has the longest running " +
|
||||
"processor for workqueue been running.",
|
||||
}, []string{"name"})
|
||||
|
||||
retries = k8smetrics.NewCounterVec(&k8smetrics.CounterOpts{
|
||||
Subsystem: WorkQueueSubsystem,
|
||||
Name: RetriesKey,
|
||||
Help: "Total number of retries handled by workqueue",
|
||||
}, []string{"name"})
|
||||
|
||||
metrics = []k8smetrics.Registerable{
|
||||
depth, adds, latency, workDuration, unfinished, longestRunningProcessor, retries,
|
||||
}
|
||||
)
|
||||
|
||||
type prometheusMetricsProvider struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
for _, m := range metrics {
|
||||
legacyregistry.MustRegister(m)
|
||||
}
|
||||
workqueue.SetProvider(prometheusMetricsProvider{})
|
||||
}
|
||||
|
||||
func (prometheusMetricsProvider) NewDepthMetric(name string) workqueue.GaugeMetric {
|
||||
return depth.WithLabelValues(name)
|
||||
}
|
||||
|
||||
func (prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterMetric {
|
||||
return adds.WithLabelValues(name)
|
||||
}
|
||||
|
||||
func (prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.HistogramMetric {
|
||||
return latency.WithLabelValues(name)
|
||||
}
|
||||
|
||||
func (prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.HistogramMetric {
|
||||
return workDuration.WithLabelValues(name)
|
||||
}
|
||||
|
||||
func (prometheusMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) workqueue.SettableGaugeMetric {
|
||||
return unfinished.WithLabelValues(name)
|
||||
}
|
||||
|
||||
func (prometheusMetricsProvider) NewLongestRunningProcessorSecondsMetric(name string) workqueue.SettableGaugeMetric {
|
||||
return longestRunningProcessor.WithLabelValues(name)
|
||||
}
|
||||
|
||||
func (prometheusMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
|
||||
return retries.WithLabelValues(name)
|
||||
}
|
||||
76
vendor/k8s.io/component-base/metrics/registry.go
generated
vendored
76
vendor/k8s.io/component-base/metrics/registry.go
generated
vendored
@@ -30,10 +30,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
showHiddenOnce sync.Once
|
||||
showHidden atomic.Value
|
||||
registries []*kubeRegistry // stores all registries created by NewKubeRegistry()
|
||||
registriesLock sync.RWMutex
|
||||
showHiddenOnce sync.Once
|
||||
disabledMetricsLock sync.RWMutex
|
||||
showHidden atomic.Value
|
||||
registries []*kubeRegistry // stores all registries created by NewKubeRegistry()
|
||||
registriesLock sync.RWMutex
|
||||
disabledMetrics = map[string]struct{}{}
|
||||
)
|
||||
|
||||
// shouldHide be used to check if a specific metric with deprecated version should be hidden
|
||||
@@ -51,19 +53,6 @@ func shouldHide(currentVersion *semver.Version, deprecatedVersion *semver.Versio
|
||||
return false
|
||||
}
|
||||
|
||||
func validateShowHiddenMetricsVersion(currentVersion semver.Version, targetVersionStr string) error {
|
||||
if targetVersionStr == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
validVersionStr := fmt.Sprintf("%d.%d", currentVersion.Major, currentVersion.Minor-1)
|
||||
if targetVersionStr != validVersionStr {
|
||||
return fmt.Errorf("--show-hidden-metrics-for-version must be omitted or have the value '%v'. Only the previous minor version is allowed", validVersionStr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateShowHiddenMetricsVersion checks invalid version for which show hidden metrics.
|
||||
func ValidateShowHiddenMetricsVersion(v string) []error {
|
||||
err := validateShowHiddenMetricsVersion(parseVersion(version.Get()), v)
|
||||
@@ -74,6 +63,12 @@ func ValidateShowHiddenMetricsVersion(v string) []error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetDisabledMetric(name string) {
|
||||
disabledMetricsLock.Lock()
|
||||
defer disabledMetricsLock.Unlock()
|
||||
disabledMetrics[name] = struct{}{}
|
||||
}
|
||||
|
||||
// SetShowHidden will enable showing hidden metrics. This will no-opt
|
||||
// after the initial call
|
||||
func SetShowHidden() {
|
||||
@@ -110,17 +105,30 @@ type Registerable interface {
|
||||
FQName() string
|
||||
}
|
||||
|
||||
type resettable interface {
|
||||
Reset()
|
||||
}
|
||||
|
||||
// KubeRegistry is an interface which implements a subset of prometheus.Registerer and
|
||||
// prometheus.Gatherer interfaces
|
||||
type KubeRegistry interface {
|
||||
// Deprecated
|
||||
RawMustRegister(...prometheus.Collector)
|
||||
// CustomRegister is our internal variant of Prometheus registry.Register
|
||||
CustomRegister(c StableCollector) error
|
||||
// CustomMustRegister is our internal variant of Prometheus registry.MustRegister
|
||||
CustomMustRegister(cs ...StableCollector)
|
||||
// Register conforms to Prometheus registry.Register
|
||||
Register(Registerable) error
|
||||
// MustRegister conforms to Prometheus registry.MustRegister
|
||||
MustRegister(...Registerable)
|
||||
// Unregister conforms to Prometheus registry.Unregister
|
||||
Unregister(collector Collector) bool
|
||||
// Gather conforms to Prometheus gatherer.Gather
|
||||
Gather() ([]*dto.MetricFamily, error)
|
||||
// Reset invokes the Reset() function on all items in the registry
|
||||
// which are added as resettables.
|
||||
Reset()
|
||||
}
|
||||
|
||||
// kubeRegistry is a wrapper around a prometheus registry-type object. Upon initialization
|
||||
@@ -133,6 +141,8 @@ type kubeRegistry struct {
|
||||
stableCollectors []StableCollector // stores all stable collector
|
||||
hiddenCollectorsLock sync.RWMutex
|
||||
stableCollectorsLock sync.RWMutex
|
||||
resetLock sync.RWMutex
|
||||
resettables []resettable
|
||||
}
|
||||
|
||||
// Register registers a new Collector to be included in metrics
|
||||
@@ -142,11 +152,11 @@ type kubeRegistry struct {
|
||||
// uniqueness criteria described in the documentation of metric.Desc.
|
||||
func (kr *kubeRegistry) Register(c Registerable) error {
|
||||
if c.Create(&kr.version) {
|
||||
defer kr.addResettable(c)
|
||||
return kr.PromRegistry.Register(c)
|
||||
}
|
||||
|
||||
kr.trackHiddenCollector(c)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -158,6 +168,7 @@ func (kr *kubeRegistry) MustRegister(cs ...Registerable) {
|
||||
for _, c := range cs {
|
||||
if c.Create(&kr.version) {
|
||||
metrics = append(metrics, c)
|
||||
kr.addResettable(c)
|
||||
} else {
|
||||
kr.trackHiddenCollector(c)
|
||||
}
|
||||
@@ -168,7 +179,7 @@ func (kr *kubeRegistry) MustRegister(cs ...Registerable) {
|
||||
// CustomRegister registers a new custom collector.
|
||||
func (kr *kubeRegistry) CustomRegister(c StableCollector) error {
|
||||
kr.trackStableCollectors(c)
|
||||
|
||||
defer kr.addResettable(c)
|
||||
if c.Create(&kr.version, c) {
|
||||
return kr.PromRegistry.Register(c)
|
||||
}
|
||||
@@ -180,14 +191,13 @@ func (kr *kubeRegistry) CustomRegister(c StableCollector) error {
|
||||
// error.
|
||||
func (kr *kubeRegistry) CustomMustRegister(cs ...StableCollector) {
|
||||
kr.trackStableCollectors(cs...)
|
||||
|
||||
collectors := make([]prometheus.Collector, 0, len(cs))
|
||||
for _, c := range cs {
|
||||
if c.Create(&kr.version, c) {
|
||||
kr.addResettable(c)
|
||||
collectors = append(collectors, c)
|
||||
}
|
||||
}
|
||||
|
||||
kr.PromRegistry.MustRegister(collectors...)
|
||||
}
|
||||
|
||||
@@ -198,6 +208,19 @@ func (kr *kubeRegistry) CustomMustRegister(cs ...StableCollector) {
|
||||
// Deprecated
|
||||
func (kr *kubeRegistry) RawMustRegister(cs ...prometheus.Collector) {
|
||||
kr.PromRegistry.MustRegister(cs...)
|
||||
for _, c := range cs {
|
||||
kr.addResettable(c)
|
||||
}
|
||||
}
|
||||
|
||||
// addResettable will automatically add our metric to our reset
|
||||
// list if it satisfies the interface
|
||||
func (kr *kubeRegistry) addResettable(i interface{}) {
|
||||
kr.resetLock.Lock()
|
||||
defer kr.resetLock.Unlock()
|
||||
if resettable, ok := i.(resettable); ok {
|
||||
kr.resettables = append(kr.resettables, resettable)
|
||||
}
|
||||
}
|
||||
|
||||
// Unregister unregisters the Collector that equals the Collector passed
|
||||
@@ -279,6 +302,15 @@ func (kr *kubeRegistry) enableHiddenStableCollectors() {
|
||||
kr.CustomMustRegister(cs...)
|
||||
}
|
||||
|
||||
// Reset invokes Reset on all metrics that are resettable.
|
||||
func (kr *kubeRegistry) Reset() {
|
||||
kr.resetLock.RLock()
|
||||
defer kr.resetLock.RUnlock()
|
||||
for _, r := range kr.resettables {
|
||||
r.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
// BuildVersion is a helper function that can be easily mocked.
|
||||
var BuildVersion = version.Get
|
||||
|
||||
@@ -287,6 +319,7 @@ func newKubeRegistry(v apimachineryversion.Info) *kubeRegistry {
|
||||
PromRegistry: prometheus.NewRegistry(),
|
||||
version: parseVersion(v),
|
||||
hiddenCollectors: make(map[string]Registerable),
|
||||
resettables: make([]resettable, 0),
|
||||
}
|
||||
|
||||
registriesLock.Lock()
|
||||
@@ -300,6 +333,5 @@ func newKubeRegistry(v apimachineryversion.Info) *kubeRegistry {
|
||||
// pre-registered.
|
||||
func NewKubeRegistry() KubeRegistry {
|
||||
r := newKubeRegistry(BuildVersion())
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
45
vendor/k8s.io/component-base/metrics/summary.go
generated
vendored
45
vendor/k8s.io/component-base/metrics/summary.go
generated
vendored
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/blang/semver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@@ -74,6 +75,11 @@ func (s *Summary) initializeDeprecatedMetric() {
|
||||
s.initializeMetric()
|
||||
}
|
||||
|
||||
// WithContext allows the normal Summary metric to pass in context. The context is no-op now.
|
||||
func (s *Summary) WithContext(ctx context.Context) ObserverMetric {
|
||||
return s.ObserverMetric
|
||||
}
|
||||
|
||||
// SummaryVec is the internal representation of our wrapping struct around prometheus
|
||||
// summaryVecs.
|
||||
//
|
||||
@@ -93,12 +99,19 @@ type SummaryVec struct {
|
||||
func NewSummaryVec(opts *SummaryOpts, labels []string) *SummaryVec {
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
fqName := BuildFQName(opts.Namespace, opts.Subsystem, opts.Name)
|
||||
allowListLock.RLock()
|
||||
if allowList, ok := labelValueAllowLists[fqName]; ok {
|
||||
opts.LabelValueAllowLists = allowList
|
||||
}
|
||||
allowListLock.RUnlock()
|
||||
|
||||
v := &SummaryVec{
|
||||
SummaryOpts: opts,
|
||||
originalLabels: labels,
|
||||
lazyMetric: lazyMetric{},
|
||||
}
|
||||
v.lazyInit(v, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||
v.lazyInit(v, fqName)
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -133,6 +146,9 @@ func (v *SummaryVec) WithLabelValues(lvs ...string) ObserverMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainToAllowedList(v.originalLabels, lvs)
|
||||
}
|
||||
return v.SummaryVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
@@ -144,6 +160,9 @@ func (v *SummaryVec) With(labels map[string]string) ObserverMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainLabelMap(labels)
|
||||
}
|
||||
return v.SummaryVec.With(labels)
|
||||
}
|
||||
|
||||
@@ -169,3 +188,27 @@ func (v *SummaryVec) Reset() {
|
||||
|
||||
v.SummaryVec.Reset()
|
||||
}
|
||||
|
||||
// WithContext returns wrapped SummaryVec with context
|
||||
func (v *SummaryVec) WithContext(ctx context.Context) *SummaryVecWithContext {
|
||||
return &SummaryVecWithContext{
|
||||
ctx: ctx,
|
||||
SummaryVec: *v,
|
||||
}
|
||||
}
|
||||
|
||||
// SummaryVecWithContext is the wrapper of SummaryVec with context.
|
||||
type SummaryVecWithContext struct {
|
||||
SummaryVec
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// WithLabelValues is the wrapper of SummaryVec.WithLabelValues.
|
||||
func (vc *SummaryVecWithContext) WithLabelValues(lvs ...string) ObserverMetric {
|
||||
return vc.SummaryVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
// With is the wrapper of SummaryVec.With.
|
||||
func (vc *SummaryVecWithContext) With(labels map[string]string) ObserverMetric {
|
||||
return vc.SummaryVec.With(labels)
|
||||
}
|
||||
|
||||
129
vendor/k8s.io/component-base/metrics/testutil/metrics.go
generated
vendored
129
vendor/k8s.io/component-base/metrics/testutil/metrics.go
generated
vendored
@@ -43,8 +43,8 @@ type Metrics map[string]model.Samples
|
||||
|
||||
// Equal returns true if all metrics are the same as the arguments.
|
||||
func (m *Metrics) Equal(o Metrics) bool {
|
||||
leftKeySet := []string{}
|
||||
rightKeySet := []string{}
|
||||
var leftKeySet []string
|
||||
var rightKeySet []string
|
||||
for k := range *m {
|
||||
leftKeySet = append(leftKeySet, k)
|
||||
}
|
||||
@@ -86,35 +86,22 @@ func ParseMetrics(data string, output *Metrics) error {
|
||||
continue
|
||||
}
|
||||
for _, metric := range v {
|
||||
name := string(metric.Metric[model.MetricNameLabel])
|
||||
name := string(metric.Metric[MetricNameLabel])
|
||||
(*output)[name] = append((*output)[name], metric)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ExtractMetricSamples parses the prometheus metric samples from the input string.
|
||||
func ExtractMetricSamples(metricsBlob string) ([]*model.Sample, error) {
|
||||
dec := expfmt.NewDecoder(strings.NewReader(metricsBlob), expfmt.FmtText)
|
||||
decoder := expfmt.SampleDecoder{
|
||||
Dec: dec,
|
||||
Opts: &expfmt.DecodeOptions{},
|
||||
}
|
||||
|
||||
var samples []*model.Sample
|
||||
for {
|
||||
var v model.Vector
|
||||
if err := decoder.Decode(&v); err != nil {
|
||||
if err == io.EOF {
|
||||
// Expected loop termination condition.
|
||||
return samples, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
samples = append(samples, v...)
|
||||
}
|
||||
// TextToMetricFamilies reads 'in' as the simple and flat text-based exchange
|
||||
// format and creates MetricFamily proto messages. It returns the MetricFamily
|
||||
// proto messages in a map where the metric names are the keys, along with any
|
||||
// error encountered.
|
||||
func TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error) {
|
||||
var textParser expfmt.TextParser
|
||||
return textParser.TextToMetricFamilies(in)
|
||||
}
|
||||
|
||||
// PrintSample returns formated representation of metric Sample
|
||||
// PrintSample returns formatted representation of metric Sample
|
||||
func PrintSample(sample *model.Sample) string {
|
||||
buf := make([]string, 0)
|
||||
// Id is a VERY special label. For 'normal' container it's useless, but it's necessary
|
||||
@@ -198,22 +185,22 @@ func GetHistogramFromGatherer(gatherer metrics.Gatherer, metricName string) (His
|
||||
return Histogram{}, err
|
||||
}
|
||||
for _, mFamily := range m {
|
||||
if mFamily.Name != nil && *mFamily.Name == metricName {
|
||||
if mFamily.GetName() == metricName {
|
||||
metricFamily = mFamily
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if metricFamily == nil {
|
||||
return Histogram{}, fmt.Errorf("Metric %q not found", metricName)
|
||||
return Histogram{}, fmt.Errorf("metric %q not found", metricName)
|
||||
}
|
||||
|
||||
if metricFamily.GetMetric() == nil {
|
||||
return Histogram{}, fmt.Errorf("Metric %q is empty", metricName)
|
||||
return Histogram{}, fmt.Errorf("metric %q is empty", metricName)
|
||||
}
|
||||
|
||||
if len(metricFamily.GetMetric()) == 0 {
|
||||
return Histogram{}, fmt.Errorf("Metric %q is empty", metricName)
|
||||
return Histogram{}, fmt.Errorf("metric %q is empty", metricName)
|
||||
}
|
||||
|
||||
return Histogram{
|
||||
@@ -253,6 +240,10 @@ func bucketQuantile(q float64, buckets []bucket) float64 {
|
||||
return buckets[0].upperBound * (rank / buckets[0].count)
|
||||
}
|
||||
|
||||
if b == len(buckets)-1 && math.IsInf(buckets[b].upperBound, 1) {
|
||||
return buckets[len(buckets)-2].upperBound
|
||||
}
|
||||
|
||||
// linear approximation of b-th bucket
|
||||
brank := rank - buckets[b-1].count
|
||||
bSize := buckets[b].upperBound - buckets[b-1].upperBound
|
||||
@@ -264,48 +255,39 @@ func bucketQuantile(q float64, buckets []bucket) float64 {
|
||||
// Quantile computes q-th quantile of a cumulative histogram.
|
||||
// It's expected the histogram is valid (by calling Validate)
|
||||
func (hist *Histogram) Quantile(q float64) float64 {
|
||||
buckets := []bucket{}
|
||||
var buckets []bucket
|
||||
|
||||
for _, bckt := range hist.Bucket {
|
||||
buckets = append(buckets, bucket{
|
||||
count: float64(*bckt.CumulativeCount),
|
||||
upperBound: *bckt.UpperBound,
|
||||
count: float64(bckt.GetCumulativeCount()),
|
||||
upperBound: bckt.GetUpperBound(),
|
||||
})
|
||||
}
|
||||
|
||||
// bucketQuantile expects the upper bound of the last bucket to be +inf
|
||||
// buckets[len(buckets)-1].upperBound = math.Inf(+1)
|
||||
if len(buckets) == 0 || buckets[len(buckets)-1].upperBound != math.Inf(+1) {
|
||||
// The list of buckets in dto.Histogram doesn't include the final +Inf bucket, so we
|
||||
// add it here for the reset of the samples.
|
||||
buckets = append(buckets, bucket{
|
||||
count: float64(hist.GetSampleCount()),
|
||||
upperBound: math.Inf(+1),
|
||||
})
|
||||
}
|
||||
|
||||
return bucketQuantile(q, buckets)
|
||||
}
|
||||
|
||||
// Average computes histogram's average value
|
||||
func (hist *Histogram) Average() float64 {
|
||||
return *hist.SampleSum / float64(*hist.SampleCount)
|
||||
}
|
||||
|
||||
// Clear clears all fields of the wrapped histogram
|
||||
func (hist *Histogram) Clear() {
|
||||
if hist.SampleCount != nil {
|
||||
*hist.SampleCount = 0
|
||||
}
|
||||
if hist.SampleSum != nil {
|
||||
*hist.SampleSum = 0
|
||||
}
|
||||
for _, b := range hist.Bucket {
|
||||
if b.CumulativeCount != nil {
|
||||
*b.CumulativeCount = 0
|
||||
}
|
||||
}
|
||||
return hist.GetSampleSum() / float64(hist.GetSampleCount())
|
||||
}
|
||||
|
||||
// Validate makes sure the wrapped histogram has all necessary fields set and with valid values.
|
||||
func (hist *Histogram) Validate() error {
|
||||
if hist.SampleCount == nil || *hist.SampleCount == 0 {
|
||||
if hist.SampleCount == nil || hist.GetSampleCount() == 0 {
|
||||
return fmt.Errorf("nil or empty histogram SampleCount")
|
||||
}
|
||||
|
||||
if hist.SampleSum == nil || *hist.SampleSum == 0 {
|
||||
if hist.SampleSum == nil || hist.GetSampleSum() == 0 {
|
||||
return fmt.Errorf("nil or empty histogram SampleSum")
|
||||
}
|
||||
|
||||
@@ -313,7 +295,7 @@ func (hist *Histogram) Validate() error {
|
||||
if bckt == nil {
|
||||
return fmt.Errorf("empty histogram bucket")
|
||||
}
|
||||
if bckt.UpperBound == nil || *bckt.UpperBound < 0 {
|
||||
if bckt.UpperBound == nil || bckt.GetUpperBound() < 0 {
|
||||
return fmt.Errorf("nil or negative histogram bucket UpperBound")
|
||||
}
|
||||
}
|
||||
@@ -321,29 +303,60 @@ func (hist *Histogram) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetGaugeMetricValue extract metric value from GaugeMetric
|
||||
// GetGaugeMetricValue extracts metric value from GaugeMetric
|
||||
func GetGaugeMetricValue(m metrics.GaugeMetric) (float64, error) {
|
||||
metricProto := &dto.Metric{}
|
||||
if err := m.Write(metricProto); err != nil {
|
||||
return 0, fmt.Errorf("Error writing m: %v", err)
|
||||
return 0, fmt.Errorf("error writing m: %v", err)
|
||||
}
|
||||
return metricProto.Gauge.GetValue(), nil
|
||||
}
|
||||
|
||||
// GetCounterMetricValue extract metric value from CounterMetric
|
||||
// GetCounterMetricValue extracts metric value from CounterMetric
|
||||
func GetCounterMetricValue(m metrics.CounterMetric) (float64, error) {
|
||||
metricProto := &dto.Metric{}
|
||||
if err := m.(metrics.Metric).Write(metricProto); err != nil {
|
||||
return 0, fmt.Errorf("Error writing m: %v", err)
|
||||
return 0, fmt.Errorf("error writing m: %v", err)
|
||||
}
|
||||
return metricProto.Counter.GetValue(), nil
|
||||
}
|
||||
|
||||
// GetHistogramMetricValue extract sum of all samples from ObserverMetric
|
||||
// GetHistogramMetricValue extracts sum of all samples from ObserverMetric
|
||||
func GetHistogramMetricValue(m metrics.ObserverMetric) (float64, error) {
|
||||
metricProto := &dto.Metric{}
|
||||
if err := m.(metrics.Metric).Write(metricProto); err != nil {
|
||||
return 0, fmt.Errorf("Error writing m: %v", err)
|
||||
return 0, fmt.Errorf("error writing m: %v", err)
|
||||
}
|
||||
return metricProto.Histogram.GetSampleSum(), nil
|
||||
}
|
||||
|
||||
// GetHistogramMetricCount extracts count of all samples from ObserverMetric
|
||||
func GetHistogramMetricCount(m metrics.ObserverMetric) (uint64, error) {
|
||||
metricProto := &dto.Metric{}
|
||||
if err := m.(metrics.Metric).Write(metricProto); err != nil {
|
||||
return 0, fmt.Errorf("error writing m: %v", err)
|
||||
}
|
||||
return metricProto.Histogram.GetSampleCount(), nil
|
||||
}
|
||||
|
||||
// LabelsMatch returns true if metric has all expected labels otherwise false
|
||||
func LabelsMatch(metric *dto.Metric, labelFilter map[string]string) bool {
|
||||
metricLabels := map[string]string{}
|
||||
|
||||
for _, labelPair := range metric.Label {
|
||||
metricLabels[labelPair.GetName()] = labelPair.GetValue()
|
||||
}
|
||||
|
||||
// length comparison then match key to values in the maps
|
||||
if len(labelFilter) > len(metricLabels) {
|
||||
return false
|
||||
}
|
||||
|
||||
for labelName, labelValue := range labelFilter {
|
||||
if value, ok := metricLabels[labelName]; !ok || value != labelValue {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
156
vendor/k8s.io/component-base/metrics/testutil/promlint.go
generated
vendored
Normal file
156
vendor/k8s.io/component-base/metrics/testutil/promlint.go
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/testutil/promlint"
|
||||
)
|
||||
|
||||
// exceptionMetrics is an exception list of metrics which violates promlint rules.
|
||||
//
|
||||
// The original entries come from the existing metrics when we introduce promlint.
|
||||
// We setup this list for allow and not fail on the current violations.
|
||||
// Generally speaking, you need to fix the problem for a new metric rather than add it into the list.
|
||||
var exceptionMetrics = []string{
|
||||
// k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/server/egressselector
|
||||
"apiserver_egress_dialer_dial_failure_count", // counter metrics should have "_total" suffix
|
||||
|
||||
// k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/server/healthz
|
||||
"apiserver_request_total", // label names should be written in 'snake_case' not 'camelCase'
|
||||
|
||||
// k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/endpoints/filters
|
||||
"authenticated_user_requests", // counter metrics should have "_total" suffix
|
||||
"authentication_attempts", // counter metrics should have "_total" suffix
|
||||
|
||||
// kube-apiserver
|
||||
"aggregator_openapi_v2_regeneration_count",
|
||||
"apiserver_admission_step_admission_duration_seconds_summary",
|
||||
"apiserver_current_inflight_requests",
|
||||
"apiserver_longrunning_gauge",
|
||||
"get_token_count",
|
||||
"get_token_fail_count",
|
||||
"ssh_tunnel_open_count",
|
||||
"ssh_tunnel_open_fail_count",
|
||||
|
||||
// kube-controller-manager
|
||||
"attachdetach_controller_forced_detaches",
|
||||
"authenticated_user_requests",
|
||||
"authentication_attempts",
|
||||
"get_token_count",
|
||||
"get_token_fail_count",
|
||||
"node_collector_evictions_number",
|
||||
|
||||
// k8s.io/kubernetes/pkg/kubelet/server/stats
|
||||
// The two metrics have been deprecated and will be removed in release v1.20+.
|
||||
"container_cpu_usage_seconds_total", // non-counter metrics should not have "_total" suffix
|
||||
"node_cpu_usage_seconds_total", // non-counter metrics should not have "_total" suffix
|
||||
}
|
||||
|
||||
// A Problem is an issue detected by a Linter.
|
||||
type Problem promlint.Problem
|
||||
|
||||
func (p *Problem) String() string {
|
||||
return fmt.Sprintf("%s:%s", p.Metric, p.Text)
|
||||
}
|
||||
|
||||
// A Linter is a Prometheus metrics linter. It identifies issues with metric
|
||||
// names, types, and metadata, and reports them to the caller.
|
||||
type Linter struct {
|
||||
promLinter *promlint.Linter
|
||||
}
|
||||
|
||||
// Lint performs a linting pass, returning a slice of Problems indicating any
|
||||
// issues found in the metrics stream. The slice is sorted by metric name
|
||||
// and issue description.
|
||||
func (l *Linter) Lint() ([]Problem, error) {
|
||||
promProblems, err := l.promLinter.Lint()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Ignore problems those in exception list
|
||||
problems := make([]Problem, 0, len(promProblems))
|
||||
for i := range promProblems {
|
||||
if !l.shouldIgnore(promProblems[i].Metric) {
|
||||
problems = append(problems, Problem(promProblems[i]))
|
||||
}
|
||||
}
|
||||
|
||||
return problems, nil
|
||||
}
|
||||
|
||||
// shouldIgnore returns true if metric in the exception list, otherwise returns false.
|
||||
func (l *Linter) shouldIgnore(metricName string) bool {
|
||||
for i := range exceptionMetrics {
|
||||
if metricName == exceptionMetrics[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// NewPromLinter creates a new Linter that reads an input stream of Prometheus metrics.
|
||||
// Only the text exposition format is supported.
|
||||
func NewPromLinter(r io.Reader) *Linter {
|
||||
return &Linter{
|
||||
promLinter: promlint.New(r),
|
||||
}
|
||||
}
|
||||
|
||||
func mergeProblems(problems []Problem) string {
|
||||
var problemsMsg []string
|
||||
|
||||
for index := range problems {
|
||||
problemsMsg = append(problemsMsg, problems[index].String())
|
||||
}
|
||||
|
||||
return strings.Join(problemsMsg, ",")
|
||||
}
|
||||
|
||||
// shouldIgnore returns true if metric in the exception list, otherwise returns false.
|
||||
func shouldIgnore(metricName string) bool {
|
||||
for i := range exceptionMetrics {
|
||||
if metricName == exceptionMetrics[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// getLintError will ignore the metrics in exception list and converts lint problem to error.
|
||||
func getLintError(problems []promlint.Problem) error {
|
||||
var filteredProblems []Problem
|
||||
for _, problem := range problems {
|
||||
if shouldIgnore(problem.Metric) {
|
||||
continue
|
||||
}
|
||||
|
||||
filteredProblems = append(filteredProblems, Problem(problem))
|
||||
}
|
||||
|
||||
if len(filteredProblems) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("lint error: %s", mergeProblems(filteredProblems))
|
||||
}
|
||||
16
vendor/k8s.io/component-base/metrics/testutil/testutil.go
generated
vendored
16
vendor/k8s.io/component-base/metrics/testutil/testutil.go
generated
vendored
@@ -30,6 +30,14 @@ import (
|
||||
// pedantic Registry. It then does the same as GatherAndCompare, gathering the
|
||||
// metrics from the pedantic Registry.
|
||||
func CollectAndCompare(c metrics.Collector, expected io.Reader, metricNames ...string) error {
|
||||
lintProblems, err := testutil.CollectAndLint(c, metricNames...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := getLintError(lintProblems); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return testutil.CollectAndCompare(c, expected, metricNames...)
|
||||
}
|
||||
|
||||
@@ -38,6 +46,14 @@ func CollectAndCompare(c metrics.Collector, expected io.Reader, metricNames ...s
|
||||
// exposition format. If any metricNames are provided, only metrics with those
|
||||
// names are compared.
|
||||
func GatherAndCompare(g metrics.Gatherer, expected io.Reader, metricNames ...string) error {
|
||||
lintProblems, err := testutil.GatherAndLint(g, metricNames...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := getLintError(lintProblems); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return testutil.GatherAndCompare(g, expected, metricNames...)
|
||||
}
|
||||
|
||||
|
||||
2
vendor/k8s.io/component-base/metrics/version.go
generated
vendored
2
vendor/k8s.io/component-base/metrics/version.go
generated
vendored
@@ -25,7 +25,7 @@ var (
|
||||
Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit, git tree state, build date, Go version, and compiler from which Kubernetes was built, and platform on which it is running.",
|
||||
StabilityLevel: ALPHA,
|
||||
},
|
||||
[]string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState", "buildDate", "goVersion", "compiler", "platform"},
|
||||
[]string{"major", "minor", "git_version", "git_commit", "git_tree_state", "build_date", "go_version", "compiler", "platform"},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
2
vendor/k8s.io/component-base/version/base.go
generated
vendored
2
vendor/k8s.io/component-base/version/base.go
generated
vendored
@@ -55,7 +55,7 @@ var (
|
||||
// NOTE: The $Format strings are replaced during 'git archive' thanks to the
|
||||
// companion .gitattributes file containing 'export-subst' in this same
|
||||
// directory. See also https://git-scm.com/docs/gitattributes
|
||||
gitVersion = "v0.0.0-master+$Format:%h$"
|
||||
gitVersion = "v0.0.0-master+$Format:%H$"
|
||||
gitCommit = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD)
|
||||
gitTreeState = "" // state of git tree, either "clean" or "dirty"
|
||||
|
||||
|
||||
39
vendor/k8s.io/component-base/version/def.bzl
generated
vendored
39
vendor/k8s.io/component-base/version/def.bzl
generated
vendored
@@ -1,39 +0,0 @@
|
||||
# Copyright 2017 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Implements hack/lib/version.sh's kube::version::ldflags() for Bazel.
|
||||
def version_x_defs():
|
||||
# This should match the list of packages in kube::version::ldflag
|
||||
stamp_pkgs = [
|
||||
"k8s.io/kubernetes/vendor/k8s.io/component-base/version",
|
||||
"k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version",
|
||||
]
|
||||
|
||||
# This should match the list of vars in kube::version::ldflags
|
||||
# It should also match the list of vars set in hack/print-workspace-status.sh.
|
||||
stamp_vars = [
|
||||
"buildDate",
|
||||
"gitCommit",
|
||||
"gitMajor",
|
||||
"gitMinor",
|
||||
"gitTreeState",
|
||||
"gitVersion",
|
||||
]
|
||||
|
||||
# Generate the cross-product.
|
||||
x_defs = {}
|
||||
for pkg in stamp_pkgs:
|
||||
for var in stamp_vars:
|
||||
x_defs["%s.%s" % (pkg, var)] = "{%s}" % var
|
||||
return x_defs
|
||||
Reference in New Issue
Block a user