From 4db974e28dab19ce1051c85f02ca11af9c4815f8 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 2 Feb 2022 13:22:07 +0100 Subject: [PATCH] fix: address review comments --- .../src/durable-objects/gateway-metrics.js | 8 ++++---- .../src/durable-objects/gateway-rate-limits.js | 16 ++++++++-------- packages/gateway/src/metrics.js | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/gateway/src/durable-objects/gateway-metrics.js b/packages/gateway/src/durable-objects/gateway-metrics.js index 107c99cea0a..98bd683776c 100644 --- a/packages/gateway/src/durable-objects/gateway-metrics.js +++ b/packages/gateway/src/durable-objects/gateway-metrics.js @@ -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} 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' diff --git a/packages/gateway/src/durable-objects/gateway-rate-limits.js b/packages/gateway/src/durable-objects/gateway-rate-limits.js index 39b0e6fe86c..068417e7f46 100644 --- a/packages/gateway/src/durable-objects/gateway-rate-limits.js +++ b/packages/gateway/src/durable-objects/gateway-rate-limits.js @@ -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, - }) + } } } diff --git a/packages/gateway/src/metrics.js b/packages/gateway/src/metrics.js index f2b149139d3..b770b10d8d8 100644 --- a/packages/gateway/src/metrics.js +++ b/packages/gateway/src/metrics.js @@ -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`,