{"id":20832867,"url":"https://github.com/udhos/groupcache_ratelimit","last_synced_at":"2026-04-21T17:36:18.931Z","repository":{"id":225266731,"uuid":"765457121","full_name":"udhos/groupcache_ratelimit","owner":"udhos","description":"groupcache_ratelimit provides rate limiting for distributed applications using groupcache.","archived":false,"fork":false,"pushed_at":"2024-03-04T02:29:17.000Z","size":25,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-15T11:50:49.564Z","etag":null,"topics":["cache","go","golang","groupcache","kubernetes","rate-limiting"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/udhos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-01T00:31:52.000Z","updated_at":"2024-03-11T09:31:56.000Z","dependencies_parsed_at":"2024-03-01T05:25:40.235Z","dependency_job_id":"750e2023-ed29-4cb7-9bf8-b0a913d60043","html_url":"https://github.com/udhos/groupcache_ratelimit","commit_stats":null,"previous_names":["udhos/groupcache_ratelimit"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/udhos/groupcache_ratelimit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fgroupcache_ratelimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fgroupcache_ratelimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fgroupcache_ratelimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fgroupcache_ratelimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/udhos","download_url":"https://codeload.github.com/udhos/groupcache_ratelimit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fgroupcache_ratelimit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27667252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","go","golang","groupcache","kubernetes","rate-limiting"],"created_at":"2024-11-18T00:13:28.942Z","updated_at":"2025-12-11T17:03:29.324Z","avatar_url":"https://github.com/udhos.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/udhos/groupcache_ratelimit/blob/main/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/udhos/groupcache_ratelimit)](https://goreportcard.com/report/github.com/udhos/groupcache_ratelimit)\n[![Go Reference](https://pkg.go.dev/badge/github.com/udhos/groupcache_ratelimit.svg)](https://pkg.go.dev/github.com/udhos/groupcache_ratelimit)\n\n# groupcache_ratelimit\n\n[groupcache_ratelimit](https://github.com/udhos/groupcache_ratelimit) provides rate limiting for distributed applications using [groupcache](https://github.com/modernprogram/groupcache).\n\n# Usage\n\n```go\nimport (\n    \"github.com/modernprogram/groupcache/v2\"\n    \"github.com/udhos/groupcache_exporter\"\n    \"github.com/udhos/groupcache_exporter/groupcache/modernprogram\"\n    \"github.com/udhos/groupcache_ratelimit/ratelimit\"\n    \"github.com/udhos/kubegroup/kubegroup\"\n)\n\n//\n// Initialize groupcache as usual.\n//\n\ngroupcachePort := \":5000\"\n\nworkspace := groupcache.NewWorkspace()\n\n// Example using kubegroup for kubernetes peers autodiscovery\nmyURL, errURL = kubegroup.FindMyURL(groupcachePort)\n\npool := groupcache.NewHTTPPoolOptsWithWorkspace(workspace, myURL, \u0026groupcache.HTTPPoolOptions{})\n\n// Start groupcache peering server\nserver := \u0026http.Server{Addr: groupcachePort, Handler: pool}\ngo func() {\n    log.Printf(\"groupcache server: listening on %s\", groupcachePort)\n    err := server.ListenAndServe()\n    log.Printf(\"groupcache server: exited: %v\", err)\n}()\n\n// Start kubegroup autodiscovery\noptionsKg := kubegroup.Options{\n    Pool:           pool,\n    GroupCachePort: groupCachePort,\n}\ngroup, errGroup := kubegroup.UpdatePeers(optionsKg)\nif errGroup != nil {\n    log.Fatalf(\"kubegroup: %v\", errGroup)\n}\n\n//\n// Create the rate limiter: 60 slots at every 30-second interval.\n//\noptionsLim := ratelimit.Options{\n    Interval:            30 * time.Second,\n    Slots:               60,\n    GroupcacheWorkspace: workspace,\n}\n\nlim := ratelimit.New(optionsLim)\n\n//\n// Optionally expose groupcache metrics for rate limiter in Prometheus format.\n//\nlabels := map[string]string{}\nnamespace := \"\"\ncollector := groupcache_exporter.NewExporter(namespace, labels, lim.MetricsExporter())\nprometheus.MustRegister(collector)\n\n//\n// Query the rate limiter.\n//\naccept, errRate := lim.Consume(context.TODO(), \"some-key\")\nif errRate == nil {\n    if accept {\n        log.Printf(\"key accepted by rate limiting\")\n    } else {\n        log.Printf(\"key rejected by rate limiting\")\n    }\n} else {\n    log.Printf(\"rate limiting error: %v\", errRate)\n}\n```\n\n# Istio interceptionMode TPROXY\n\nIstio sidecard interceptionMode with REDIRECT hides real source IP.\n\nIn order to receive the real POD source IP to perform rate limiting,\nset POD annotation `sidecar.istio.io/interceptionMode` to `TPROXY`.\n\n```yaml\nannotations:\n  \"sidecar.istio.io/interceptionMode\": \"TPROXY\" # REDIRECT or TPROXY\n```\n\nDocumentation: https://istio.io/latest/docs/reference/config/annotations/#SidecarInterceptionMode\n\nExample helm chart: https://github.com/udhos/kubecache/blob/main/charts/kubecache/values.yaml#L40\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudhos%2Fgroupcache_ratelimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fudhos%2Fgroupcache_ratelimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudhos%2Fgroupcache_ratelimit/lists"}