Skip to content

Commit

Permalink
Rate limit sometimes kicks in at 50% (#4673)
Browse files Browse the repository at this point in the history
Remove rate limiting for the release
Will be re-added with a different rate limitter in April.
Fixes #4671
  • Loading branch information
alexr00 authored Mar 27, 2023
1 parent babc044 commit de2c177
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 55 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,6 @@
"dayjs": "1.10.4",
"events": "3.2.0",
"fast-deep-equal": "^3.1.3",
"limiter": "^2.1.0",
"lru-cache": "6.0.0",
"marked": "^4.0.10",
"react": "^16.12.0",
Expand Down
52 changes: 10 additions & 42 deletions src/github/loggingOctokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import { Octokit } from '@octokit/rest';
import { ApolloClient, ApolloQueryResult, FetchResult, MutationOptions, NormalizedCacheObject, OperationVariables, QueryOptions } from 'apollo-boost';
import { RateLimiter } from 'limiter';
import * as vscode from 'vscode';
import Logger from '../common/logger';
import { ITelemetry } from '../common/telemetry';
import { RateLimit } from './graphql';
Expand All @@ -19,28 +17,10 @@ interface RestResponse {
}

export class RateLogger {
private limiter: RateLimiter;
private static ID = 'RateLimit';
private hasLoggedLowRateLimit: boolean = false;

constructor(private readonly telemetry: ITelemetry) {
this.limiter = new RateLimiter({ tokensPerInterval: 120, interval: 'second' });
}

public logAndLimit(): boolean {
if (!this.limiter.tryRemoveTokens(1)) {
Logger.error('API call count has exceeded 100 calls in 1 second.', RateLogger.ID);
// We have hit 100 requests in 1 second. This likely indicates a bug in the extension.
/* __GDPR__
"pr.highApiCallRate" : {}
*/
this.telemetry.sendTelemetryErrorEvent('pr.highApiCallRate');
vscode.window.showErrorMessage(vscode.l10n.t('The GitHub Pull Requests extension is making too many requests to GitHub. This indicates a bug in the extension. Please file an issue on GitHub and include the output from "GitHub Pull Request".'));
return false;
}
Logger.debug(`Extension rate limit remaining: ${this.limiter.getTokensRemaining()}`, RateLogger.ID);
return true;
}
constructor(private readonly telemetry: ITelemetry) { }

public async logRateLimit(info: string | undefined, result: Promise<{ data: { rateLimit: RateLimit | undefined } | undefined } | undefined>, isRest: boolean = false) {
let rateLimitInfo;
Expand Down Expand Up @@ -90,36 +70,24 @@ export class LoggingApolloClient {
constructor(private readonly _graphql: ApolloClient<NormalizedCacheObject>, private _rateLogger: RateLogger) { };

query<T = any, TVariables = OperationVariables>(options: QueryOptions<TVariables>): Promise<ApolloQueryResult<T>> {
if (this._rateLogger.logAndLimit()) {
const result = this._graphql.query(options);
this._rateLogger.logRateLimit((options.query.definitions[0] as { name: { value: string } | undefined }).name?.value, result as any);
return result;
} else {
throw new Error('API call count has exceeded a rate limit.');
}
const result = this._graphql.query(options);
this._rateLogger.logRateLimit((options.query.definitions[0] as { name: { value: string } | undefined }).name?.value, result as any);
return result;
}

mutate<T = any, TVariables = OperationVariables>(options: MutationOptions<T, TVariables>): Promise<FetchResult<T>> {
if (this._rateLogger.logAndLimit()) {
const result = this._graphql.mutate(options);
this._rateLogger.logRateLimit(options.context, result as any);
return result;
} else {
throw new Error('API call count has exceeded a rate limit.');
}
const result = this._graphql.mutate(options);
this._rateLogger.logRateLimit(options.context, result as any);
return result;
}
}

export class LoggingOctokit {
constructor(public readonly api: Octokit, private _rateLogger: RateLogger) { };

async call<T, U>(api: (T) => Promise<U>, args: T): Promise<U> {
if (this._rateLogger.logAndLimit()) {
const result = api(args);
this._rateLogger.logRestRateLimit((api as unknown as { endpoint: { DEFAULTS: { url: string } | undefined } | undefined }).endpoint?.DEFAULTS?.url, result as Promise<unknown> as Promise<RestResponse>);
return result;
} else {
throw new Error('API call count has exceeded a rate limit.');
}
const result = api(args);
this._rateLogger.logRestRateLimit((api as unknown as { endpoint: { DEFAULTS: { url: string } | undefined } | undefined }).endpoint?.DEFAULTS?.url, result as Promise<unknown> as Promise<RestResponse>);
return result;
}
}
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3605,11 +3605,6 @@ just-extend@^4.0.2:
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-4.1.1.tgz#158f1fdb01f128c411dc8b286a7b4837b3545282"
integrity sha512-aWgeGFW67BP3e5181Ep1Fv2v8z//iBJfrvyTnq8wG86vEESwmonn1zPBJ0VfmT9CJq2FIT0VsETtrNFm2a+SHA==

just-performance@4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/just-performance/-/just-performance-4.3.0.tgz#cc2bc8c9227f09e97b6b1df4cd0de2df7ae16db1"
integrity sha512-L7RjvtJsL0QO8xFs5wEoDDzzJwoiowRw6Rn/GnvldlchS2JQr9wFYPiwZcDfrbbujEKqKN0tvENdbjXdYhDp5Q==

keygrip@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/keygrip/-/keygrip-1.1.0.tgz#871b1681d5e159c62a445b0c74b615e0917e7226"
Expand Down Expand Up @@ -3726,13 +3721,6 @@ levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

limiter@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/limiter/-/limiter-2.1.0.tgz#d38d7c5b63729bb84fb0c4d8594b7e955a5182a2"
integrity sha512-361TYz6iay6n+9KvUUImqdLuFigK+K79qrUtBsXhJTLdH4rIt/r1y8r1iozwh8KbZNpujbFTSh74mJ7bwbAMOw==
dependencies:
just-performance "4.3.0"

lines-and-columns@^1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
Expand Down

0 comments on commit de2c177

Please sign in to comment.