Skip to content

Commit

Permalink
use constant for maxGetEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
aditsachde committed Sep 29, 2024
1 parent bd97a0b commit 4eb885e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/ctmonitor/fastly.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func FastlyServe(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Reque
cache: make(map[string]*CacheEntry),
requests: 0,
}
f := newFetch(s, maskSize)
f := newFetch(s, maskSize, 75) // Limit get-entries to 75

if r.URL.Path == "/ct/v1/get-sth-consistency" {
FastlyWrapper(f.get_sth_consistency)(ctx, w, r)
Expand Down
12 changes: 7 additions & 5 deletions internal/ctmonitor/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import (
)

type Fetch struct {
s Storage
maskSize int
s Storage
maskSize int
maxGetEntry int
}

func newFetch(storage Storage, maskSize int) Fetch {
func newFetch(storage Storage, maskSize, maxGetEntry int) Fetch {
return Fetch{
s: storage,
maskSize: maskSize,
s: storage,
maskSize: maskSize,
maxGetEntry: maxGetEntry,
}
}

Expand Down
7 changes: 4 additions & 3 deletions internal/ctmonitor/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
// TODO: Evaluate if the context is actually needed
func Start(ctx context.Context, tileStoreDir string, tileStoreUrl string, maskSize int) (http.Handler, error) {
var f Fetch
maxGetEntry := 1024

if tileStoreDir != "" {
storage := &FsStorage{root: tileStoreDir}
f = newFetch(storage, maskSize)
f = newFetch(storage, maskSize, maxGetEntry)
} else {
storage := &UrlStorage{urlPrefix: tileStoreUrl}
f = newFetch(storage, maskSize)
f = newFetch(storage, maskSize, maxGetEntry)
}

// Wrap the HTTP handler function with OTel instrumentation
Expand Down Expand Up @@ -282,7 +283,7 @@ func (f Fetch) get_entries(ctx context.Context, reqBody io.ReadCloser, query url
}

// Limit the number of entries fetched at once
const limit = 75
limit := int64(f.maxGetEntry)
if end-start > limit {
end = start + limit
}
Expand Down

0 comments on commit 4eb885e

Please sign in to comment.