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

TS-1037 #64

Merged
merged 1 commit into from
Dec 5, 2018
Merged

TS-1037 #64

merged 1 commit into from
Dec 5, 2018

Conversation

miroswan
Copy link
Contributor

@miroswan miroswan commented Dec 5, 2018

When the do-agent restarts, it is likely that it'll send a metric faster than rate limitation will allow, resulting in a 429 error. This can safely be ignored. The code adjustment herein determines if the first response from a metric submission is an error with a status of 429. If so, it ignores it.

Looking to extract the status code from the error in Flush here:

return &UnexpectedHTTPStatusError{StatusCode: resp.StatusCode}

err := s.client.Flush()
httpError, ok := err.(*tsclient.UnexpectedHTTPStatusError)
if !s.firstWriteSent && ok && httpError.StatusCode == 421 {
log.Errorf("This error can safely be ignored on startup: %s", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove this line? We don't want an error message in this case.

When the do-agent restarts, it is likely that it'll send a metric
faster than rate limitation will allow, resulting in a 429 error.
This can safely be ignored. The code adjustment herein determines
if the first response from a metric submission is an error with
a status of 429. If so, it ignores it.
@alexcb
Copy link
Contributor

alexcb commented Dec 5, 2018

LGTM

@miroswan miroswan merged commit 218f52f into beta Dec 5, 2018
@miroswan miroswan deleted the TS-1037 branch December 5, 2018 15:51
if !s.firstWriteSent && ok && httpError.StatusCode == 429 {
err = nil
}
s.firstWriteSent = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is racey and should be wrapped in a sync.Once. Rather than using a boolean value (which is not thread safe). You should create a field on Sonar called onceIgnoreError sync.Once and you should change this block to be something like:

err := s.client.Flush()
s.onceIgnoreError.Do(func() {
    httpError, ok := err.(*tsclient.UnexpectedHTTPStatusError)
    if ok && httpError.StatusCode == 429 {
        err = nil
    }
})
return err

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

Successfully merging this pull request may close these issues.

None yet

3 participants