Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(profiler): Force gax to retry in case of certificate errors #3178

Merged
merged 27 commits into from Jan 28, 2021
Merged
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b4bc13d
fix(profiler): exit profiler agent on certificate errors
kalyanac Nov 10, 2020
e5f42d1
chore(profiler): add code comments
kalyanac Nov 10, 2020
b94cacf
Fix typo
kalyanac Nov 10, 2020
3469efd
Employ exponential backoff on errors instead of exiting.
kalyanac Nov 10, 2020
a42dd12
update comments
kalyanac Nov 10, 2020
c9bb5e3
Merge branch 'master' into master
kalyanac Nov 10, 2020
ecee895
Use exponential backoff on all errors returned from createProfile.
kalyanac Nov 10, 2020
e07097d
Merge branch 'master' of https://github.com/kalyanac/google-cloud-go
kalyanac Nov 10, 2020
d627d00
Update comments.
kalyanac Nov 10, 2020
7acc10c
Merge branch 'master' into master
kalyanac Nov 10, 2020
1fa8405
Merge branch 'master' into master
kalyanac Nov 13, 2020
aae6c09
Force gax.Invoke() to retry cert errors
kalyanac Nov 13, 2020
08816b7
Merge branch 'master' of https://github.com/kalyanac/google-cloud-go
kalyanac Nov 13, 2020
ba22df5
revert changes in profiler_test.go
kalyanac Nov 13, 2020
ea017b1
use prefix in debugLog
kalyanac Nov 13, 2020
d5e7e8a
Merge branch 'master' into master
kalyanac Nov 13, 2020
a6958be
Merge branch 'master' into master
aalexand Nov 25, 2020
797c090
Merge branch 'master' into master
kalyanac Jan 22, 2021
5abeb75
Merge branch 'master' into master
kalyanac Jan 22, 2021
fd60f31
Init logger in start()
kalyanac Jan 22, 2021
113e641
Merge branch 'master' into master
aalexand Jan 24, 2021
4308d15
Merge branch 'master' into master
kalyanac Jan 25, 2021
85790f1
Merge branch 'master' into master
kalyanac Jan 25, 2021
092feb1
Merge branch 'master' into master
kalyanac Jan 28, 2021
6131922
Init logger in start()
kalyanac Jan 22, 2021
db1dfa8
Merge branch 'master' of https://github.com/kalyanac/google-cloud-go
kalyanac Jan 28, 2021
e768510
Merge branch 'master' into master
kalyanac Jan 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions profiler/profiler.go
Expand Up @@ -44,6 +44,7 @@ import (
"regexp"
"runtime"
"runtime/pprof"
"strings"
"sync"
"time"

Expand All @@ -67,6 +68,7 @@ var (
config Config
startOnce allowUntilSuccess
mutexEnabled bool
logger *log.Logger
// The functions below are stubbed to be overrideable for testing.
getProjectID = gcemd.ProjectID
getInstanceName = gcemd.InstanceName
Expand Down Expand Up @@ -215,6 +217,7 @@ func (o *allowUntilSuccess) do(f func() error) (err error) {
// Config for details. Start should only be called once. Any
// additional calls will be ignored.
func Start(cfg Config, options ...option.ClientOption) error {
logger = log.New(os.Stderr, "Cloud Profiler: ", log.LstdFlags|log.Lmsgprefix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into start().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

startError := startOnce.do(func() error {
return start(cfg, options...)
})
Expand Down Expand Up @@ -261,7 +264,7 @@ func start(cfg Config, options ...option.ClientOption) error {

func debugLog(format string, e ...interface{}) {
if config.DebugLogging {
log.Printf(format, e...)
logger.Printf(format, e...)
}
}

Expand Down Expand Up @@ -315,7 +318,8 @@ func (r *retryer) Retry(err error) (time.Duration, bool) {
// createProfile talks to the profiler server to create profile. In
// case of error, the goroutine will sleep and retry. Sleep duration may
// be specified by the server. Otherwise it will be an exponentially
// increasing value, bounded by maxBackoff.
// increasing value, bounded by maxBackoff. Special handling for
// certificate errors is described below.
func (a *agent) createProfile(ctx context.Context) *pb.Profile {
req := pb.CreateProfileRequest{
Parent: "projects/" + a.deployment.ProjectId,
Expand All @@ -332,6 +336,11 @@ func (a *agent) createProfile(ctx context.Context) *pb.Profile {
p, err = a.client.CreateProfile(ctx, &req, grpc.Trailer(&md))
if err != nil {
debugLog("failed to create profile, will retry: %v", err)
if strings.Contains(err.Error(), "x509: certificate signed by unknown authority") {
// gax.Invoke does not retry missing certificate error. Force a retry by returning
// a different error. See https://github.com/googleapis/google-cloud-go/issues/3158.
err = errors.New("retry the certificate error")
}
}
return err
}, gax.WithRetry(func() gax.Retryer {
Expand Down