Skip to content

Commit

Permalink
Add TTL for http error status.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Feb 20, 2024
1 parent add38e0 commit 7a4d673
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 13 deletions.
4 changes: 2 additions & 2 deletions charts/kubecache/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.2
version: 0.0.3

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.0.2"
appVersion: "0.0.3"

# Optional fields

Expand Down
2 changes: 1 addition & 1 deletion charts/kubecache/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
protocol: TCP
name: http
selector:
Expand Down
8 changes: 5 additions & 3 deletions charts/kubecache/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ customLabels:
resources:
requests:
cpu: 300m
memory: 100Mi
memory: 200Mi
ephemeral-storage: 200Mi
limits:
cpu: 2000m
Expand All @@ -98,6 +98,7 @@ affinity: {}
service:
type: ClusterIP
port: 9000
targetPort: 8080

podHealthCheck:
port: 8888
Expand All @@ -109,18 +110,19 @@ podHealthCheck:
configMapProperties:
#SECRET_ROLE_ARN: ""
#DEBUG_LOG: "true"
#LISTEN_ADDR: ":9000"
#LISTEN_ADDR: ":8080"
#BACKEND_URL: "http:https://config-server:9000"
#BACKEND_TIMEOUT: 300s
#CACHE_TTL: 300s
#CACHE_ERROR_TTL: 60s
#HEALTH_ADDR: ":8888"
#HEALTH_PATH: /health
#METRICS_ADDR: "":3000"
#METRICS_PATH: /metrics
#METRICS_NAMESPACE: ""
#METRICS_BUCKETS_LATENCY_HTTP: "0.00001, 0.000025, 0.00005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5, 10, 25, 50, 100, 250, 500, 1000"
#GROUPCACHE_PORT: :5000
#GROUPCACHE_SIZE_BYTES: "10000000"
#GROUPCACHE_SIZE_BYTES: "100000000"
#KUBEGROUP_METRICS_NAMESPACE: ""
#KUBEGROUP_DEBUG: "true"
#KUBEGROUP_LISTER_INTERVAL: 20s
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubecache/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestApp(t *testing.T) {

time.Sleep(100 * time.Millisecond) // give time for the application to start

u := "http:https://localhost:9000/test"
u := "http:https://localhost:8080/test"

if serverHits != 0 {
t.Errorf("non-zero server hits: %d", serverHits)
Expand Down
6 changes: 4 additions & 2 deletions cmd/kubecache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type config struct {
backendURL string
backendTimeout time.Duration
cacheTTL time.Duration
cacheErrorTTL time.Duration
healthAddr string
healthPath string
metricsAddr string
Expand All @@ -31,9 +32,10 @@ func newConfig(roleSessionName string) config {

return config{
debugLog: env.Bool("DEBUG_LOG", true),
listenAddr: env.String("LISTEN_ADDR", ":9000"),
listenAddr: env.String("LISTEN_ADDR", ":8080"),
backendURL: env.String("BACKEND_URL", "http:https://config-server:9000"),
cacheTTL: env.Duration("CACHE_TTL", 300*time.Second),
cacheErrorTTL: env.Duration("CACHE_ERROR_TTL", 60*time.Second),
backendTimeout: env.Duration("BACKEND_TIMEOUT", 300*time.Second),
healthAddr: env.String("HEALTH_ADDR", ":8888"),
healthPath: env.String("HEALTH_PATH", "/health"),
Expand All @@ -43,7 +45,7 @@ func newConfig(roleSessionName string) config {
metricsBucketsLatencyHTTP: env.Float64Slice("METRICS_BUCKETS_LATENCY_HTTP",
[]float64{0.00001, 0.000025, 0.00005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5, 10, 25, 50, 100, 250, 500, 1000}),
groupcachePort: env.String("GROUPCACHE_PORT", ":5000"),
groupcacheSizeBytes: env.Int64("GROUPCACHE_SIZE_BYTES", 10_000_000),
groupcacheSizeBytes: env.Int64("GROUPCACHE_SIZE_BYTES", 100_000_000),
kubegroupMetricsNamespace: env.String("KUBEGROUP_METRICS_NAMESPACE", ""),
kubegroupDebug: env.Bool("KUBEGROUP_DEBUG", true),
kubegroupListerInterval: env.Duration("KUBEGROUP_LISTER_INTERVAL", 20*time.Second),
Expand Down
12 changes: 10 additions & 2 deletions cmd/kubecache/groupcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ func startGroupcache(app *application) func() {

elap := time.Since(begin)

isErrorStatus := isHTTPError(status)

//
// log fetch status
//
traceID := span.SpanContext().TraceID().String()
if errFetch == nil {
if isHTTPError(status) {
if isErrorStatus {
//
// http error
//
Expand Down Expand Up @@ -134,7 +136,13 @@ func startGroupcache(app *application) func() {
return errJ
}

expire := time.Now().Add(app.cfg.cacheTTL)
var ttl time.Duration
if isErrorStatus {
ttl = app.cfg.cacheErrorTTL
} else {
ttl = app.cfg.cacheTTL
}
expire := time.Now().Add(ttl)

return dest.SetBytes(data, expire)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubecache/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const version = "0.0.2"
const version = "0.0.3"
14 changes: 13 additions & 1 deletion docs/index.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
apiVersion: v1
entries:
kubecache:
- apiVersion: v2
appVersion: 0.0.3
created: "2024-02-19T21:39:22.8439581-03:00"
description: Helm chart to install kubecache on kubernetes
digest: 0c72506d127a11190971893ade043ba3d3fb380c0030fb0fee7e8dec6db32ecc
name: kubecache
sources:
- https://github.com/udhos/kubecache
type: application
urls:
- https://udhos.github.io/kubecache/kubecache-0.0.3.tgz
version: 0.0.3
- apiVersion: v2
appVersion: 0.0.2
created: "2024-02-19T08:12:22.991107964-03:00"
Expand Down Expand Up @@ -37,4 +49,4 @@ entries:
urls:
- https://udhos.github.io/kubecache/kubecache-0.0.0.tgz
version: 0.0.0
generated: "2024-02-19T08:12:22.990652789-03:00"
generated: "2024-02-19T21:39:22.84275326-03:00"
Binary file added docs/kubecache-0.0.3.tgz
Binary file not shown.

0 comments on commit 7a4d673

Please sign in to comment.