@@ -44,6 +44,7 @@ import (
4444 "regexp"
4545 "runtime"
4646 "runtime/pprof"
47+ "strings"
4748 "sync"
4849 "time"
4950
6768 config Config
6869 startOnce allowUntilSuccess
6970 mutexEnabled bool
71+ logger * log.Logger
7072 // The functions below are stubbed to be overrideable for testing.
7173 getProjectID = gcemd .ProjectID
7274 getInstanceName = gcemd .InstanceName
@@ -222,6 +224,7 @@ func Start(cfg Config, options ...option.ClientOption) error {
222224}
223225
224226func start (cfg Config , options ... option.ClientOption ) error {
227+ logger = log .New (os .Stderr , "Cloud Profiler: " , log .LstdFlags )
225228 if err := initializeConfig (cfg ); err != nil {
226229 debugLog ("failed to initialize config: %v" , err )
227230 return err
@@ -261,7 +264,7 @@ func start(cfg Config, options ...option.ClientOption) error {
261264
262265func debugLog (format string , e ... interface {}) {
263266 if config .DebugLogging {
264- log .Printf (format , e ... )
267+ logger .Printf (format , e ... )
265268 }
266269}
267270
@@ -315,7 +318,8 @@ func (r *retryer) Retry(err error) (time.Duration, bool) {
315318// createProfile talks to the profiler server to create profile. In
316319// case of error, the goroutine will sleep and retry. Sleep duration may
317320// be specified by the server. Otherwise it will be an exponentially
318- // increasing value, bounded by maxBackoff.
321+ // increasing value, bounded by maxBackoff. Special handling for
322+ // certificate errors is described below.
319323func (a * agent ) createProfile (ctx context.Context ) * pb.Profile {
320324 req := pb.CreateProfileRequest {
321325 Parent : "projects/" + a .deployment .ProjectId ,
@@ -332,6 +336,11 @@ func (a *agent) createProfile(ctx context.Context) *pb.Profile {
332336 p , err = a .client .CreateProfile (ctx , & req , grpc .Trailer (& md ))
333337 if err != nil {
334338 debugLog ("failed to create profile, will retry: %v" , err )
339+ if strings .Contains (err .Error (), "x509: certificate signed by unknown authority" ) {
340+ // gax.Invoke does not retry missing certificate error. Force a retry by returning
341+ // a different error. See https://github.com/googleapis/google-cloud-go/issues/3158.
342+ err = errors .New ("retry the certificate error" )
343+ }
335344 }
336345 return err
337346 }, gax .WithRetry (func () gax.Retryer {
0 commit comments