2022-11-22 14:26:49 +00:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
2022-11-22 15:12:30 +00:00
|
|
|
"time"
|
2022-11-22 14:26:49 +00:00
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
"github.com/go-logr/logr"
|
2023-08-18 03:54:05 +00:00
|
|
|
github_com_google_gnostic_models_openapiv2 "github.com/google/gnostic-models/openapiv2"
|
2022-11-22 14:26:49 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/metrics"
|
2022-11-22 15:12:30 +00:00
|
|
|
"go.uber.org/multierr"
|
2022-11-22 14:26:49 +00:00
|
|
|
k8s_io_apimachinery_pkg_apis_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
k8s_io_apimachinery_pkg_version "k8s.io/apimachinery/pkg/version"
|
|
|
|
k8s_io_client_go_discovery "k8s.io/client-go/discovery"
|
|
|
|
k8s_io_client_go_openapi "k8s.io/client-go/openapi"
|
|
|
|
k8s_io_client_go_rest "k8s.io/client-go/rest"
|
|
|
|
)
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
func WithLogging(inner k8s_io_client_go_discovery.DiscoveryInterface, logger logr.Logger) k8s_io_client_go_discovery.DiscoveryInterface {
|
|
|
|
return &withLogging{inner, logger}
|
|
|
|
}
|
|
|
|
|
2022-11-22 14:26:49 +00:00
|
|
|
func WithMetrics(inner k8s_io_client_go_discovery.DiscoveryInterface, recorder metrics.Recorder) k8s_io_client_go_discovery.DiscoveryInterface {
|
|
|
|
return &withMetrics{inner, recorder}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithTracing(inner k8s_io_client_go_discovery.DiscoveryInterface, client, kind string) k8s_io_client_go_discovery.DiscoveryInterface {
|
|
|
|
return &withTracing{inner, client, kind}
|
|
|
|
}
|
|
|
|
|
2022-11-22 15:12:30 +00:00
|
|
|
type withLogging struct {
|
|
|
|
inner k8s_io_client_go_discovery.DiscoveryInterface
|
|
|
|
logger logr.Logger
|
|
|
|
}
|
|
|
|
|
2023-08-18 03:54:05 +00:00
|
|
|
func (c *withLogging) OpenAPISchema() (*github_com_google_gnostic_models_openapiv2.Document, error) {
|
2022-11-22 15:12:30 +00:00
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "OpenAPISchema")
|
|
|
|
ret0, ret1 := c.inner.OpenAPISchema()
|
|
|
|
if err := multierr.Combine(ret1); err != nil {
|
|
|
|
logger.Error(err, "OpenAPISchema failed", "duration", time.Since(start))
|
|
|
|
} else {
|
|
|
|
logger.Info("OpenAPISchema done", "duration", time.Since(start))
|
|
|
|
}
|
|
|
|
return ret0, ret1
|
|
|
|
}
|
|
|
|
func (c *withLogging) OpenAPIV3() k8s_io_client_go_openapi.Client {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "OpenAPIV3")
|
|
|
|
ret0 := c.inner.OpenAPIV3()
|
|
|
|
logger.Info("OpenAPIV3 done", "duration", time.Since(start))
|
|
|
|
return ret0
|
|
|
|
}
|
|
|
|
func (c *withLogging) RESTClient() k8s_io_client_go_rest.Interface {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "RESTClient")
|
|
|
|
ret0 := c.inner.RESTClient()
|
|
|
|
logger.Info("RESTClient done", "duration", time.Since(start))
|
|
|
|
return ret0
|
|
|
|
}
|
|
|
|
func (c *withLogging) ServerGroups() (*k8s_io_apimachinery_pkg_apis_meta_v1.APIGroupList, error) {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "ServerGroups")
|
|
|
|
ret0, ret1 := c.inner.ServerGroups()
|
|
|
|
if err := multierr.Combine(ret1); err != nil {
|
|
|
|
logger.Error(err, "ServerGroups failed", "duration", time.Since(start))
|
|
|
|
} else {
|
|
|
|
logger.Info("ServerGroups done", "duration", time.Since(start))
|
|
|
|
}
|
|
|
|
return ret0, ret1
|
|
|
|
}
|
|
|
|
func (c *withLogging) ServerGroupsAndResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIGroup, []*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "ServerGroupsAndResources")
|
|
|
|
ret0, ret1, ret2 := c.inner.ServerGroupsAndResources()
|
|
|
|
if err := multierr.Combine(ret2); err != nil {
|
|
|
|
logger.Error(err, "ServerGroupsAndResources failed", "duration", time.Since(start))
|
|
|
|
} else {
|
|
|
|
logger.Info("ServerGroupsAndResources done", "duration", time.Since(start))
|
|
|
|
}
|
|
|
|
return ret0, ret1, ret2
|
|
|
|
}
|
|
|
|
func (c *withLogging) ServerPreferredNamespacedResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "ServerPreferredNamespacedResources")
|
|
|
|
ret0, ret1 := c.inner.ServerPreferredNamespacedResources()
|
|
|
|
if err := multierr.Combine(ret1); err != nil {
|
|
|
|
logger.Error(err, "ServerPreferredNamespacedResources failed", "duration", time.Since(start))
|
|
|
|
} else {
|
|
|
|
logger.Info("ServerPreferredNamespacedResources done", "duration", time.Since(start))
|
|
|
|
}
|
|
|
|
return ret0, ret1
|
|
|
|
}
|
|
|
|
func (c *withLogging) ServerPreferredResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "ServerPreferredResources")
|
|
|
|
ret0, ret1 := c.inner.ServerPreferredResources()
|
|
|
|
if err := multierr.Combine(ret1); err != nil {
|
|
|
|
logger.Error(err, "ServerPreferredResources failed", "duration", time.Since(start))
|
|
|
|
} else {
|
|
|
|
logger.Info("ServerPreferredResources done", "duration", time.Since(start))
|
|
|
|
}
|
|
|
|
return ret0, ret1
|
|
|
|
}
|
|
|
|
func (c *withLogging) ServerResourcesForGroupVersion(arg0 string) (*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "ServerResourcesForGroupVersion")
|
|
|
|
ret0, ret1 := c.inner.ServerResourcesForGroupVersion(arg0)
|
|
|
|
if err := multierr.Combine(ret1); err != nil {
|
|
|
|
logger.Error(err, "ServerResourcesForGroupVersion failed", "duration", time.Since(start))
|
|
|
|
} else {
|
|
|
|
logger.Info("ServerResourcesForGroupVersion done", "duration", time.Since(start))
|
|
|
|
}
|
|
|
|
return ret0, ret1
|
|
|
|
}
|
|
|
|
func (c *withLogging) ServerVersion() (*k8s_io_apimachinery_pkg_version.Info, error) {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "ServerVersion")
|
|
|
|
ret0, ret1 := c.inner.ServerVersion()
|
|
|
|
if err := multierr.Combine(ret1); err != nil {
|
|
|
|
logger.Error(err, "ServerVersion failed", "duration", time.Since(start))
|
|
|
|
} else {
|
|
|
|
logger.Info("ServerVersion done", "duration", time.Since(start))
|
|
|
|
}
|
|
|
|
return ret0, ret1
|
|
|
|
}
|
2022-12-21 22:33:51 +00:00
|
|
|
func (c *withLogging) WithLegacy() k8s_io_client_go_discovery.DiscoveryInterface {
|
|
|
|
start := time.Now()
|
|
|
|
logger := c.logger.WithValues("operation", "WithLegacy")
|
|
|
|
ret0 := c.inner.WithLegacy()
|
|
|
|
logger.Info("WithLegacy done", "duration", time.Since(start))
|
|
|
|
return ret0
|
|
|
|
}
|
2022-11-22 15:12:30 +00:00
|
|
|
|
2022-11-22 14:26:49 +00:00
|
|
|
type withMetrics struct {
|
|
|
|
inner k8s_io_client_go_discovery.DiscoveryInterface
|
|
|
|
recorder metrics.Recorder
|
|
|
|
}
|
|
|
|
|
2023-08-18 03:54:05 +00:00
|
|
|
func (c *withMetrics) OpenAPISchema() (*github_com_google_gnostic_models_openapiv2.Document, error) {
|
2022-11-22 14:26:49 +00:00
|
|
|
defer c.recorder.Record("open_api_schema")
|
|
|
|
return c.inner.OpenAPISchema()
|
|
|
|
}
|
|
|
|
func (c *withMetrics) OpenAPIV3() k8s_io_client_go_openapi.Client {
|
|
|
|
defer c.recorder.Record("open_apiv3")
|
|
|
|
return c.inner.OpenAPIV3()
|
|
|
|
}
|
|
|
|
func (c *withMetrics) RESTClient() k8s_io_client_go_rest.Interface {
|
|
|
|
defer c.recorder.Record("rest_client")
|
|
|
|
return c.inner.RESTClient()
|
|
|
|
}
|
|
|
|
func (c *withMetrics) ServerGroups() (*k8s_io_apimachinery_pkg_apis_meta_v1.APIGroupList, error) {
|
|
|
|
defer c.recorder.Record("server_groups")
|
|
|
|
return c.inner.ServerGroups()
|
|
|
|
}
|
|
|
|
func (c *withMetrics) ServerGroupsAndResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIGroup, []*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
defer c.recorder.Record("server_groups_and_resources")
|
|
|
|
return c.inner.ServerGroupsAndResources()
|
|
|
|
}
|
|
|
|
func (c *withMetrics) ServerPreferredNamespacedResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
defer c.recorder.Record("server_preferred_namespaced_resources")
|
|
|
|
return c.inner.ServerPreferredNamespacedResources()
|
|
|
|
}
|
|
|
|
func (c *withMetrics) ServerPreferredResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
defer c.recorder.Record("server_preferred_resources")
|
|
|
|
return c.inner.ServerPreferredResources()
|
|
|
|
}
|
|
|
|
func (c *withMetrics) ServerResourcesForGroupVersion(arg0 string) (*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
|
|
|
defer c.recorder.Record("server_resources_for_group_version")
|
|
|
|
return c.inner.ServerResourcesForGroupVersion(arg0)
|
|
|
|
}
|
|
|
|
func (c *withMetrics) ServerVersion() (*k8s_io_apimachinery_pkg_version.Info, error) {
|
|
|
|
defer c.recorder.Record("server_version")
|
|
|
|
return c.inner.ServerVersion()
|
|
|
|
}
|
2022-12-21 22:33:51 +00:00
|
|
|
func (c *withMetrics) WithLegacy() k8s_io_client_go_discovery.DiscoveryInterface {
|
|
|
|
defer c.recorder.Record("with_legacy")
|
|
|
|
return c.inner.WithLegacy()
|
|
|
|
}
|
2022-11-22 14:26:49 +00:00
|
|
|
|
|
|
|
type withTracing struct {
|
|
|
|
inner k8s_io_client_go_discovery.DiscoveryInterface
|
|
|
|
client string
|
|
|
|
kind string
|
|
|
|
}
|
|
|
|
|
2023-08-18 03:54:05 +00:00
|
|
|
func (c *withTracing) OpenAPISchema() (*github_com_google_gnostic_models_openapiv2.Document, error) {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.OpenAPISchema()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) OpenAPIV3() k8s_io_client_go_openapi.Client {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.OpenAPIV3()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) RESTClient() k8s_io_client_go_rest.Interface {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.RESTClient()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) ServerGroups() (*k8s_io_apimachinery_pkg_apis_meta_v1.APIGroupList, error) {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.ServerGroups()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) ServerGroupsAndResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIGroup, []*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.ServerGroupsAndResources()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) ServerPreferredNamespacedResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.ServerPreferredNamespacedResources()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) ServerPreferredResources() ([]*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.ServerPreferredResources()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) ServerResourcesForGroupVersion(arg0 string) (*k8s_io_apimachinery_pkg_apis_meta_v1.APIResourceList, error) {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.ServerResourcesForGroupVersion(arg0)
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
|
|
|
func (c *withTracing) ServerVersion() (*k8s_io_apimachinery_pkg_version.Info, error) {
|
2022-12-08 14:52:12 +00:00
|
|
|
return c.inner.ServerVersion()
|
2022-11-22 14:26:49 +00:00
|
|
|
}
|
2022-12-21 22:33:51 +00:00
|
|
|
func (c *withTracing) WithLegacy() k8s_io_client_go_discovery.DiscoveryInterface {
|
|
|
|
return c.inner.WithLegacy()
|
|
|
|
}
|