Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octokit log is not going into pino from Probot #1673

Open
kammerjaeger opened this issue Apr 8, 2022 · 2 comments
Open

Octokit log is not going into pino from Probot #1673

kammerjaeger opened this issue Apr 8, 2022 · 2 comments

Comments

@kammerjaeger
Copy link
Contributor

kammerjaeger commented Apr 8, 2022

Bug Report

Current Behavior

The throttling log is not showing up in the log file (that is send to ESC in our case), instead it is printed to the console.
Reason: Currently the octokit.log object is not set correctly when called form probot.auth()
The following test shows it, I did not make sure that it is true on success, I was only using it for looking for the log outputs, for now:

test('Throtteling logging', async () => {
        const output = [];

        const streamLogsToOutput = new stream.Writable({ objectMode: true });
        streamLogsToOutput._write = (object: string, _encoding, done) => {
            output.push(JSON.parse(object));
            done();
        };

        logger = pino(streamLogsToOutput);

        const mock = nock(/github\.amd\.com/);

        const probot = createProbot({
            overrides: {
                appId: 1,
                githubToken: 'test',
                log: logger,
                privateKey: mockCert,
                logLevel: 'debug',
                Octokit: ProbotOctokit.defaults({
                    //    retry: { enabled: false},
                    //    throttle: { enabled: false},
                    // logger // <- does not change anything
                }),
            },
        });

        mock.get('/api/v3/app').reply(
            403,
            {
                message:
                    "API rate limit exceeded for xxx.xxx.xxx.xxx.",
                documentation_url: 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting',
            },
            {
                'x-ratelimit-limit': '60',
                'x-ratelimit-remaining': '0',
                'x-ratelimit-reset': '1377013266',
            }
        );

        const octokit = await probot.auth();
        // Also does not work
        //const octokit = await probot.auth(undefined, logger.child({name:"octo"}));

        octokit.log.warn("test");

        try {
            const auths = await octokit.apps.getAuthenticated();
            expect(auths).toBeNull(); // should not reach here
        } catch (err) {
            console.log(err);
        }
        //expect(async () => await octokit.apps.getAuthenticated()).toThrow("HttpError: API rate limit exceeded for xxx.xxx.xxx.xxx.")

        expect(output).toBeArrayOfSize(2);
});

Expected behavior/code
The logging goes into the pino logger. The test should not show any console logging.

Environment

  • Probot version(s): 12.2.2
  • Node/npm version: lts 16
  • OS: Windows 10

Possible Solution

I'm still investigating why this is not set correctly, as seen in the example I tried to set the logger directly but that is not working for me.
I will provide a better test once I figure out what actually goes wrong.

Edit:
I think it may be the missing Octokit options here. I will test this more in the next days:

const octokit = new Octokit();

Additional context/Screenshots
NA

@welcome
Copy link

welcome bot commented Apr 8, 2022

Thanks for opening this issue. A contributor should be by to give feedback soon. In the meantime, please check out the contributing guidelines and explore other ways you can get involved.

@hkdobrev
Copy link
Contributor

hkdobrev commented Mar 8, 2024

Should this be closed as resolved in #1676?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants