Add ability to configure proxy quotas

The quotas can be configured in the yaml configuration file. Default quota will be applied to any userId that is not matched in the custom quota list.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178804649
This commit is contained in:
jianglai 2017-12-12 13:19:14 -08:00
parent c941190e71
commit c5515ab4e6
8 changed files with 258 additions and 1 deletions

View file

@ -61,6 +61,7 @@ public class ProxyConfig {
public int headerLengthBytes;
public int readTimeoutSeconds;
public String serverHostname;
public Quota quota;
}
/** Configuration options that apply to WHOIS protocol. */
@ -70,6 +71,7 @@ public class ProxyConfig {
public String relayPath;
public int maxMessageLengthBytes;
public int readTimeoutSeconds;
public Quota quota;
}
/** Configuration options that apply to GCP load balancer health check protocol. */
@ -92,6 +94,21 @@ public class ProxyConfig {
public int writeIntervalSeconds;
}
/** Configuration options that apply to quota management. */
public static class Quota {
/** Quota configuration for a specific set of users. */
public static class QuotaGroup {
public List<String> userId;
public int tokenAmount;
public int refillSeconds;
}
public int refreshSeconds;
public QuotaGroup defaultQuota;
public List<QuotaGroup> customQuota;
}
static ProxyConfig getProxyConfig(Environment env) {
String defaultYaml = readResourceUtf8(ProxyConfig.class, DEFAULT_CONFIG);
String customYaml =