Skip to content

Commit

Permalink
Update the deps
Browse files Browse the repository at this point in the history
  • Loading branch information
houshengbo committed May 17, 2024
1 parent 6043ef8 commit d8184f2
Show file tree
Hide file tree
Showing 11 changed files with 1,250 additions and 18 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/golang-lru v1.0.2
go.opencensus.io v0.24.0
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.27.0
Expand All @@ -14,11 +13,11 @@ require (
k8s.io/client-go v0.29.2
k8s.io/code-generator v0.29.2
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00
knative.dev/caching v0.0.0-20240513135106-1a6c1c714c18
knative.dev/caching v0.0.0-20240516131342-69083faf77fc
knative.dev/hack v0.0.0-20240507013718-68e3bfb39d11
knative.dev/networking v0.0.0-20240508055612-25012a498278
knative.dev/pkg v0.0.0-20240513091600-b1fd04d5c458
knative.dev/serving v0.41.1-0.20240509134134-3789ff9cc0f0
knative.dev/networking v0.0.0-20240516132600-507209b2bf6f
knative.dev/pkg v0.0.0-20240516194901-4a9c38d654dc
knative.dev/serving v0.41.0
)

require (
Expand Down Expand Up @@ -82,6 +81,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jmespath/go-jmespath v0.4.1-0.20220621161143-b0104c826a24 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -799,16 +799,16 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/caching v0.0.0-20240513135106-1a6c1c714c18 h1:heXgTE/8kVJV/YmYRaCm9PXhRvysqWA6XdqWxWiS37Q=
knative.dev/caching v0.0.0-20240513135106-1a6c1c714c18/go.mod h1:RaoremM8tuvy5M73QYWAIwwe8bq/8IFBPgajle9nxzg=
knative.dev/caching v0.0.0-20240516131342-69083faf77fc h1:lHETLEA/8O599yQEe0qSJgYGUySwwiRcBvge1bl3eRg=

Check failure on line 802 in go.sum

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[woke] reported by reviewdog 🐶 [error] `GUyS` may be insensitive, use `folks`, `people`, `you all`, `y'all`, `yinz` instead Raw Output: go.sum:802:81: [error] `GUyS` may be insensitive, use `folks`, `people`, `you all`, `y'all`, `yinz` instead
knative.dev/caching v0.0.0-20240516131342-69083faf77fc/go.mod h1:ExMA0ZLLFh7jDSVjFvS55CFCkiKfiqJxdP2A9OoQhGE=
knative.dev/hack v0.0.0-20240507013718-68e3bfb39d11 h1:CYoD72R8/R35REjeY2nnWfBak+Q3f+NxXwEfwcID1eU=
knative.dev/hack v0.0.0-20240507013718-68e3bfb39d11/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/networking v0.0.0-20240508055612-25012a498278 h1:uToI/YqBS1oQ0XIgcNXpAJ0qdeghBN/rREPYN/nwtNs=
knative.dev/networking v0.0.0-20240508055612-25012a498278/go.mod h1:ySd8prgXDd7V5wEE80T800yeBOfVncAWp3nFTbZl34I=
knative.dev/pkg v0.0.0-20240513091600-b1fd04d5c458 h1:ESofRToj3xFQfKd5rlwd3EHd7G/CbVpchrUsw1HzI1w=
knative.dev/pkg v0.0.0-20240513091600-b1fd04d5c458/go.mod h1:fkgcK/71v1QSJza7pCOxtuk7zSsWYPQ7eiuX8M2wXxs=
knative.dev/serving v0.41.1-0.20240509134134-3789ff9cc0f0 h1:0CKFqFj8/7LZC4TX/VCbrT3d3J7BJKRIay3jt49D+UE=
knative.dev/serving v0.41.1-0.20240509134134-3789ff9cc0f0/go.mod h1:5E+DXwl+tmCpfKVV6Qmn3n6O9q5FPeTHtY5BP0P5Oes=
knative.dev/networking v0.0.0-20240516132600-507209b2bf6f h1:+K321QB+dTAArNPHRfhrIzDcG0nwX3GrqO3IzBzAJF8=
knative.dev/networking v0.0.0-20240516132600-507209b2bf6f/go.mod h1:bKoqFoKxbixmcRyN8LKt4ye+tyZ/NNw2xmcyFU03lsM=
knative.dev/pkg v0.0.0-20240516194901-4a9c38d654dc h1:aiFq7jcBYaZlPxJkbJSNOg9Azcbgfu8dCrh2a/pkdN0=
knative.dev/pkg v0.0.0-20240516194901-4a9c38d654dc/go.mod h1:fkgcK/71v1QSJza7pCOxtuk7zSsWYPQ7eiuX8M2wXxs=
knative.dev/serving v0.41.0 h1:A431GizCZri8Pteuf6/U5CEBgx9bY/ja34Ks8/C06ZI=
knative.dev/serving v0.41.0/go.mod h1:RigKdoO6pY+uyHvQLTNIvgVv5HHVhcysSHx6Cl1k31s=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: build

on:
push:
branches:
tags:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: set up go 1.19
uses: actions/setup-go@v1
with:
go-version: 1.19
id: go

- name: checkout
uses: actions/checkout@v2

- name: build and test
run: |
go test -timeout=60s -race
go build -race
- name: install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.50.1

- name: run golangci-lint
run: $GITHUB_WORKSPACE/golangci-lint run --out-format=github-actions
305 changes: 305 additions & 0 deletions third_party/VENDOR-LICENSE/github.com/hashicorp/golang-lru/2q_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
package lru

import (
"testing"
)

func Benchmark2Q_Rand(b *testing.B) {
l, err := New2Q(8192)
if err != nil {
b.Fatalf("err: %v", err)
}

trace := make([]int64, b.N*2)
for i := 0; i < b.N*2; i++ {
trace[i] = getRand(b) % 32768
}

b.ResetTimer()

var hit, miss int
for i := 0; i < 2*b.N; i++ {
if i%2 == 0 {
l.Add(trace[i], trace[i])
} else {
_, ok := l.Get(trace[i])
if ok {
hit++
} else {
miss++
}
}
}
b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss))
}

func Benchmark2Q_Freq(b *testing.B) {
l, err := New2Q(8192)
if err != nil {
b.Fatalf("err: %v", err)
}

trace := make([]int64, b.N*2)
for i := 0; i < b.N*2; i++ {
if i%2 == 0 {
trace[i] = getRand(b) % 16384
} else {
trace[i] = getRand(b) % 32768
}
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
l.Add(trace[i], trace[i])
}
var hit, miss int
for i := 0; i < b.N; i++ {
_, ok := l.Get(trace[i])
if ok {
hit++
} else {
miss++
}
}
b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(miss))
}

func Test2Q_RandomOps(t *testing.T) {
size := 128
l, err := New2Q(128)
if err != nil {
t.Fatalf("err: %v", err)
}

n := 200000
for i := 0; i < n; i++ {
key := getRand(t) % 512
r := getRand(t)
switch r % 3 {
case 0:
l.Add(key, key)
case 1:
l.Get(key)
case 2:
l.Remove(key)
}

if l.recent.Len()+l.frequent.Len() > size {
t.Fatalf("bad: recent: %d freq: %d",
l.recent.Len(), l.frequent.Len())
}
}
}

func Test2Q_Get_RecentToFrequent(t *testing.T) {
l, err := New2Q(128)
if err != nil {
t.Fatalf("err: %v", err)
}

// Touch all the entries, should be in t1
for i := 0; i < 128; i++ {
l.Add(i, i)
}
if n := l.recent.Len(); n != 128 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 0 {
t.Fatalf("bad: %d", n)
}

// Get should upgrade to t2
for i := 0; i < 128; i++ {
_, ok := l.Get(i)
if !ok {
t.Fatalf("missing: %d", i)
}
}
if n := l.recent.Len(); n != 0 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 128 {
t.Fatalf("bad: %d", n)
}

// Get be from t2
for i := 0; i < 128; i++ {
_, ok := l.Get(i)
if !ok {
t.Fatalf("missing: %d", i)
}
}
if n := l.recent.Len(); n != 0 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 128 {
t.Fatalf("bad: %d", n)
}
}

