Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Feb 2, 2022
1 parent 13f4a93 commit 4db974e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/gateway/src/durable-objects/gateway-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* @property {number} totalSuccessfulRequests total number of successful requests
* @property {number} totalFailedRequests total number of requests failed
* @property {number} totalWinnerRequests number of performed requests where winner
* @property {number} totalRateLimitedErroredRequests number of performed requests prevented from rate limiting
* @property {number} totalRateLimitedPreventedRequests number of performed requests prevented from rate limiting
* @property {number} totalRateLimitedErroredRequests number of performed requests that errored with rate limit code without being prevented
* @property {number} totalRateLimitedPreventedRequests number of requests not sent to upstream gateway as it would exceed the rate limit
* @property {Record<string, number>} responseTimeHistogram
*
* @typedef {Object} ResponseStats
* @property {boolean} ok request was successful
* @property {number} [responseTime] number of milliseconds to get response
* @property {boolean} [winner] response was from winner gateway
* @property {boolean} [rateLimitPrevented] response not obtained as request did not happen to prevent rate limit blockage
* @property {boolean} [rateLimitErrored] rate limit was not prevented, but worker was still rate limited
* @property {boolean} [rateLimitPrevented] request not sent to upstream gateway as it would exceed the rate limit
* @property {boolean} [rateLimitErrored] request errored with rate limit code without being prevented
*/

const GATEWAY_METRICS_ID = 'gateway_metrics'
Expand Down
16 changes: 8 additions & 8 deletions packages/gateway/src/durable-objects/gateway-rate-limits.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ const MINUTE = 1000 * 60
function getRateLimitingCharacteristics(gatewayUrl) {
switch (gatewayUrl) {
case 'https://ipfs.io':
return Object.freeze({
return {
RATE_LIMIT_REQUESTS: 800,
RATE_LIMIT_TIMEFRAME: MINUTE,
})
}
case 'https://cf-ipfs.com':
return Object.freeze({
return {
RATE_LIMIT_REQUESTS: 100,
RATE_LIMIT_TIMEFRAME: MINUTE,
})
}
case 'https://nft-storage.mypinata.cloud/':
return Object.freeze({
return {
RATE_LIMIT_REQUESTS: 200,
RATE_LIMIT_TIMEFRAME: MINUTE,
})
}
// Default to 100
default:
return Object.freeze({
return {
RATE_LIMIT_REQUESTS: 100,
RATE_LIMIT_TIMEFRAME: MINUTE,
})
}
}
}
6 changes: 3 additions & 3 deletions packages/gateway/src/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ export async function metricsGet(request, env, ctx) {
(gw) =>
`nftgateway_rate_limited_errored_requests_total{gateway="${gw}",env="${env.ENV}"} ${metricsCollected.ipfsGateways[gw].totalRateLimitedErroredRequests}`
),
`# HELP nftstorage_gateway_total_faster_requests Total requests with faster response.`,
`# TYPE nftstorage_gateway_total_faster_requests counter`,
`# HELP nftgateway_winner_requests_total Total requests with winner response to each gateway.`,
`# TYPE nftgateway_winner_requests_total counter`,
...env.ipfsGateways.map(
(gw) =>
`nftstorage_gateway_total_faster_requests{gateway="${gw}",env="${env.ENV}"} ${metricsCollected.ipfsGateways[gw].totalWinnerRequests}`
`nftgateway_winner_requests_total{gateway="${gw}",env="${env.ENV}"} ${metricsCollected.ipfsGateways[gw].totalWinnerRequests}`
),
`# HELP nftgateway_requests_per_time_total`,
`# TYPE nftgateway_requests_per_time_total histogram for total of requests per response time bucket`,
Expand Down

0 comments on commit 4db974e

Please sign in to comment.