Skip to content

Commit 7685d51

Browse files
authored
Merge pull request #610 from SumoLogic/Test
Retryable http client in Sumologic TF provider masking error code bug fix.
2 parents 58016cd + 2561439 commit 7685d51

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ package main
33
import (
44
"github.com/SumoLogic/terraform-provider-sumologic/sumologic"
55
"github.com/hashicorp/terraform-plugin-sdk/plugin"
6+
"log"
67
)
78

89
var version string // provider version is passed as compile time argument
910
var defaultVersion = "dev"
1011

1112
func main() {
13+
// Remove any date and time prefix in log package function output to
14+
// prevent duplicate timestamp and incorrect log level setting
15+
// See: https://developer.hashicorp.com/terraform/plugin/log/writing#duplicate-timestamp-and-incorrect-level-messages
16+
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
1217
if version == "" {
1318
sumologic.ProviderVersion = defaultVersion
1419
} else {

sumologic/sumologic_client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func createNewRequest(method, url string, body io.Reader, accessID string, acces
6363
func logRequestAndResponse(req *http.Request, resp *http.Response) {
6464
var maskedHeader = req.Header.Clone()
6565
maskedHeader.Set("Authorization", "xxxxxxxxxxx")
66-
log.Printf("[DEBUG] Request: [Method=%s] [URL=%s] [Headers=%s]. Response: [StatusCode=%s]\n", req.Method, req.URL, maskedHeader, resp.Status)
66+
log.Printf("[DEBUG] Request: [Method=%s] [URL=%s] [Headers=%s]. Response: [Status=%s]\n", req.Method, req.URL, maskedHeader, resp.Status)
6767
}
6868

6969
func (s *Client) PostWithCookies(urlPath string, payload interface{}) ([]byte, []*http.Cookie, error) {
@@ -328,12 +328,17 @@ func (s *Client) Delete(urlPath string) ([]byte, error) {
328328
return d, nil
329329
}
330330

331+
func ErrorHandler(resp *http.Response, err error, numTries int) (*http.Response, error) {
332+
log.Printf("[ERROR] Request %s failed after %d attempts with response: [%s]", resp.Request.URL, numTries, resp.Status)
333+
return resp, err
334+
}
335+
331336
func NewClient(accessID, accessKey, authJwt, environment, base_url string, admin bool) (*Client, error) {
332337
retryClient := retryablehttp.NewClient()
333338
retryClient.RetryMax = 10
334339
// Disable DEBUG logs (https://github.com/hashicorp/go-retryablehttp/issues/31)
335340
retryClient.Logger = nil
336-
341+
retryClient.ErrorHandler = ErrorHandler
337342
client := Client{
338343
AccessID: accessID,
339344
AccessKey: accessKey,

0 commit comments

Comments
 (0)