Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb14b68

Browse files
committed
Improve tracing information by deleting traces from etcd cache and adding information to traces from generic registry.
1 parent 6ffe46a commit eb14b68

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

pkg/registry/generic/etcd/etcd.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package etcd
1818

1919
import (
2020
"fmt"
21+
"reflect"
2122
"time"
2223

2324
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
@@ -146,9 +147,9 @@ func (e *Etcd) List(ctx api.Context, label labels.Selector, field fields.Selecto
146147

147148
// ListPredicate returns a list of all the items matching m.
148149
func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object, error) {
149-
trace := util.NewTrace("List")
150-
defer trace.LogIfLong(time.Second)
151150
list := e.NewListFunc()
151+
trace := util.NewTrace("List " + reflect.TypeOf(list).String())
152+
defer trace.LogIfLong(600 * time.Millisecond)
152153
if name, ok := m.MatchesSingle(); ok {
153154
trace.Step("About to read single object")
154155
key, err := e.KeyFunc(ctx, name)
@@ -201,7 +202,7 @@ func (e *Etcd) CreateWithName(ctx api.Context, name string, obj runtime.Object)
201202

202203
// Create inserts a new item according to the unique key from the object.
203204
func (e *Etcd) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
204-
trace := util.NewTrace("Create")
205+
trace := util.NewTrace("Create " + reflect.TypeOf(obj).String())
205206
defer trace.LogIfLong(time.Second)
206207
if err := rest.BeforeCreate(e.CreateStrategy, ctx, obj); err != nil {
207208
return nil, err
@@ -268,7 +269,7 @@ func (e *Etcd) UpdateWithName(ctx api.Context, name string, obj runtime.Object)
268269
// or an error. If the registry allows create-on-update, the create flow will be executed.
269270
// A bool is returned along with the object and any errors, to indicate object creation.
270271
func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
271-
trace := util.NewTrace("Update")
272+
trace := util.NewTrace("Update " + reflect.TypeOf(obj).String())
272273
defer trace.LogIfLong(time.Second)
273274
name, err := e.ObjectNameFunc(obj)
274275
if err != nil {
@@ -358,9 +359,9 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
358359

359360
// Get retrieves the item from etcd.
360361
func (e *Etcd) Get(ctx api.Context, name string) (runtime.Object, error) {
361-
trace := util.NewTrace("Get")
362-
defer trace.LogIfLong(time.Second)
363362
obj := e.NewFunc()
363+
trace := util.NewTrace("Get " + reflect.TypeOf(obj).String())
364+
defer trace.LogIfLong(time.Second)
364365
key, err := e.KeyFunc(ctx, name)
365366
if err != nil {
366367
return nil, err
@@ -380,14 +381,14 @@ func (e *Etcd) Get(ctx api.Context, name string) (runtime.Object, error) {
380381

381382
// Delete removes the item from etcd.
382383
func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions) (runtime.Object, error) {
383-
trace := util.NewTrace("Delete")
384-
defer trace.LogIfLong(time.Second)
385384
key, err := e.KeyFunc(ctx, name)
386385
if err != nil {
387386
return nil, err
388387
}
389388

390389
obj := e.NewFunc()
390+
trace := util.NewTrace("Delete " + reflect.TypeOf(obj).String())
391+
defer trace.LogIfLong(time.Second)
391392
trace.Step("About to read object")
392393
if err := e.Helper.ExtractObj(key, obj, false); err != nil {
393394
return nil, etcderr.InterpretDeleteError(err, e.EndpointName, name)

pkg/tools/etcd_helper.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,15 @@ type etcdCache interface {
228228
}
229229

230230
func (h *EtcdHelper) getFromCache(index uint64) (runtime.Object, bool) {
231-
trace := util.NewTrace("getFromCache")
232-
defer trace.LogIfLong(200 * time.Microsecond)
233231
startTime := time.Now()
234232
defer func() {
235233
cacheGetLatency.Observe(float64(time.Since(startTime) / time.Microsecond))
236234
}()
237235
obj, found := h.cache.Get(index)
238-
trace.Step("Raw get done")
239236
if found {
240237
// We should not return the object itself to avoid poluting the cache if someone
241238
// modifies returned values.
242239
objCopy, err := api.Scheme.DeepCopy(obj)
243-
trace.Step("Deep copied")
244240
if err != nil {
245241
glog.Errorf("Error during DeepCopy of cached object: %q", err)
246242
return nil, false

0 commit comments

Comments
 (0)