Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 96ad4b4

Browse files
authored
Merge pull request #1190 from eparis/disk-cache
Write github cache to disk
2 parents 2cae41c + bb89026 commit 96ad4b4

File tree

40 files changed

+2158
-2006
lines changed

40 files changed

+2158
-2006
lines changed

hack/verify-flags/known-flags.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ forward-services
3535
generated-files-config
3636
health-check-path
3737
healthz-port
38+
http-cache-dir
39+
http-cache-size
3840
http-port
3941
insecure-registry
4042
insecure-skip-verify
@@ -92,7 +94,6 @@ udp-services-configmap
9294
unit-status-context
9395
url-list
9496
use-cluster-credentials
95-
use-http-cache
9697
use-ip
9798
use-kubernetes-cluster-service
9899
use-real-cloud

mungegithub/Godeps/Godeps.json

Lines changed: 33 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mungegithub/github/github.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636
"github.com/golang/glog"
3737
"github.com/google/go-github/github"
3838
"github.com/gregjones/httpcache"
39+
"github.com/gregjones/httpcache/diskcache"
40+
"github.com/peterbourgon/diskv"
3941
"github.com/spf13/cobra"
4042
"golang.org/x/oauth2"
4143
)
@@ -150,6 +152,9 @@ type Config struct {
150152
Address string // if a munger runs a web server, where it should live
151153
WWWRoot string
152154

155+
HTTPCacheDir string
156+
HTTPCacheSize uint64
157+
153158
MinPRNumber int
154159
MaxPRNumber int
155160

@@ -159,8 +164,6 @@ type Config struct {
159164
// Defaults to 30 seconds.
160165
PendingWaitTime *time.Duration
161166

162-
useMemoryCache bool
163-
164167
// When we clear analytics we store the last values here
165168
lastAnalytics analytics
166169
analytics analytics
@@ -292,13 +295,14 @@ func (config *Config) AddRootFlags(cmd *cobra.Command) {
292295
cmd.PersistentFlags().IntVar(&config.MinPRNumber, "min-pr-number", 0, "The minimum PR to start with")
293296
cmd.PersistentFlags().IntVar(&config.MaxPRNumber, "max-pr-number", maxInt, "The maximum PR to start with")
294297
cmd.PersistentFlags().BoolVar(&config.DryRun, "dry-run", true, "If true, don't actually merge anything")
295-
cmd.PersistentFlags().BoolVar(&config.useMemoryCache, "use-http-cache", true, "If true, use a client side HTTP cache for API requests.")
296298
cmd.PersistentFlags().StringVar(&config.Org, "organization", "kubernetes", "The github organization to scan")
297299
cmd.PersistentFlags().StringVar(&config.Project, "project", "kubernetes", "The github project to scan")
298300
cmd.PersistentFlags().StringVar(&config.state, "state", "open", "State of PRs to process: 'open', 'all', etc")
299301
cmd.PersistentFlags().StringSliceVar(&config.labels, "labels", []string{}, "CSV list of label which should be set on processed PRs. Unset is all labels.")
300302
cmd.PersistentFlags().StringVar(&config.Address, "address", ":8080", "The address to listen on for HTTP Status")
301303
cmd.PersistentFlags().StringVar(&config.WWWRoot, "www", "www", "Path to static web files to serve from the webserver")
304+
cmd.PersistentFlags().StringVar(&config.HTTPCacheDir, "http-cache-dir", "", "Path to directory where github data can be cached across restarts, if unset use in memory cache")
305+
cmd.PersistentFlags().Uint64Var(&config.HTTPCacheSize, "http-cache-size", 1000, "Maximum size for the HTTP cache (in MB)")
302306
cmd.PersistentFlags().AddGoFlagSet(goflag.CommandLine)
303307
}
304308

@@ -337,17 +341,26 @@ func (config *Config) PreExecute() error {
337341
config.apiLimit = callLimitTransport
338342
transport = callLimitTransport
339343

340-
if config.useMemoryCache {
341-
t := httpcache.NewMemoryCacheTransport()
342-
t.Transport = transport
343-
344-
zeroCacheTransport := &zeroCacheRoundTripper{
345-
delegate: t,
346-
}
344+
var t *httpcache.Transport
345+
if config.HTTPCacheDir != "" {
346+
maxBytes := config.HTTPCacheSize * 1000000 // convert M to B. This is storage so not base 2...
347+
d := diskv.New(diskv.Options{
348+
BasePath: config.HTTPCacheDir,
349+
CacheSizeMax: maxBytes,
350+
})
351+
cache := diskcache.NewWithDiskv(d)
352+
t = httpcache.NewTransport(cache)
353+
} else {
354+
t = httpcache.NewMemoryCacheTransport()
355+
}
356+
t.Transport = transport
347357

348-
transport = zeroCacheTransport
358+
zeroCacheTransport := &zeroCacheRoundTripper{
359+
delegate: t,
349360
}
350361

362+
transport = zeroCacheTransport
363+
351364
if len(token) > 0 {
352365
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
353366
transport = &oauth2.Transport{

mungegithub/submit-queue/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ spec:
2020
- --weak-stable-jobs=kubernetes-kubemark-500-gce
2121
- --required-contexts="Jenkins GCE Node e2e"
2222
- --number-of-old-test-results=5
23+
- --http-cache-dir=/cache/httpcache
2324
image: gcr.io/google_containers/submit-queue:2016-05-24-86f86cd
2425
ports:
2526
- name: status
@@ -34,6 +35,8 @@ spec:
3435
name: secret-volume
3536
- mountPath: /gitrepos
3637
name: kubernetes-repo
38+
- mountPath: /cache
39+
name: cache-volume
3740
volumes:
3841
- name: secret-volume
3942
secret:
@@ -42,3 +45,6 @@ spec:
4245
gitRepo:
4346
repository: "https://github.com/kubernetes/kubernetes.git"
4447
revision: "master"
48+
- name: cache-volume
49+
persistentVolumeClaim:
50+
claimName: submit-queue-cache

mungegithub/submit-queue/pv.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
labels:
5+
app: submit-queue
6+
name: submit-queue-cache
7+
spec:
8+
capacity:
9+
storage: 10Gi
10+
accessModes:
11+
- ReadWriteOnce
12+
persistentVolumeReclaimPolicy: Retain
13+
gcePersistentDisk:
14+
pdName: submit-queue
15+
fsType: ext4

mungegithub/submit-queue/pvc.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kind: PersistentVolumeClaim
2+
apiVersion: v1
3+
metadata:
4+
name: submit-queue-cache
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 10Gi

mungegithub/vendor/github.com/google/btree/.travis.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)