Skip to content

Commit dff0075

Browse files
committed
tracing: add span for cacher.Get
Also updates tracing integration tests for cacher.GetList
1 parent 7ad1eaa commit dff0075

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,16 +693,23 @@ func (c *Cacher) Watch(ctx context.Context, key string, opts storage.ListOptions
693693

694694
// Get implements storage.Interface.
695695
func (c *Cacher) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error {
696+
ctx, span := tracing.Start(ctx, "cacher.Get",
697+
attribute.String("audit-id", audit.GetAuditIDTruncated(ctx)),
698+
attribute.String("key", key),
699+
attribute.String("resource-version", opts.ResourceVersion))
700+
defer span.End(500 * time.Millisecond)
696701
if opts.ResourceVersion == "" {
697702
// If resourceVersion is not specified, serve it from underlying
698703
// storage (for backward compatibility).
704+
span.AddEvent("About to Get from underlying storage")
699705
return c.storage.Get(ctx, key, opts, objPtr)
700706
}
701707

702708
if utilfeature.DefaultFeatureGate.Enabled(features.ResilientWatchCacheInitialization) {
703709
if !c.ready.check() {
704710
// If Cache is not initialized, delegate Get requests to storage
705711
// as described in https://kep.k8s.io/4568
712+
span.AddEvent("About to Get from underlying storage - cache not initialized")
706713
return c.storage.Get(ctx, key, opts, objPtr)
707714
}
708715
}
@@ -722,6 +729,7 @@ func (c *Cacher) Get(ctx context.Context, key string, opts storage.GetOptions, o
722729
if getRV == 0 && !c.ready.check() {
723730
// If Cacher is not yet initialized and we don't require any specific
724731
// minimal resource version, simply forward the request to storage.
732+
span.AddEvent("About to Get from underlying storage - cache not initialized and no resourceVersion set")
725733
return c.storage.Get(ctx, key, opts, objPtr)
726734
}
727735
if err := c.ready.wait(ctx); err != nil {
@@ -734,6 +742,7 @@ func (c *Cacher) Get(ctx context.Context, key string, opts storage.GetOptions, o
734742
return err
735743
}
736744

745+
span.AddEvent("About to fetch object from cache")
737746
obj, exists, readResourceVersion, err := c.watchCache.WaitUntilFreshAndGet(ctx, getRV, key)
738747
if err != nil {
739748
return err
@@ -856,7 +865,7 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
856865
}
857866
}
858867

859-
ctx, span := tracing.Start(ctx, "cacher list",
868+
ctx, span := tracing.Start(ctx, "cacher.GetList",
860869
attribute.String("audit-id", audit.GetAuditIDTruncated(ctx)),
861870
attribute.Stringer("type", c.groupResource))
862871
defer span.End(500 * time.Millisecond)

test/integration/apiserver/tracing/tracing_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,23 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
472472
"Writing http response done",
473473
},
474474
},
475+
{
476+
name: "cacher.Get",
477+
attributes: map[string]func(*commonv1.AnyValue) bool{
478+
"audit-id": func(v *commonv1.AnyValue) bool {
479+
return v.GetStringValue() != ""
480+
},
481+
"key": func(v *commonv1.AnyValue) bool {
482+
return v.GetStringValue() == "/minions/fake"
483+
},
484+
"resource-version": func(v *commonv1.AnyValue) bool {
485+
return v.GetStringValue() == ""
486+
},
487+
},
488+
events: []string{
489+
"About to Get from underlying storage",
490+
},
491+
},
475492
{
476493
name: "etcdserverpb.KV/Range",
477494
attributes: map[string]func(*commonv1.AnyValue) bool{
@@ -562,6 +579,22 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
562579
"Writing http response done",
563580
},
564581
},
582+
{
583+
name: "cacher.GetList",
584+
attributes: map[string]func(*commonv1.AnyValue) bool{
585+
"audit-id": func(v *commonv1.AnyValue) bool {
586+
return v.GetStringValue() != ""
587+
},
588+
"type": func(v *commonv1.AnyValue) bool {
589+
return v.GetStringValue() == "nodes"
590+
},
591+
},
592+
events: []string{
593+
"Ready",
594+
"Listed items from cache",
595+
"Filtered items",
596+
},
597+
},
565598
{
566599
name: "SerializeObject",
567600
attributes: map[string]func(*commonv1.AnyValue) bool{

0 commit comments

Comments
 (0)