Skip to content

Commit

Permalink
ff pkg (knative#6850)
Browse files Browse the repository at this point in the history
  • Loading branch information
vagababov committed Feb 14, 2020
1 parent 931ad54 commit d161feb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/knative.dev/pkg/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/knative.dev/pkg/metrics/metricstest/metricstest.go
Expand Up @@ -90,6 +90,21 @@ func CheckDistributionData(t test.T, name string, wantTags map[string]string, ex
}
}

// CheckDistributionRange checks the view with a name matching string name to verify that the DistributionData stats reported
// are tagged with the tags in wantTags and that expectedCount number of records were reported.
func CheckDistributionCount(t test.T, name string, wantTags map[string]string, expectedCount int64) {
t.Helper()
if row := checkExactlyOneRow(t, name); row != nil {
checkRowTags(t, row, name, wantTags)

if s, ok := row.Data.(*view.DistributionData); !ok {
t.Error("want DistributionData", "metric", name, "got", reflect.TypeOf(row.Data))
} else if s.Count != expectedCount {
t.Error("reporter count wrong", "metric", name, "got", s.Count, "want", expectedCount)
}
}
}

// CheckLastValueData checks the view with a name matching string name to verify that the LastValueData stats
// reported are tagged with the tags in wantTags and that wantValue matches reported last value.
func CheckLastValueData(t test.T, name string, wantTags map[string]string, wantValue float64) {
Expand Down
22 changes: 18 additions & 4 deletions vendor/knative.dev/pkg/tracker/enqueue.go
Expand Up @@ -131,6 +131,13 @@ func (i *impl) TrackReference(ref Reference, obj interface{}) error {
key := types.NamespacedName{Namespace: object.GetNamespace(), Name: object.GetName()}

i.m.Lock()
// Call the callback without the lock held.
var keys []types.NamespacedName
defer func(cb func(types.NamespacedName)) {
for _, key := range keys {
cb(key)
}
}(i.cb) // read i.cb with the lock held
defer i.m.Unlock()
if i.exact == nil {
i.exact = make(map[Reference]set)
Expand Down Expand Up @@ -158,7 +165,7 @@ func (i *impl) TrackReference(ref Reference, obj interface{}) error {
// The simplest way of eliminating such a window is to call the
// callback to "catch up" immediately following new
// registrations.
i.cb(key)
keys = append(keys, key)
}
// Overwrite the key with a new expiration.
l[key] = time.Now().Add(i.leaseDuration)
Expand Down Expand Up @@ -191,7 +198,7 @@ func (i *impl) TrackReference(ref Reference, obj interface{}) error {
// The simplest way of eliminating such a window is to call the
// callback to "catch up" immediately following new
// registrations.
i.cb(key)
keys = append(keys, key)
}
// Overwrite the key with a new expiration.
l[key] = matcher{
Expand Down Expand Up @@ -223,6 +230,13 @@ func (i *impl) OnChanged(obj interface{}) {
}

i.m.Lock()
// Call the callbacks without the lock held.
var keys []types.NamespacedName
defer func(cb func(types.NamespacedName)) {
for _, key := range keys {
cb(key)
}
}(i.cb) // read i.cb with the lock held
defer i.m.Unlock()

// Handle exact matches.
Expand All @@ -234,7 +248,7 @@ func (i *impl) OnChanged(obj interface{}) {
delete(s, key)
continue
}
i.cb(key)
keys = append(keys, key)
}
if len(s) == 0 {
delete(i.exact, ref)
Expand All @@ -253,7 +267,7 @@ func (i *impl) OnChanged(obj interface{}) {
continue
}
if m.selector.Matches(ls) {
i.cb(key)
keys = append(keys, key)
}
}
if len(s) == 0 {
Expand Down

0 comments on commit d161feb

Please sign in to comment.