Skip to content

Commit

Permalink
feat: add new metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Dec 15, 2024
1 parent c266558 commit 4f02154
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/authenticator/auto_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (a AutoAuthenticator) Auth(ctx context.Context, tokenString string) error {
if err := a.Validator.Validate(ctx, headers, "bearer "+tokenString); err != nil {
a.Metrics.Latency(time.Since(start).Seconds(), a.Company, err)

return fmt.Errorf("token is invalid: %w", err)
return fmt.Errorf("token is invalid: %w (validator response time %g)", err, time.Since(start).Seconds())
}

a.Metrics.Latency(time.Since(start).Seconds(), a.Company, nil)
Expand Down
11 changes: 3 additions & 8 deletions pkg/validator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (c *Client) Validate(parentCtx context.Context, headers http.Header, bearer
return fmt.Errorf("validator sending request failed %w", err)
}

closeBody(response)
defer func() {
_ = response.Body.Close()
}()

if response.StatusCode != http.StatusOK {
return ErrRequestFailed
Expand All @@ -109,10 +111,3 @@ func (c *Client) Validate(parentCtx context.Context, headers http.Header, bearer

return nil
}

// closeBody to avoid memory leak when reusing http connection.
func closeBody(response *http.Response) {
if response != nil {
_ = response.Body.Close()
}
}

0 comments on commit 4f02154

Please sign in to comment.