Skip to content

Commit

Permalink
Use go-githubapp client caching (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvoboda authored Jun 24, 2019
1 parent 7f5229c commit 243eef8
Show file tree
Hide file tree
Showing 14 changed files with 1,412 additions and 34 deletions.
31 changes: 29 additions & 2 deletions Gopkg.lock

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

5 changes: 5 additions & 0 deletions config/policy-bot.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ logging:
# Choose from: debug, info, warn, error
level: debug

# Options for the HTTP Cache
cache:
# The maximum size of the cache (specified in human readable units)
max_size: 50 MB

# Options for connecting to GitHub
github:
# The URL of the GitHub homepage
Expand Down
6 changes: 6 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package server

import (
"github.com/c2h5oh/datasize"
"github.com/palantir/go-baseapp/baseapp"
"github.com/palantir/go-baseapp/baseapp/datadog"
"github.com/palantir/go-githubapp/githubapp"
Expand All @@ -27,6 +28,7 @@ import (
type Config struct {
Server baseapp.HTTPConfig `yaml:"server"`
Logging LoggingConfig `yaml:"logging"`
Cache CachingConfig `yaml:"cache"`
Github githubapp.Config `yaml:"github"`
Sessions SessionsConfig `yaml:"sessions"`
Options handler.PullEvaluationOptions `yaml:"options"`
Expand All @@ -39,6 +41,10 @@ type LoggingConfig struct {
Text bool `yaml:"text" json:"text"`
}

type CachingConfig struct {
MaxSize datasize.ByteSize `yaml:"max_size"`
}

type SessionsConfig struct {
Key string `yaml:"key"`
Lifetime string `yaml:"lifetime"`
Expand Down
11 changes: 11 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (

"github.com/alexedwards/scs"
"github.com/bluekeyes/hatpear"
"github.com/c2h5oh/datasize"
"github.com/die-net/lrucache"
"github.com/gregjones/httpcache"
"github.com/palantir/go-baseapp/baseapp"
"github.com/palantir/go-baseapp/baseapp/datadog"
"github.com/palantir/go-githubapp/githubapp"
Expand Down Expand Up @@ -76,10 +79,18 @@ func New(c *Config) (*Server, error) {
return nil, errors.Wrap(err, "failed to initialize base server")
}

maxSize := int64(50 * datasize.MB)
if c.Cache.MaxSize != 0 {
maxSize = int64(c.Cache.MaxSize)
}

userAgent := fmt.Sprintf("%s/%s", c.Options.AppName, version.GetVersion())
cc, err := githubapp.NewDefaultCachingClientCreator(
c.Github,
githubapp.WithClientUserAgent(userAgent),
githubapp.WithClientCaching(true, func() httpcache.Cache {
return lrucache.New(maxSize, 0)
}),
githubapp.WithClientMiddleware(
githubapp.ClientLogging(zerolog.DebugLevel),
githubapp.ClientMetrics(base.Registry()),
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/c2h5oh/datasize/LICENSE

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

217 changes: 217 additions & 0 deletions vendor/github.com/c2h5oh/datasize/datasize.go

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

Loading

0 comments on commit 243eef8

Please sign in to comment.