Skip to content

Commit

Permalink
Remove rate limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Apr 16, 2024
1 parent 01c4299 commit 737f3b1
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 47 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.3.6
version: 0.4.0

# 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.3.6"
appVersion: "0.4.0"

# Optional fields

Expand Down
2 changes: 0 additions & 2 deletions charts/kubecache/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ configMapProperties:
#KUBEGROUP_METRICS_NAMESPACE: ""
#KUBEGROUP_DEBUG: "true"
#KUBEGROUP_LABEL_SELECTOR: "app=kubecache"
#RATELIMIT_INTERVAL: 10s
#RATELIMIT_SLOTS: "5"
OTEL_TRACES_SAMPLER: parentbased_traceidratio
OTEL_TRACES_SAMPLER_ARG: "0.01"
# pick one of OTEL_SERVICE_NAME or OTEL_RESOURCE_ATTRIBUTES
Expand Down
19 changes: 1 addition & 18 deletions cmd/kubecache/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/modernprogram/groupcache/v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
"github.com/udhos/groupcache_ratelimit/ratelimit"
"github.com/udhos/otelconfig/oteltrace"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/attribute"
Expand All @@ -35,7 +34,6 @@ type application struct {
restrictMethod []string
backendURL *url.URL
httpClient *http.Client
limiter *ratelimit.Limiter
}

func (app *application) run() {
Expand Down Expand Up @@ -307,27 +305,12 @@ func isHTTPError(status int) bool {
return status < 200 || status > 299
}

func (app *application) query(c context.Context, key, reqIP string, useCache bool) (response, error) {
func (app *application) query(c context.Context, key, _ /*reqIP*/ string, useCache bool) (response, error) {

const me = "app.query"
ctx, span := app.tracer.Start(c, me)
defer span.End()

accept, errRate := app.limiter.Consume(ctx, reqIP)
if errRate == nil {
if !accept {
msg := fmt.Sprintf("%s - %d - too many requests\n",
reqIP, http.StatusTooManyRequests)
resp := response{
Body: []byte(msg),
Status: http.StatusTooManyRequests,
}
return resp, nil
}
} else {
log.Error().Msgf("ip='%s' key='%s' rate limit error:%v", reqIP, key, errRate)
}

if useCache {
var resp response
var data []byte
Expand Down
4 changes: 0 additions & 4 deletions cmd/kubecache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ type config struct {
kubegroupMetricsNamespace string
kubegroupDebug bool
kubegroupLabelSelector string
ratelimitInterval time.Duration
ratelimitSlots int
}

func newConfig(roleSessionName string) config {
Expand Down Expand Up @@ -60,7 +58,5 @@ func newConfig(roleSessionName string) config {
kubegroupMetricsNamespace: env.String("KUBEGROUP_METRICS_NAMESPACE", ""),
kubegroupDebug: env.Bool("KUBEGROUP_DEBUG", true),
kubegroupLabelSelector: env.String("KUBEGROUP_LABEL_SELECTOR", "app=kubecache"),
ratelimitInterval: env.Duration("RATELIMIT_INTERVAL", 10*time.Second),
ratelimitSlots: env.Int("RATELIMIT_SLOTS", 5),
}
}
18 changes: 1 addition & 17 deletions cmd/kubecache/groupcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/rs/zerolog/log"
"github.com/udhos/groupcache_exporter"
"github.com/udhos/groupcache_exporter/groupcache/modernprogram"
"github.com/udhos/groupcache_ratelimit/ratelimit"
"github.com/udhos/kube/kubeclient"
"github.com/udhos/kubegroup/kubegroup"
)
Expand Down Expand Up @@ -110,18 +109,14 @@ func startGroupcache(app *application, forceNamespaceDefault bool) func() {
app.cache = groupcache.NewGroupWithWorkspace(workspace, "path",
app.cfg.groupcacheSizeBytes, getter)

app.limiter = newRatelimit(app.cfg.ratelimitInterval,
app.cfg.ratelimitSlots, workspace)

//
// expose prometheus metrics for groupcache
//

g := modernprogram.New(app.cache)
labels := map[string]string{}
namespace := ""
collector := groupcache_exporter.NewExporter(namespace, labels, g,
app.limiter.MetricsExporter())
collector := groupcache_exporter.NewExporter(namespace, labels, g)
app.registry.MustRegister(collector)

stop := func() {
Expand All @@ -130,14 +125,3 @@ func startGroupcache(app *application, forceNamespaceDefault bool) func() {

return stop
}

func newRatelimit(interval time.Duration, slots int,
groupcacheWorkspace *groupcache.Workspace) *ratelimit.Limiter {
options := ratelimit.Options{
Interval: interval,
Slots: slots,
GroupcacheWorkspace: groupcacheWorkspace,
}

return ratelimit.New(options)
}
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.3.6"
const version = "0.4.0"
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/rs/zerolog v1.32.0
github.com/udhos/boilerplate v1.2.7
github.com/udhos/groupcache_exporter v0.1.0
github.com/udhos/groupcache_ratelimit v0.1.0
github.com/udhos/kube v0.0.1
github.com/udhos/kubegroup v1.0.2
github.com/udhos/otelconfig v0.1.8
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ github.com/udhos/boilerplate v1.2.7 h1:VemmQ2ucP8evD8ys3WrssYCDwd8wdoAhr+rq9wIGb
github.com/udhos/boilerplate v1.2.7/go.mod h1:Qee+p5PpI0WH6pYSFCp0FUOxpbZlnBxNJ48CBCXvrck=
github.com/udhos/groupcache_exporter v0.1.0 h1:1pXP7c00VX2YTvCMo4CO3d/nv2rWq/0JOlnDwb6bO8s=
github.com/udhos/groupcache_exporter v0.1.0/go.mod h1:CD1BGchO6jV4u6aarWVXkbr7UVztizOj8Bi8tJ2gN/A=
github.com/udhos/groupcache_ratelimit v0.1.0 h1:qToj5IyGixsSJixbp03dkEh2Uhnlozj+iSyjia7Z644=
github.com/udhos/groupcache_ratelimit v0.1.0/go.mod h1:8sDwE5bG37SUn0bBh1phyfrkHJe4KlR4w0xYp/nzWCI=
github.com/udhos/kube v0.0.1 h1:FFWNyn+xf4aHZTaldKZuueu6ZQqmJR76I4OrfeJo9W4=
github.com/udhos/kube v0.0.1/go.mod h1:UgnFniZC6fLV5vEvAqpDvN+rY+aQJwzRM1ejhK2yzEI=
github.com/udhos/kubegroup v1.0.2 h1:Qkg29U0j0gXwVwbE7rMv7n7VMcb0xG9oMogi08o8Rss=
Expand Down

0 comments on commit 737f3b1

Please sign in to comment.