{"id":19587198,"url":"https://github.com/leocolman/simplefeaturethrottler","last_synced_at":"2025-04-27T12:31:27.727Z","repository":{"id":57725879,"uuid":"179617081","full_name":"LeoColman/SimpleFeatureThrottler","owner":"LeoColman","description":"When adding a new feature to an unstable production environment, a service might want to limit the amount of calls made to external services or procedures. With Simple Feature Throttle you can control this.","archived":false,"fork":false,"pushed_at":"2023-12-15T05:41:50.000Z","size":72,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-01T16:48:50.629Z","etag":null,"topics":["feature","hacktoberfest","kotlin","percentage-throttle","rate-limit","rate-limiter","rate-limiting","throttle","throttler","throttling"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/LeoColman.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}},"created_at":"2019-04-05T04:07:05.000Z","updated_at":"2020-10-07T01:02:43.000Z","dependencies_parsed_at":"2023-01-23T16:00:29.290Z","dependency_job_id":null,"html_url":"https://github.com/LeoColman/SimpleFeatureThrottler","commit_stats":null,"previous_names":["kerooker/simplefeaturethrottler"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoColman%2FSimpleFeatureThrottler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoColman%2FSimpleFeatureThrottler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoColman%2FSimpleFeatureThrottler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoColman%2FSimpleFeatureThrottler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeoColman","download_url":"https://codeload.github.com/LeoColman/SimpleFeatureThrottler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224069488,"owners_count":17250456,"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","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":["feature","hacktoberfest","kotlin","percentage-throttle","rate-limit","rate-limiter","rate-limiting","throttle","throttler","throttling"],"created_at":"2024-11-11T08:02:24.294Z","updated_at":"2024-11-11T08:02:25.158Z","avatar_url":"https://github.com/LeoColman.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Feature Throttler\n\n[![Build Status](https://travis-ci.com/LeoColman/SimpleFeatureThrottler.svg?branch=master)](https://travis-ci.com/LeoColman/SimpleFeatureThrottler) [![GitHub](https://img.shields.io/github/license/LeoColman/SimpleFeatureThrottler.svg)](https://github.com/LeoColman/SimpleFeatureThrottler/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/com.kerooker.simplefeaturethrottler/simple-feature-throttler.svg)](https://search.maven.org/search?q=a:simple-feature-throttler)\n\nWhen adding a new feature to an unstable production environment, a service might want to limit the amount of calls made to external services or procedures. With Simple Feature Throttler you can control this.\n\n## Using in your project\n\nTo use Simple Feature Throttler in your project, include the dependency in your `build.gradle`, and you're good to go!\n\n```\nimplementation(\"com.kerooker.simplefeaturethrottler:simple-feature-throttler:{currentVersion}\")\n```\n\n## Available API\n\nTo keep it simple, this library provides two ways to throttle your feature: `Throttler` and `FeatureThrottler`.\n\n#### Using Throttler:\n\nThe `Throttler` class draws number from a Random pool and checks if the next execution of your feature should be denied or not, based on a throttle percentage:\n\n```kotlin\n\nval throttler = Throttler(90.0) // I'll deny 90% of the executions! Only 10% will go through\n\nfun myFeatureThatShouldBeThrottled() {\n\n    if (throttler.shouldThrottle()) return\n    \n    callOtherSystem()\n}\n\n```\n\nThe `Throttler` also contains a utility Companion Object, with a function that mimics its behavior:\n\n```kotlin\n\nfun myFeatureThatShouldBeThrottled() {\n\n    if (Throttler.shouldThrottle(33.3)) return\n    \n    callOtherSystem()\n\n}\n```\n\n\n#### Using Feature Throttler\n\nThe `FeatureThrottler` may be useful if you have more than one feature currently being throttled, and you want more configuration on it. You can configure a feature in 3 different ways:\n\n1. By Environment Variables, with the key being your feature and the value being the throttle percentage, for example: `my.feature=33.3`\n2. By the System Properties, in the same fashion as the Environment Variables: `my.feature=33.3`\n3. By calling the function `FeatureThrottler.setThrottlePercentage(\"my.feature\", 33.3)`\n\n\nTo use the value you set anywhere in the program, you can simply use `FeatureThrottler.shouldThrottle(\"my.feature\")`\n\n\nSo, for example:\n\n```kotlin\n\nfun myFeatureThatShouldBeThrottled() {\n\n    if (FeatureThrottler.shouldThrottle(\"my.feature\")) return\n    \n    callBackend()\n\n}\n```\n\nIf for any reason you need to know what is the current throttling for a given feature, you can use `FeatureThrottler.getThrottlePercentage(\"my.feature\")`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocolman%2Fsimplefeaturethrottler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleocolman%2Fsimplefeaturethrottler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocolman%2Fsimplefeaturethrottler/lists"}