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

Loki response status codes 301 and 400 code do not lead to failure workflow #98

Open
comradealpha opened this issue Feb 10, 2022 · 2 comments

Comments

@comradealpha
Copy link

winston - 3.3.3
winston-loki - 6.0.3
transport - http

Hello! When Loki returns status code 301 or 400 for POST /loki/api/v1/push transport request does not emit error event and batcher treats this case as successful sending. Looks like this behavior is unexpected, can you please comment on that?

@Linkaynn
Copy link
Contributor

@comradealpha

This PR adds a way to handle your situation: #97

I was not sure if the right way is to add a hook to handle or emit it, feedback is welcome here 😄

@comradealpha
Copy link
Author

Unfortunately, this PR seems not to fix my problem, because 301 and 400 codes do not lead to error event emit. Here is some code snippet based on your requests.js code:

const https = require('https')

async function postRequestToFail() {
    return new Promise((resolve, reject) => {
        // Construct the node request options
    const options = {
        hostname: 'loki-transport.free.beeceptor.com',
        path: '/lokibatchpush',
        port:443,
        method: 'POST',
        timeout: 30
    }
  
    console.log("request starts")
    const req = https.request(options, res => {
        res.on('data', _data => {console.log('response status: ' + res.statusCode)})
        res.on('end', () => {console.log('on ended'); resolve();})
    })

    req.on('error', error => {
        console.log('on error' + error)
        reject();
    })
    
    req.end()
    });

}

(async function() {
    await postRequestToFail();
    console.log('awaited');
})();

The output will be:

request starts
response status: 400
on ended
awaited

So, function promise will be never rejected and onConnectionError() from #97 will be never called. I suggest that status code from loki should be checked before resolving.

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