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

[chore][extension/sumologic] Fix lint error #34083

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions extension/sumologicextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (se *SumologicExtension) registerCollector(ctx context.Context, collectorNa
defer res.Body.Close()

if res.StatusCode < 200 || res.StatusCode >= 400 {
return se.handleRegistrationError(res)
return credentials.CollectorCredentials{}, se.handleRegistrationError(res)
} else if res.StatusCode == 301 {
// Use the URL from Location header for subsequent requests.
u := strings.TrimSuffix(res.Header.Get("Location"), "/")
Expand Down Expand Up @@ -487,17 +487,17 @@ func (se *SumologicExtension) registerCollector(ctx context.Context, collectorNa

// handleRegistrationError handles the collector registration errors and returns
// appropriate error for backoff handling and logging purposes.
func (se *SumologicExtension) handleRegistrationError(res *http.Response) (credentials.CollectorCredentials, error) { // nolint: unparam
func (se *SumologicExtension) handleRegistrationError(res *http.Response) error {
var errResponse api.ErrorResponsePayload
if err := json.NewDecoder(res.Body).Decode(&errResponse); err != nil {
var buff bytes.Buffer
if _, errCopy := io.Copy(&buff, res.Body); errCopy != nil {
return credentials.CollectorCredentials{}, fmt.Errorf(
return fmt.Errorf(
"failed to read the collector registration response body, status code: %d, err: %w",
res.StatusCode, errCopy,
)
}
return credentials.CollectorCredentials{}, fmt.Errorf(
return fmt.Errorf(
"failed to decode collector registration response body: %s, status code: %d, err: %w",
buff.String(), res.StatusCode, err,
)
Expand All @@ -511,13 +511,13 @@ func (se *SumologicExtension) handleRegistrationError(res *http.Response) (crede

// Return unrecoverable error for 4xx status codes except 429
if res.StatusCode >= 400 && res.StatusCode < 500 && res.StatusCode != 429 {
return credentials.CollectorCredentials{}, backoff.Permanent(fmt.Errorf(
return backoff.Permanent(fmt.Errorf(
"failed to register the collector, got HTTP status code: %d",
res.StatusCode,
))
}

return credentials.CollectorCredentials{}, fmt.Errorf(
return fmt.Errorf(
"failed to register the collector, got HTTP status code: %d", res.StatusCode,
)
}
Expand Down