Skip to content

Commit b1192e6

Browse files
committed
better metrics + auto reset them after 24h
1 parent e3c932b commit b1192e6

File tree

10 files changed

+257
-208
lines changed

10 files changed

+257
-208
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "discord-api-proxy"
3-
version = "1.1.1"
3+
version = "1.2.0"
44
edition = "2021"
55

66
[features]

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Discord API Proxy
2-
A transparent, Redis backed proxy for handling Discord's API ratelimits.
2+
A transparent, Redis backed proxy for handling Discord's API ratelimits. Designed for use in any distributed environment that needs to interact with the Discord API, this service will centralize and nicely handle all the ratelimiting for your client applications.
33

44
## Usage
55

@@ -15,9 +15,11 @@ docker run -d \
1515

1616
Once up and running, just send your normal requests to `http://YOURPROXY/api/v*` instead of `https://discord.com/api/v*`.
1717

18-
You'll get back all the same responses, except when you would have hit a ratelimit - then you'll get a 429 from the proxy with `x-sent-by-proxy` and `x-ratelimit-bucket` headers.
18+
You'll get back all the same responses, except when you would have hit a ratelimit - then you'll get a 429 from the proxy with `x-sent-by-proxy` and `x-ratelimit-bucket` headers as well as the usual ratelimiting headers.
1919

20-
If you get a 429 from the proxy, you should just retry until it works. If it's happening a lot, just stop hitting them.
20+
## Metrics
21+
22+
Metrics are enabled by default and can be accessed at `/metrics` on the proxy. They are exposed in the Prometheus format.
2123

2224
#### Environment Variables
2325
| Name | Description |
@@ -40,9 +42,6 @@ If you get a 429 from the proxy, you should just retry until it works. If it's h
4042

4143
## Warnings
4244

43-
### Slightly Reduced Throughput
44-
When sending globally ratelimited requests, the proxy currently starts the 1s bucket time from when the first response is received as Discord never provide the exact time. This can cause the proxy to be slightly over-restrictive depending on your , with a bot where the global ratelimit is 50 only being allowed up to ~47 requests per second.
45-
4645
### HTTP2 Connection Drops
4746
These are caused by the underlying HTTP library, see https://github.com/hyperium/hyper/issues/2500. If you're seeing errors, you should use the `DISABLE_HTTP2` environment variable until the linked issue is resolved.
4847

benchmarks/stress_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { sleep } from 'k6';
44
export const options = {
55
stages: [
66
{ duration: '15s', target: 1000 },
7-
{ duration: '15s', target: 2000 },
8-
{ duration: '15m', target: 2000 },
7+
{ duration: '15s', target: 1500 },
8+
{ duration: '15m', target: 1500 },
99
{ duration: '15s', target: 0 }
1010
],
1111
};

src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ pub struct ProxyEnvConfig {
6767

6868
pub disable_http2: bool,
6969
pub clustered_redis: bool, // TODO: Clustered redis only really needs a small number of changes to the client as all keys are already namespaced, but it's not finished yet
70+
71+
#[cfg(feature = "metrics")]
72+
pub metrics_ttl: u64,
7073
}
7174

7275
pub enum EnvError {
@@ -184,6 +187,9 @@ impl AppEnvConfig {
184187
let host = get_envvar_with_default("HOST", "127.0.0.1".to_string());
185188
let port = get_and_parse_envvar::<u16>("PORT", 8080);
186189

190+
#[cfg(feature = "metrics")]
191+
let metrics_ttl = get_and_parse_envvar::<u64>("METRICS_TTL", 86400000);
192+
187193
Self {
188194
redis: Arc::new(RedisEnvConfig {
189195
host: redis_host,
@@ -216,6 +222,9 @@ impl AppEnvConfig {
216222
disable_http2,
217223

218224
clustered_redis,
225+
226+
#[cfg(feature = "metrics")]
227+
metrics_ttl,
219228
}),
220229
}
221230
}

src/discord.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const LARGE_SHARDING_INTERNAL_SHARD_RL: u16 = 25;
1111

1212
#[derive(Deserialize)]
1313
struct GetGatewayBotResponse {
14-
_url: String,
15-
_shards: u16,
14+
// url: String,
15+
// shards: u16,
1616
session_start_limit: SessionStartLimit,
1717
}
1818

1919
#[derive(Deserialize)]
2020
struct SessionStartLimit {
21-
_total: u16,
22-
_remaining: u16,
23-
_reset_after: u64,
21+
// total: u16,
22+
// remaining: u16,
23+
// reset_after: u64,
2424
max_concurrency: u16,
2525
}
2626

0 commit comments

Comments
 (0)