fix(github): Shrink pages for specific types of errors (#16388)

This commit is contained in:
Sergei Zharinov 2022-07-02 19:41:02 +03:00 committed by GitHub
parent b5df686fb7
commit 1454b602fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View file

@ -345,6 +345,38 @@ describe('modules/datasource/github-releases/cache/cache-base', () => {
expect(packageCache.set).not.toHaveBeenCalled();
});
it('shrinks for some of graphql errors', async () => {
packageCache.get.mockResolvedValueOnce({
items: {},
createdAt: t3,
updatedAt: t3,
});
responses = [
{
statusCode: 200,
headers: {},
body: {
errors: [
{ message: 'Something went wrong while executing your query.' },
],
},
},
resp([{ name: 'v3', createdAt: t3, foo: 'ccc' }], true),
resp([{ name: 'v2', createdAt: t2, foo: 'bbb' }], true),
resp([{ name: 'v1', createdAt: t1, foo: 'aaa' }]),
];
const cache = new TestCache(http, { resetDeltaMinutes: 0 });
const res = await cache.getItems({ packageName: 'foo/bar' });
expect(sortItems(res)).toMatchObject([
{ version: 'v1', bar: 'aaa' },
{ version: 'v2', bar: 'bbb' },
{ version: 'v3', bar: 'ccc' },
]);
expect(packageCache.set).toHaveBeenCalled();
});
it('finds latest release timestamp correctly', () => {
const cache = new TestCache(http);
const ts = cache.getLastReleaseTimestamp({

View file

@ -1,4 +1,5 @@
import { DateTime, DurationLikeObject } from 'luxon';
import { logger } from '../../../../logger';
import * as packageCache from '../../../../util/cache/package';
import type {
GithubGraphqlResponse,
@ -265,6 +266,19 @@ export abstract class AbstractGithubDatasourceCache<
while (pagesRemained > 0 && !stopIteration) {
const res = await this.query(baseUrl, variables);
if (res instanceof Error) {
if (
res.message.startsWith(
'Something went wrong while executing your query.' // #16343
) &&
variables.count > 30
) {
logger.warn(
`GitHub datasource cache: shrinking GraphQL page size due to error`
);
pagesRemained *= 2;
variables.count = Math.floor(variables.count / 2);
continue;
}
throw res;
}