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: don't panic when datadog APM socket cannot be found, retry to wait for it to become available #181

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/gitdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func setupJWT(cfg config, m *mux.Router, h *gitdb.CheckoutHandler, logger *log.L
if err != nil {
return fmt.Errorf("unable to parse public key in file %s: %w", cfg.JWTPublicKey, err)
}
keyFunc := func(token *jwt.Token) (interface{}, error) {
keyFunc := func(_ *jwt.Token) (interface{}, error) {
return parsedPublicKey, nil
}
h.SetupPublicJWTHandler(m, keyFunc, repoConfig.Repositories)
Expand Down Expand Up @@ -300,7 +300,7 @@ func setupJWTSigning(ctx context.Context, cfg config, log *log.Logger, m *mux.Ro
Auth: func(username string, password string) (bool, error) {
return username == cfg.JWTSignInUsername && password == cfg.JWTSignInPassword, nil
},
SigningString: func(username string) *rsa.PrivateKey {
SigningString: func(_ string) *rsa.PrivateKey {
return pKey
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gitdb/goget/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (g *GitCheckout) LsDir(ctx context.Context, dir string, branch string) (ret
if err != nil {
return nil, &unknownBranch{branch: branch, wraps: err}
}
retErr = g.tracing.StartSpanFromContext(ctx, tracing.SpanConfig{OperationName: "ls_dir"}, func(ctx context.Context) error {
retErr = g.tracing.StartSpanFromContext(ctx, tracing.SpanConfig{OperationName: "ls_dir"}, func(_ context.Context) error {
co, err := g.repo.CommitObject(r.Hash())
if err != nil {
return fmt.Errorf("unable to make commit object for hash %s: %w", r.Hash(), err)
Expand Down
15 changes: 13 additions & 2 deletions internal/gitdb/tracing/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,25 @@ func envToStruct(env []string, into interface{}) error {
return json.Unmarshal(b, into)
}

func verifyFileExistsWithRetry(file string, retries int, delay time.Duration) bool {
for i := 0; i < retries; i++ {
if fileExists(file) {
return true
}
time.Sleep(delay)
}
return false
}

func NewTracer(originalConfig tracing.Config) (tracing.Tracing, error) {
var cfg config
if err := envToStruct(originalConfig.Env, &cfg); err != nil {
return nil, fmt.Errorf("unable to convert env to config: %w", err)
}
if !fileExists(cfg.apmFile()) {
// the datadog APM socket is mounted from the host, sometimes it is not available immediately
if !verifyFileExistsWithRetry(cfg.apmFile(), 10, 1*time.Second) {
originalConfig.Log.Info(context.Background(), "Unable to find datadog APM file", zap.String("file_name", cfg.apmFile()))
return nil, nil
return nil, fmt.Errorf("unable to find datadog APM file: %s", cfg.apmFile())
}
u := &unixRoundTripper{
file: cfg.apmFile(),
Expand Down
4 changes: 2 additions & 2 deletions internal/httpserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestJWTSignIn(t *testing.T) {
Auth: func(username string, password string) (bool, error) {
return username == "user" && password == "pass", nil
},
SigningString: func(username string) *rsa.PrivateKey {
SigningString: func(_ string) *rsa.PrivateKey {
return pk
},
}
Expand All @@ -31,7 +31,7 @@ func TestJWTSignIn(t *testing.T) {
j.ServeHTTP(rec, req)
require.Equal(t, http.StatusOK, rec.Code)

tok, err := jwt.Parse(rec.Body.String(), func(token *jwt.Token) (interface{}, error) {
tok, err := jwt.Parse(rec.Body.String(), func(_ *jwt.Token) (interface{}, error) {
return pk.Public(), nil
})
require.NoError(t, err)
Expand Down
Loading