Skip to content

Commit 4f02154

Browse files
committed
feat: add new metrics
1 parent c266558 commit 4f02154

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

internal/authenticator/auto_authenticator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (a AutoAuthenticator) Auth(ctx context.Context, tokenString string) error {
5353
if err := a.Validator.Validate(ctx, headers, "bearer "+tokenString); err != nil {
5454
a.Metrics.Latency(time.Since(start).Seconds(), a.Company, err)
5555

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

5959
a.Metrics.Latency(time.Since(start).Seconds(), a.Company, nil)

pkg/validator/client.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ func (c *Client) Validate(parentCtx context.Context, headers http.Header, bearer
9696
return fmt.Errorf("validator sending request failed %w", err)
9797
}
9898

99-
closeBody(response)
99+
defer func() {
100+
_ = response.Body.Close()
101+
}()
100102

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

110112
return nil
111113
}
112-
113-
// closeBody to avoid memory leak when reusing http connection.
114-
func closeBody(response *http.Response) {
115-
if response != nil {
116-
_ = response.Body.Close()
117-
}
118-
}

0 commit comments

Comments
 (0)