Set actions client timeout to 5 minutes, add logging to client (#3103)
This commit is contained in:
		
							parent
							
								
									fb11d3bfd0
								
							
						
					
					
						commit
						b202be712e
					
				|  | @ -7,9 +7,9 @@ import ( | ||||||
| 	"crypto/tls" | 	"crypto/tls" | ||||||
| 	"crypto/x509" | 	"crypto/x509" | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
|  | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"log" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/url" | 	"net/url" | ||||||
| 	"strconv" | 	"strconv" | ||||||
|  | @ -57,6 +57,28 @@ type ActionsService interface { | ||||||
| 	SetUserAgent(info UserAgentInfo) | 	SetUserAgent(info UserAgentInfo) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type clientLogger struct { | ||||||
|  | 	logr.Logger | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (l *clientLogger) Info(msg string, keysAndValues ...interface{}) { | ||||||
|  | 	l.Logger.Info(msg, keysAndValues...) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (l *clientLogger) Debug(msg string, keysAndValues ...interface{}) { | ||||||
|  | 	// discard debug log
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (l *clientLogger) Error(msg string, keysAndValues ...interface{}) { | ||||||
|  | 	l.Logger.Error(errors.New(msg), "Retryable client error", keysAndValues...) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (l *clientLogger) Warn(msg string, keysAndValues ...interface{}) { | ||||||
|  | 	l.Logger.Info(msg, keysAndValues...) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | var _ retryablehttp.LeveledLogger = &clientLogger{} | ||||||
|  | 
 | ||||||
| type Client struct { | type Client struct { | ||||||
| 	*http.Client | 	*http.Client | ||||||
| 
 | 
 | ||||||
|  | @ -168,11 +190,13 @@ func NewClient(githubConfigURL string, creds *ActionsAuth, options ...ClientOpti | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	retryClient := retryablehttp.NewClient() | 	retryClient := retryablehttp.NewClient() | ||||||
| 	retryClient.Logger = log.New(io.Discard, "", log.LstdFlags) | 	retryClient.Logger = &clientLogger{Logger: ac.logger} | ||||||
| 
 | 
 | ||||||
| 	retryClient.RetryMax = ac.retryMax | 	retryClient.RetryMax = ac.retryMax | ||||||
| 	retryClient.RetryWaitMax = ac.retryWaitMax | 	retryClient.RetryWaitMax = ac.retryWaitMax | ||||||
| 
 | 
 | ||||||
|  | 	retryClient.HTTPClient.Timeout = 5 * time.Minute // timeout must be > 1m to accomodate long polling
 | ||||||
|  | 
 | ||||||
| 	transport, ok := retryClient.HTTPClient.Transport.(*http.Transport) | 	transport, ok := retryClient.HTTPClient.Transport.(*http.Transport) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		// this should always be true, because retryablehttp.NewClient() uses
 | 		// this should always be true, because retryablehttp.NewClient() uses
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue