Log slow API requests with server spans and client timing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
@@ -13,24 +14,24 @@ func SnapshotRef(taskID string, n int) string {
|
||||
return fmt.Sprintf("%s%d", snapshotPrefix(taskID), n)
|
||||
}
|
||||
|
||||
func CommitSnapshot(dir, tree, ref, message string, env []string) (string, error) {
|
||||
head, err := Head(dir)
|
||||
func CommitSnapshot(ctx context.Context, dir, tree, ref, message string, env []string) (string, error) {
|
||||
head, err := Head(ctx, dir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
commit, err := runEnv(dir, env, "commit-tree", tree, "-p", head, "-m", message)
|
||||
commit, err := runEnv(ctx, dir, env, "commit-tree", tree, "-p", head, "-m", message)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = run(dir, "update-ref", ref, commit, "")
|
||||
_, err = run(ctx, dir, "update-ref", ref, commit, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return commit, nil
|
||||
}
|
||||
|
||||
func SnapshotRefs(repo, taskID string) ([]string, error) {
|
||||
out, err := run(repo, "for-each-ref", "--format=%(refname)", snapshotPrefix(taskID))
|
||||
func SnapshotRefs(ctx context.Context, repo, taskID string) ([]string, error) {
|
||||
out, err := run(ctx, repo, "for-each-ref", "--format=%(refname)", snapshotPrefix(taskID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -40,8 +41,8 @@ func SnapshotRefs(repo, taskID string) ([]string, error) {
|
||||
return strings.Split(out, "\n"), nil
|
||||
}
|
||||
|
||||
func DeleteSnapshotRefs(repo, taskID string) error {
|
||||
refs, err := SnapshotRefs(repo, taskID)
|
||||
func DeleteSnapshotRefs(ctx context.Context, repo, taskID string) error {
|
||||
refs, err := SnapshotRefs(ctx, repo, taskID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -53,6 +54,6 @@ func DeleteSnapshotRefs(repo, taskID string) error {
|
||||
for _, ref := range refs {
|
||||
fmt.Fprintf(b, "delete %s\n", ref)
|
||||
}
|
||||
_, err = runInput(repo, nil, b.String(), "update-ref", "--stdin")
|
||||
_, err = runInput(ctx, repo, nil, b.String(), "update-ref", "--stdin")
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user