mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(cache): default metadata freshness to 24h, under the age gate
This commit is contained in:
@@ -252,7 +252,7 @@ upstream:
|
|||||||
Every `cleanup_interval` the cleanup run removes:
|
Every `cleanup_interval` the cleanup run removes:
|
||||||
|
|
||||||
- **Idle items.** Any cached item, artifact or metadata page, whose last request is older than `idle_ttl` (default `168h`, seven days). Each request, hit or miss, resets the clock. Set `idle_ttl: 0` to turn idle eviction off.
|
- **Idle items.** Any cached item, artifact or metadata page, whose last request is older than `idle_ttl` (default `168h`, seven days). Each request, hit or miss, resets the clock. Set `idle_ttl: 0` to turn idle eviction off.
|
||||||
- **Stale metadata.** Version lists, package documents and Go `.mod`/`.info` files past `default_ttl`. They refresh on the next request.
|
- **Stale metadata.** Version lists, package documents and Go `.mod`/`.info` files past `default_ttl` (default `24h`, below the 72h release-age gate clients apply). They refresh on the next request.
|
||||||
|
|
||||||
Artifacts (tarballs, wheels, module zips) never expire by age, so a package that clients keep requesting stays cached. Size-based LRU eviction at `max_size_bytes` is unchanged. Removed items keep their download history in the statistics.
|
Artifacts (tarballs, wheels, module zips) never expire by age, so a package that clients keep requesting stays cached. Size-based LRU eviction at `max_size_bytes` is unchanged. Removed items keep their download history in the statistics.
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -89,15 +89,15 @@ metadata:
|
|||||||
log_level: "warn" # GORM log level: silent, error, warn, info
|
log_level: "warn" # GORM log level: silent, error, warn, info
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
default_ttl: "168h" # Freshness window for metadata pages (version lists, packuments, .mod/.info); artifacts never expire by age
|
default_ttl: "24h" # Freshness window for metadata pages (version lists, packuments, .mod/.info); artifacts never expire by age
|
||||||
cleanup_interval: "1h"
|
cleanup_interval: "1h"
|
||||||
idle_ttl: "168h" # Remove cached items not requested for this long; "0" disables
|
idle_ttl: "168h" # Remove cached items not requested for this long; "0" disables
|
||||||
max_size_bytes: 536870912000 # 500GB
|
max_size_bytes: 536870912000 # 500GB
|
||||||
per_project_quota: 53687091200 # 50GB
|
per_project_quota: 53687091200 # 50GB
|
||||||
ttl_overrides:
|
ttl_overrides:
|
||||||
npm: "168h"
|
npm: "24h"
|
||||||
pip: "168h"
|
pip: "24h"
|
||||||
go: "168h"
|
go: "24h"
|
||||||
|
|
||||||
security:
|
security:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
@@ -375,15 +375,15 @@ migration:
|
|||||||
|
|
||||||
# Cache configuration
|
# Cache configuration
|
||||||
cache:
|
cache:
|
||||||
defaultTTL: "168h" # 7 days
|
defaultTTL: "24h" # Freshness window for metadata pages; keep below the 72h client release-age gate
|
||||||
cleanupInterval: "1h"
|
cleanupInterval: "1h"
|
||||||
idleTTL: "168h" # Remove cached items not requested for this long; "0" disables
|
idleTTL: "168h" # Remove cached items not requested for this long; "0" disables
|
||||||
maxSizeBytes: 536870912000 # 500GB
|
maxSizeBytes: 536870912000 # 500GB
|
||||||
perProjectQuota: 53687091200 # 50GB
|
perProjectQuota: 53687091200 # 50GB
|
||||||
ttlOverrides:
|
ttlOverrides:
|
||||||
npm: "168h"
|
npm: "24h"
|
||||||
pip: "168h"
|
pip: "24h"
|
||||||
go: "168h"
|
go: "24h"
|
||||||
|
|
||||||
# Security scanning configuration
|
# Security scanning configuration
|
||||||
security:
|
security:
|
||||||
|
|||||||
Vendored
+2
-1
@@ -12,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lukaszraczylo/gohoarder/pkg/analytics"
|
"github.com/lukaszraczylo/gohoarder/pkg/analytics"
|
||||||
|
hoarderconfig "github.com/lukaszraczylo/gohoarder/pkg/config"
|
||||||
"github.com/lukaszraczylo/gohoarder/pkg/errors"
|
"github.com/lukaszraczylo/gohoarder/pkg/errors"
|
||||||
"github.com/lukaszraczylo/gohoarder/pkg/events"
|
"github.com/lukaszraczylo/gohoarder/pkg/events"
|
||||||
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
||||||
@@ -172,7 +173,7 @@ func New(storage storage.StorageBackend, metadata metadata.MetadataStore, scanne
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.DefaultTTL == 0 {
|
if config.DefaultTTL == 0 {
|
||||||
config.DefaultTTL = 7 * 24 * time.Hour // 7 days default
|
config.DefaultTTL = hoarderconfig.DefaultMetadataTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.CleanupInterval == 0 {
|
if config.CleanupInterval == 0 {
|
||||||
|
|||||||
Vendored
+1
-1
@@ -370,7 +370,7 @@ func TestNew(t *testing.T) {
|
|||||||
|
|
||||||
// Verify defaults were set
|
// Verify defaults were set
|
||||||
if tt.config.DefaultTTL == 0 {
|
if tt.config.DefaultTTL == 0 {
|
||||||
assert.Equal(t, 7*24*time.Hour, manager.config.DefaultTTL)
|
assert.Equal(t, 24*time.Hour, manager.config.DefaultTTL)
|
||||||
}
|
}
|
||||||
if tt.config.CleanupInterval == 0 {
|
if tt.config.CleanupInterval == 0 {
|
||||||
assert.Equal(t, 1*time.Hour, manager.config.CleanupInterval)
|
assert.Equal(t, 1*time.Hour, manager.config.CleanupInterval)
|
||||||
|
|||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Clients gate on a 72h release age; a metadata page that stays fresh longer would hide the gate's inputs.
|
||||||
|
func TestMetadataEntryDefaultTTLIsBelowReleaseAgeGate(t *testing.T) {
|
||||||
|
h := newIdleHarness(t, Config{})
|
||||||
|
entry := h.get(t, "left-pad", "metadata")
|
||||||
|
|
||||||
|
require.NotNil(t, entry.Package.ExpiresAt)
|
||||||
|
require.Equal(t, 24*time.Hour, entry.Package.ExpiresAt.Sub(h.clock.Now()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMetadataEntryExplicitTTLWins(t *testing.T) {
|
||||||
|
h := newIdleHarness(t, Config{DefaultTTL: 6 * time.Hour})
|
||||||
|
entry := h.get(t, "left-pad", "metadata")
|
||||||
|
|
||||||
|
require.Equal(t, 6*time.Hour, entry.Package.ExpiresAt.Sub(h.clock.Now()))
|
||||||
|
}
|
||||||
@@ -133,6 +133,10 @@ type MySQLConfig struct {
|
|||||||
ParseTime bool `mapstructure:"parse_time" json:"parse_time"`
|
ParseTime bool `mapstructure:"parse_time" json:"parse_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultMetadataTTL is the freshness window for metadata pages. It stays below the 72h
|
||||||
|
// release-age gate clients apply, so a cached page never hides the entries the gate reads.
|
||||||
|
const DefaultMetadataTTL = 24 * time.Hour
|
||||||
|
|
||||||
// DefaultIdleTTL is how long a cached item can go unrequested before cleanup removes it.
|
// DefaultIdleTTL is how long a cached item can go unrequested before cleanup removes it.
|
||||||
const DefaultIdleTTL = 7 * 24 * time.Hour
|
const DefaultIdleTTL = 7 * 24 * time.Hour
|
||||||
|
|
||||||
@@ -355,15 +359,15 @@ func Default() *Config {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Cache: CacheConfig{
|
Cache: CacheConfig{
|
||||||
DefaultTTL: 7 * 24 * time.Hour,
|
DefaultTTL: DefaultMetadataTTL,
|
||||||
CleanupInterval: 1 * time.Hour,
|
CleanupInterval: 1 * time.Hour,
|
||||||
IdleTTL: DefaultIdleTTL,
|
IdleTTL: DefaultIdleTTL,
|
||||||
MaxSizeBytes: 500 * 1024 * 1024 * 1024, // 500GB
|
MaxSizeBytes: 500 * 1024 * 1024 * 1024, // 500GB
|
||||||
PerProjectQuota: 50 * 1024 * 1024 * 1024, // 50GB
|
PerProjectQuota: 50 * 1024 * 1024 * 1024, // 50GB
|
||||||
TTLOverrides: map[string]time.Duration{
|
TTLOverrides: map[string]time.Duration{
|
||||||
"npm": 7 * 24 * time.Hour,
|
"npm": DefaultMetadataTTL,
|
||||||
"pip": 7 * 24 * time.Hour,
|
"pip": DefaultMetadataTTL,
|
||||||
"go": 7 * 24 * time.Hour,
|
"go": DefaultMetadataTTL,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Security: SecurityConfig{
|
Security: SecurityConfig{
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultMetadataTTL(t *testing.T) {
|
||||||
|
require.Equal(t, 24*time.Hour, Default().Cache.DefaultTTL)
|
||||||
|
for registry, ttl := range Default().Cache.TTLOverrides {
|
||||||
|
require.LessOrEqual(t, ttl, 72*time.Hour, "override %s outlives the 72h release-age gate", registry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The shipped examples must not teach a metadata TTL longer than the release-age gate.
|
||||||
|
func TestShippedExamplesKeepMetadataTTLWithinGate(t *testing.T) {
|
||||||
|
for file, key := range map[string]string{
|
||||||
|
"../../config.yaml.example": `default_ttl`,
|
||||||
|
"../../helm/gohoarder/values.yaml": `defaultTTL`,
|
||||||
|
} {
|
||||||
|
raw, err := os.ReadFile(file)
|
||||||
|
require.NoError(t, err)
|
||||||
|
m := regexp.MustCompile(`(?m)^\s*` + key + `:\s*"?(\d+h)"?`).FindSubmatch(raw)
|
||||||
|
require.NotNil(t, m, "%s has no %s", file, key)
|
||||||
|
ttl, err := time.ParseDuration(string(m[1]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 24*time.Hour, ttl, file)
|
||||||
|
|
||||||
|
for _, o := range regexp.MustCompile(`(?m)^\s+(?:npm|pip|go):\s*"(\d+h)"`).FindAllSubmatch(raw, -1) {
|
||||||
|
d, err := time.ParseDuration(string(o[1]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.LessOrEqual(t, d, 72*time.Hour, "%s: override %s", file, o[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user