func Test2Q_Add_RecentToFrequent(t *testing.T) {
l, err := New2Q(128)
if err != nil {
t.Fatalf("err: %v", err)
}

// Add initially to recent
l.Add(1, 1)
if n := l.recent.Len(); n != 1 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 0 {
t.Fatalf("bad: %d", n)
}

// Add should upgrade to frequent
l.Add(1, 1)
if n := l.recent.Len(); n != 0 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 1 {
t.Fatalf("bad: %d", n)
}

// Add should remain in frequent
l.Add(1, 1)
if n := l.recent.Len(); n != 0 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 1 {
t.Fatalf("bad: %d", n)
}
}

func Test2Q_Add_RecentEvict(t *testing.T) {
l, err := New2Q(4)
if err != nil {
t.Fatalf("err: %v", err)
}

// Add 1,2,3,4,5 -> Evict 1
l.Add(1, 1)
l.Add(2, 2)
l.Add(3, 3)
l.Add(4, 4)
l.Add(5, 5)
if n := l.recent.Len(); n != 4 {
t.Fatalf("bad: %d", n)
}
if n := l.recentEvict.Len(); n != 1 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 0 {
t.Fatalf("bad: %d", n)
}

// Pull in the recently evicted
l.Add(1, 1)
if n := l.recent.Len(); n != 3 {
t.Fatalf("bad: %d", n)
}
if n := l.recentEvict.Len(); n != 1 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 1 {
t.Fatalf("bad: %d", n)
}

// Add 6, should cause another recent evict
l.Add(6, 6)
if n := l.recent.Len(); n != 3 {
t.Fatalf("bad: %d", n)
}
if n := l.recentEvict.Len(); n != 2 {
t.Fatalf("bad: %d", n)
}
if n := l.frequent.Len(); n != 1 {
t.Fatalf("bad: %d", n)
}
}

func Test2Q(t *testing.T) {
l, err := New2Q(128)
if err != nil {
t.Fatalf("err: %v", err)
}

for i := 0; i < 256; i++ {
l.Add(i, i)
}
if l.Len() != 128 {
t.Fatalf("bad len: %v", l.Len())
}

for i, k := range l.Keys() {
if v, ok := l.Get(k); !ok || v != k || v != i+128 {
t.Fatalf("bad key: %v", k)
}
}
for i := 0; i < 128; i++ {
_, ok := l.Get(i)
if ok {
t.Fatalf("should be evicted")
}
}
for i := 128; i < 256; i++ {
_, ok := l.Get(i)
if !ok {
t.Fatalf("should not be evicted")
}
}
for i := 128; i < 192; i++ {
l.Remove(i)
_, ok := l.Get(i)
if ok {
t.Fatalf("should be deleted")
}
}

l.Purge()
if l.Len() != 0 {
t.Fatalf("bad len: %v", l.Len())
}
if _, ok := l.Get(200); ok {
t.Fatalf("should contain nothing")
}
}

// Test that Contains doesn't update recent-ness
func Test2Q_Contains(t *testing.T) {
l, err := New2Q(2)
if err != nil {
t.Fatalf("err: %v", err)
}

l.Add(1, 1)
l.Add(2, 2)
if !l.Contains(1) {
t.Errorf("1 should be contained")
}

l.Add(3, 3)
if l.Contains(1) {
t.Errorf("Contains should not have updated recent-ness of 1")
}
}

// Test that Peek doesn't update recent-ness
func Test2Q_Peek(t *testing.T) {
l, err := New2Q(2)
if err != nil {
t.Fatalf("err: %v", err)
}

l.Add(1, 1)
l.Add(2, 2)
if v, ok := l.Peek(1); !ok || v != 1 {
t.Errorf("1 should be set to 1: %v, %v", v, ok)
}

l.Add(3, 3)
if l.Contains(1) {
t.Errorf("should not have updated recent-ness of 1")
}
}
Loading

0 comments on commit d8184f2

Please sign in to comment.