mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	pkg/util: move trace.go to k8s.io/apiserver/pkg/util/trace
This commit is contained in:
		 Dr. Stefan Schimanski
					Dr. Stefan Schimanski
				
			
				
					committed by
					
						 Dr. Stefan Schimanski
						Dr. Stefan Schimanski
					
				
			
			
				
	
			
			
			 Dr. Stefan Schimanski
						Dr. Stefan Schimanski
					
				
			
						parent
						
							a3f8ee6578
						
					
				
				
					commit
					a12c661773
				
			| @@ -32,6 +32,7 @@ import ( | ||||
| 	utilerrors "k8s.io/apimachinery/pkg/util/errors" | ||||
| 	utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/util/wait" | ||||
| 	utiltrace "k8s.io/apiserver/pkg/util/trace" | ||||
| 	"k8s.io/client-go/tools/cache" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| 	"k8s.io/kubernetes/pkg/client/clientset_generated/clientset" | ||||
| @@ -40,7 +41,6 @@ import ( | ||||
| 	"k8s.io/kubernetes/pkg/client/record" | ||||
| 	"k8s.io/kubernetes/pkg/controller" | ||||
| 	"k8s.io/kubernetes/pkg/controller/informers" | ||||
| 	"k8s.io/kubernetes/pkg/util" | ||||
| 	"k8s.io/kubernetes/pkg/util/metrics" | ||||
| 	"k8s.io/kubernetes/pkg/util/workqueue" | ||||
| ) | ||||
| @@ -596,7 +596,7 @@ func (rm *ReplicationManager) manageReplicas(filteredPods []*v1.Pod, rc *v1.Repl | ||||
| // it did not expect to see any more of its pods created or deleted. This function is not meant to be invoked | ||||
| // concurrently with the same key. | ||||
| func (rm *ReplicationManager) syncReplicationController(key string) error { | ||||
| 	trace := util.NewTrace("syncReplicationController: " + key) | ||||
| 	trace := utiltrace.New("syncReplicationController: " + key) | ||||
| 	defer trace.LogIfLong(250 * time.Millisecond) | ||||
|  | ||||
| 	startTime := time.Now() | ||||
|   | ||||
| @@ -27,6 +27,9 @@ import ( | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/emicklei/go-restful" | ||||
| 	"github.com/golang/glog" | ||||
|  | ||||
| 	"k8s.io/apimachinery/pkg/api/errors" | ||||
| 	"k8s.io/apimachinery/pkg/api/meta" | ||||
| 	metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" | ||||
| @@ -40,12 +43,9 @@ import ( | ||||
| 	"k8s.io/apiserver/pkg/admission" | ||||
| 	"k8s.io/apiserver/pkg/endpoints/handlers/negotiation" | ||||
| 	"k8s.io/apiserver/pkg/endpoints/request" | ||||
| 	utiltrace "k8s.io/apiserver/pkg/util/trace" | ||||
| 	"k8s.io/kubernetes/pkg/genericapiserver/endpoints/handlers/responsewriters" | ||||
| 	"k8s.io/kubernetes/pkg/genericapiserver/registry/rest" | ||||
| 	"k8s.io/kubernetes/pkg/util" | ||||
|  | ||||
| 	"github.com/emicklei/go-restful" | ||||
| 	"github.com/golang/glog" | ||||
| ) | ||||
|  | ||||
| // ContextFunc returns a Context given a request - a context must be returned | ||||
| @@ -133,7 +133,7 @@ func GetResource(r rest.Getter, e rest.Exporter, scope RequestScope) restful.Rou | ||||
| 	return getResourceHandler(scope, | ||||
| 		func(ctx request.Context, name string, req *restful.Request) (runtime.Object, error) { | ||||
| 			// For performance tracking purposes. | ||||
| 			trace := util.NewTrace("Get " + req.Request.URL.Path) | ||||
| 			trace := utiltrace.New("Get " + req.Request.URL.Path) | ||||
| 			defer trace.LogIfLong(500 * time.Millisecond) | ||||
|  | ||||
| 			// check for export | ||||
| @@ -245,7 +245,7 @@ func (r *responder) Error(err error) { | ||||
| func ListResource(r rest.Lister, rw rest.Watcher, scope RequestScope, forceWatch bool, minRequestTimeout time.Duration) restful.RouteFunction { | ||||
| 	return func(req *restful.Request, res *restful.Response) { | ||||
| 		// For performance tracking purposes. | ||||
| 		trace := util.NewTrace("List " + req.Request.URL.Path) | ||||
| 		trace := utiltrace.New("List " + req.Request.URL.Path) | ||||
|  | ||||
| 		w := res.ResponseWriter | ||||
|  | ||||
| @@ -352,7 +352,7 @@ func ListResource(r rest.Lister, rw rest.Watcher, scope RequestScope, forceWatch | ||||
| func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface, includeName bool) restful.RouteFunction { | ||||
| 	return func(req *restful.Request, res *restful.Response) { | ||||
| 		// For performance tracking purposes. | ||||
| 		trace := util.NewTrace("Create " + req.Request.URL.Path) | ||||
| 		trace := utiltrace.New("Create " + req.Request.URL.Path) | ||||
| 		defer trace.LogIfLong(500 * time.Millisecond) | ||||
|  | ||||
| 		w := res.ResponseWriter | ||||
| @@ -707,7 +707,7 @@ func patchResource( | ||||
| func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectTyper, admit admission.Interface) restful.RouteFunction { | ||||
| 	return func(req *restful.Request, res *restful.Response) { | ||||
| 		// For performance tracking purposes. | ||||
| 		trace := util.NewTrace("Update " + req.Request.URL.Path) | ||||
| 		trace := utiltrace.New("Update " + req.Request.URL.Path) | ||||
| 		defer trace.LogIfLong(500 * time.Millisecond) | ||||
|  | ||||
| 		w := res.ResponseWriter | ||||
| @@ -794,7 +794,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType | ||||
| func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestScope, admit admission.Interface) restful.RouteFunction { | ||||
| 	return func(req *restful.Request, res *restful.Response) { | ||||
| 		// For performance tracking purposes. | ||||
| 		trace := util.NewTrace("Delete " + req.Request.URL.Path) | ||||
| 		trace := utiltrace.New("Delete " + req.Request.URL.Path) | ||||
| 		defer trace.LogIfLong(500 * time.Millisecond) | ||||
|  | ||||
| 		w := res.ResponseWriter | ||||
|   | ||||
| @@ -24,6 +24,9 @@ import ( | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/golang/glog" | ||||
| 	"golang.org/x/net/context" | ||||
|  | ||||
| 	"k8s.io/apimachinery/pkg/api/errors" | ||||
| 	"k8s.io/apimachinery/pkg/api/meta" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| @@ -34,11 +37,8 @@ import ( | ||||
| 	utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/util/wait" | ||||
| 	"k8s.io/apimachinery/pkg/watch" | ||||
| 	utiltrace "k8s.io/apiserver/pkg/util/trace" | ||||
| 	"k8s.io/client-go/tools/cache" | ||||
| 	"k8s.io/kubernetes/pkg/util" | ||||
|  | ||||
| 	"github.com/golang/glog" | ||||
| 	"golang.org/x/net/context" | ||||
| ) | ||||
|  | ||||
| // CacherConfig contains the configuration for a given Cache. | ||||
| @@ -413,7 +413,7 @@ func (c *Cacher) GetToList(ctx context.Context, key string, resourceVersion stri | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	trace := util.NewTrace(fmt.Sprintf("cacher %v: List", c.objectType.String())) | ||||
| 	trace := utiltrace.New(fmt.Sprintf("cacher %v: List", c.objectType.String())) | ||||
| 	defer trace.LogIfLong(500 * time.Millisecond) | ||||
|  | ||||
| 	c.ready.wait() | ||||
| @@ -469,7 +469,7 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, p | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	trace := util.NewTrace(fmt.Sprintf("cacher %v: List", c.objectType.String())) | ||||
| 	trace := utiltrace.New(fmt.Sprintf("cacher %v: List", c.objectType.String())) | ||||
| 	defer trace.LogIfLong(500 * time.Millisecond) | ||||
|  | ||||
| 	c.ready.wait() | ||||
|   | ||||
| @@ -23,6 +23,10 @@ import ( | ||||
| 	"reflect" | ||||
| 	"time" | ||||
|  | ||||
| 	etcd "github.com/coreos/etcd/client" | ||||
| 	"github.com/golang/glog" | ||||
| 	"golang.org/x/net/context" | ||||
|  | ||||
| 	"k8s.io/apimachinery/pkg/api/meta" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/conversion" | ||||
| @@ -30,14 +34,10 @@ import ( | ||||
| 	"k8s.io/apimachinery/pkg/watch" | ||||
| 	"k8s.io/apiserver/pkg/storage/etcd/metrics" | ||||
| 	utilcache "k8s.io/apiserver/pkg/util/cache" | ||||
| 	utiltrace "k8s.io/apiserver/pkg/util/trace" | ||||
| 	"k8s.io/kubernetes/pkg/api" | ||||
| 	"k8s.io/kubernetes/pkg/storage" | ||||
| 	etcdutil "k8s.io/kubernetes/pkg/storage/etcd/util" | ||||
| 	"k8s.io/kubernetes/pkg/util" | ||||
|  | ||||
| 	etcd "github.com/coreos/etcd/client" | ||||
| 	"github.com/golang/glog" | ||||
| 	"golang.org/x/net/context" | ||||
| ) | ||||
|  | ||||
| // Creates a new storage interface from the client | ||||
| @@ -92,7 +92,7 @@ func (h *etcdHelper) Versioner() storage.Versioner { | ||||
|  | ||||
| // Implements storage.Interface. | ||||
| func (h *etcdHelper) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error { | ||||
| 	trace := util.NewTrace("etcdHelper::Create " + getTypeName(obj)) | ||||
| 	trace := utiltrace.New("etcdHelper::Create " + getTypeName(obj)) | ||||
| 	defer trace.LogIfLong(250 * time.Millisecond) | ||||
| 	if ctx == nil { | ||||
| 		glog.Errorf("Context is nil") | ||||
| @@ -301,7 +301,7 @@ func (h *etcdHelper) GetToList(ctx context.Context, key string, resourceVersion | ||||
| 	if ctx == nil { | ||||
| 		glog.Errorf("Context is nil") | ||||
| 	} | ||||
| 	trace := util.NewTrace("GetToList " + getTypeName(listObj)) | ||||
| 	trace := utiltrace.New("GetToList " + getTypeName(listObj)) | ||||
| 	listPtr, err := meta.GetItemsPtr(listObj) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| @@ -338,7 +338,7 @@ func (h *etcdHelper) GetToList(ctx context.Context, key string, resourceVersion | ||||
|  | ||||
| // decodeNodeList walks the tree of each node in the list and decodes into the specified object | ||||
| func (h *etcdHelper) decodeNodeList(nodes []*etcd.Node, filter storage.FilterFunc, slicePtr interface{}) error { | ||||
| 	trace := util.NewTrace("decodeNodeList " + getTypeName(slicePtr)) | ||||
| 	trace := utiltrace.New("decodeNodeList " + getTypeName(slicePtr)) | ||||
| 	defer trace.LogIfLong(400 * time.Millisecond) | ||||
| 	v, err := conversion.EnforcePtr(slicePtr) | ||||
| 	if err != nil || v.Kind() != reflect.Slice { | ||||
| @@ -383,7 +383,7 @@ func (h *etcdHelper) List(ctx context.Context, key string, resourceVersion strin | ||||
| 	if ctx == nil { | ||||
| 		glog.Errorf("Context is nil") | ||||
| 	} | ||||
| 	trace := util.NewTrace("List " + getTypeName(listObj)) | ||||
| 	trace := utiltrace.New("List " + getTypeName(listObj)) | ||||
| 	defer trace.LogIfLong(400 * time.Millisecond) | ||||
| 	listPtr, err := meta.GetItemsPtr(listObj) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -25,18 +25,18 @@ import ( | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/coreos/etcd/clientv3" | ||||
| 	"github.com/golang/glog" | ||||
| 	"golang.org/x/net/context" | ||||
|  | ||||
| 	"k8s.io/apimachinery/pkg/api/meta" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/apimachinery/pkg/conversion" | ||||
| 	"k8s.io/apimachinery/pkg/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/watch" | ||||
| 	utiltrace "k8s.io/apiserver/pkg/util/trace" | ||||
| 	"k8s.io/kubernetes/pkg/storage" | ||||
| 	"k8s.io/kubernetes/pkg/storage/etcd" | ||||
| 	"k8s.io/kubernetes/pkg/util" | ||||
|  | ||||
| 	"github.com/coreos/etcd/clientv3" | ||||
| 	"github.com/golang/glog" | ||||
| 	"golang.org/x/net/context" | ||||
| ) | ||||
|  | ||||
| type store struct { | ||||
| @@ -216,7 +216,7 @@ func (s *store) conditionalDelete(ctx context.Context, key string, out runtime.O | ||||
| func (s *store) GuaranteedUpdate( | ||||
| 	ctx context.Context, key string, out runtime.Object, ignoreNotFound bool, | ||||
| 	precondtions *storage.Preconditions, tryUpdate storage.UpdateFunc, suggestion ...runtime.Object) error { | ||||
| 	trace := util.NewTrace(fmt.Sprintf("GuaranteedUpdate etcd3: %s", reflect.TypeOf(out).String())) | ||||
| 	trace := utiltrace.New(fmt.Sprintf("GuaranteedUpdate etcd3: %s", reflect.TypeOf(out).String())) | ||||
| 	defer trace.LogIfLong(500 * time.Millisecond) | ||||
|  | ||||
| 	v, err := conversion.EnforcePtr(out) | ||||
|   | ||||
| @@ -29,9 +29,9 @@ import ( | ||||
| 	"k8s.io/apimachinery/pkg/labels" | ||||
| 	"k8s.io/apimachinery/pkg/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/watch" | ||||
| 	utiltrace "k8s.io/apiserver/pkg/util/trace" | ||||
| 	"k8s.io/client-go/tools/cache" | ||||
| 	"k8s.io/client-go/util/clock" | ||||
| 	"k8s.io/kubernetes/pkg/util" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| @@ -281,7 +281,7 @@ func (w *watchCache) List() []interface{} { | ||||
| // waitUntilFreshAndBlock waits until cache is at least as fresh as given <resourceVersion>. | ||||
| // NOTE: This function acquired lock and doesn't release it. | ||||
| // You HAVE TO explicitly call w.RUnlock() after this function. | ||||
| func (w *watchCache) waitUntilFreshAndBlock(resourceVersion uint64, trace *util.Trace) error { | ||||
| func (w *watchCache) waitUntilFreshAndBlock(resourceVersion uint64, trace *utiltrace.Trace) error { | ||||
| 	startTime := w.clock.Now() | ||||
| 	go func() { | ||||
| 		// Wake us up when the time limit has expired.  The docs | ||||
| @@ -313,7 +313,7 @@ func (w *watchCache) waitUntilFreshAndBlock(resourceVersion uint64, trace *util. | ||||
| } | ||||
|  | ||||
| // WaitUntilFreshAndList returns list of pointers to <storeElement> objects. | ||||
| func (w *watchCache) WaitUntilFreshAndList(resourceVersion uint64, trace *util.Trace) ([]interface{}, uint64, error) { | ||||
| func (w *watchCache) WaitUntilFreshAndList(resourceVersion uint64, trace *utiltrace.Trace) ([]interface{}, uint64, error) { | ||||
| 	err := w.waitUntilFreshAndBlock(resourceVersion, trace) | ||||
| 	defer w.RUnlock() | ||||
| 	if err != nil { | ||||
| @@ -323,7 +323,7 @@ func (w *watchCache) WaitUntilFreshAndList(resourceVersion uint64, trace *util.T | ||||
| } | ||||
|  | ||||
| // WaitUntilFreshAndGet returns a pointers to <storeElement> object. | ||||
| func (w *watchCache) WaitUntilFreshAndGet(resourceVersion uint64, key string, trace *util.Trace) (interface{}, bool, uint64, error) { | ||||
| func (w *watchCache) WaitUntilFreshAndGet(resourceVersion uint64, key string, trace *utiltrace.Trace) (interface{}, bool, uint64, error) { | ||||
| 	err := w.waitUntilFreshAndBlock(resourceVersion, trace) | ||||
| 	defer w.RUnlock() | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -26,8 +26,8 @@ import ( | ||||
|  | ||||
| 	"github.com/golang/glog" | ||||
| 	"k8s.io/apimachinery/pkg/util/errors" | ||||
| 	utiltrace "k8s.io/apiserver/pkg/util/trace" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| 	"k8s.io/kubernetes/pkg/util" | ||||
| 	"k8s.io/kubernetes/pkg/util/workqueue" | ||||
| 	"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" | ||||
| 	"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/predicates" | ||||
| @@ -87,7 +87,7 @@ type genericScheduler struct { | ||||
| // If it succeeds, it will return the name of the node. | ||||
| // If it fails, it will return a Fiterror error with reasons. | ||||
| func (g *genericScheduler) Schedule(pod *v1.Pod, nodeLister algorithm.NodeLister) (string, error) { | ||||
| 	trace := util.NewTrace(fmt.Sprintf("Scheduling %s/%s", pod.Namespace, pod.Name)) | ||||
| 	trace := utiltrace.New(fmt.Sprintf("Scheduling %s/%s", pod.Namespace, pod.Name)) | ||||
| 	defer trace.LogIfLong(100 * time.Millisecond) | ||||
|  | ||||
| 	nodes, err := nodeLister.List() | ||||
|   | ||||
| @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and | ||||
| limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| package util | ||||
| package trace | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| @@ -35,7 +35,7 @@ type Trace struct { | ||||
| 	steps     []traceStep | ||||
| } | ||||
| 
 | ||||
| func NewTrace(name string) *Trace { | ||||
| func New(name string) *Trace { | ||||
| 	return &Trace{name, time.Now(), nil} | ||||
| } | ||||
| 
 | ||||
		Reference in New Issue
	
	Block a user