Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to ccache which is more maintained #1425

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/gorilla/sessions v1.2.0
github.com/h2non/gock v1.0.9
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/golang-lru v0.5.4
github.com/jenkins-x/go-scm v1.11.2
github.com/karlseguin/ccache/v2 v2.0.8
github.com/mattn/go-zglob v0.0.1
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.3
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ github.com/jstrachan/pipeline v0.21.1-0.20210811150720-45a86a5488af/go.mod h1:m8
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/karlseguin/ccache/v2 v2.0.8 h1:lT38cE//uyf6KcFok0rlgXtGFBWxkI6h/qg4tbFyDnA=
github.com/karlseguin/ccache/v2 v2.0.8/go.mod h1:2BDThcfQMf/c0jnZowt16eW405XIqZPavt+HoYEtcxQ=
github.com/karlseguin/expect v1.0.2-0.20190806010014-778a5f0c6003 h1:vJ0Snvo+SLMY72r5J4sEfkuE7AFbixEP2qRbEcum/wA=
github.com/karlseguin/expect v1.0.2-0.20190806010014-778a5f0c6003/go.mod h1:zNBxMY8P21owkeogJELCLeHIt+voOSduHYTFUbwRAV8=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
Expand Down Expand Up @@ -726,6 +730,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/vdemeester/k8s-pkg-credentialprovider v1.19.7/go.mod h1:K2nMO14cgZitdwBqdQps9tInJgcaXcU/7q5F59lpbNI=
github.com/vmware/govmomi v0.20.3/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU=
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0 h1:3UeQBvD0TFrlVjOeLOBz+CPAI8dnbqNSVwUwRrkp7vQ=
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0/go.mod h1:IXCdmsXIht47RaVFLEdVnh1t+pgYtTAhQGj73kz+2DM=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
9 changes: 5 additions & 4 deletions pkg/webhook/create_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func (s *Server) CreateAgent(l *logrus.Entry, owner, repo, ref string) (plugins.

key := owner + "/" + repo + "/" + ref
c := s.InRepoCache
if x, found := c.Get(key); found {
pa := x.(*plugins.Agent)
if x := c.Get(key); x != nil {
value := x.Value()
pa := value.(*plugins.Agent)
if pa != nil {
return *pa, nil
}
Expand All @@ -63,8 +64,8 @@ func (s *Server) CreateAgent(l *logrus.Entry, owner, repo, ref string) (plugins.
if err != nil {
return pc, errors.Wrapf(err, "failed to create agent")
}
c.Add(key, &pc)
duration := time.Now().Sub(start)
c.Set(key, &pc, time.Minute * 10)
duration := time.Since(start)
l.WithField("Duration", duration.String()).Info("created configAgent")
return pc, nil
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/webhook/create_agent_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

lru "github.com/hashicorp/golang-lru"
lru "github.com/karlseguin/ccache/v2"
"github.com/jenkins-x/go-scm/scm"
"github.com/jenkins-x/lighthouse/pkg/clients"
"github.com/jenkins-x/lighthouse/pkg/config"
Expand Down Expand Up @@ -72,8 +72,7 @@ func TestCreateAgentIntegration(t *testing.T) {
s.FileBrowsers, err = filebrowser.NewFileBrowsers(serverURL, fb)
assert.NoError(t, err)

s.InRepoCache, err = lru.New(5000)
assert.NoError(t, err)
s.InRepoCache = lru.New(lru.Configure())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default ccache sets the size to 5000.


s.ClientAgent = &plugins.ClientAgent{
BotName: "test-bot",
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"strconv"
"sync"

lru "github.com/hashicorp/golang-lru"
lru "github.com/karlseguin/ccache/v2"
"github.com/jenkins-x/go-scm/scm"
"github.com/jenkins-x/lighthouse/pkg/config"
"github.com/jenkins-x/lighthouse/pkg/filebrowser"
Expand Down
9 changes: 3 additions & 6 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/jenkins-x/lighthouse/pkg/externalplugincfg"

lru "github.com/hashicorp/golang-lru"
"github.com/jenkins-x/go-scm/scm"
"github.com/jenkins-x/lighthouse/pkg/clients"
"github.com/jenkins-x/lighthouse/pkg/config"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/jenkins-x/lighthouse/pkg/util"
"github.com/jenkins-x/lighthouse/pkg/version"
"github.com/jenkins-x/lighthouse/pkg/watcher"
lru "github.com/karlseguin/ccache/v2"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -509,18 +509,15 @@ func (o *WebhooksController) createHookServer() (*Server, error) {
return nil, errors.Wrapf(err, "failed to parse server URL %s", o.gitServerURL)
}

cache, err := lru.New(5000)
if err != nil {
return nil, errors.Wrapf(err, "failed to create in-repo LRU cache")
}
cache := lru.New(lru.Configure())

server := &Server{
ConfigAgent: configAgent,
Plugins: pluginAgent,
Metrics: promMetrics,
ServerURL: serverURL,
InRepoCache: cache,
//TokenGenerator: secretAgent.GetTokenGenerator(o.webhookSecretFile),
// TokenGenerator: secretAgent.GetTokenGenerator(o.webhookSecretFile),
}
return server, nil
}
Expand Down