Skip to content

Commit

Permalink
Add even more tracing (#28)
Browse files Browse the repository at this point in the history
Now every function that interacts with git2go should in theory be
traced, both here and in githttp.
  • Loading branch information
lhchavez authored Dec 2, 2021
1 parent e9c0aac commit 01277c3
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 72 deletions.
5 changes: 4 additions & 1 deletion cmd/omegaup-gitserver/health_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"errors"
"io"
"io/ioutil"
Expand Down Expand Up @@ -32,6 +33,8 @@ func TestHealth(t *testing.T) {
defer os.RemoveAll(tmpDir)
}

ctx := context.Background()

log := base.StderrLog(false)
ts := httptest.NewUnstartedServer(nil)
_, portString, err := net.SplitHostPort(ts.Listener.Addr().String())
Expand Down Expand Up @@ -69,7 +72,7 @@ func TestHealth(t *testing.T) {

problemAlias := "sumas"

repo, err := gitserver.InitRepository(path.Join(tmpDir, problemAlias))
repo, err := gitserver.InitRepository(ctx, path.Join(tmpDir, problemAlias))
if err != nil {
t.Fatalf("Failed to initialize git repository: %v", err)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/omegaup-translate-problem/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ func createPackfileFromMergedCommit(
}

func unmergeRepository(
ctx context.Context,
sourceRepositoryPath,
destRepositoryPath string,
ignoreCommitter bool,
Expand All @@ -468,7 +469,7 @@ func unmergeRepository(
}
defer sourceRepo.Free()

destRepo, err := gitserver.InitRepository(destRepositoryPath)
destRepo, err := gitserver.InitRepository(ctx, destRepositoryPath)
if err != nil {
return nil, errors.Wrapf(
err,
Expand Down Expand Up @@ -606,6 +607,7 @@ func main() {
os.Exit(1)
}

ctx := context.Background()
operation := args[0]
sourceRepositoryPath := args[1]
destRepositoryPath := args[2]
Expand Down Expand Up @@ -635,7 +637,7 @@ func main() {
}
defer f.Close()

report, err := unmergeRepository(sourceRepositoryPath, destRepositoryPath, *ignoreCommitter, log)
report, err := unmergeRepository(ctx, sourceRepositoryPath, destRepositoryPath, *ignoreCommitter, log)
if err != nil {
log.Crit(
"failed to unmerge repository",
Expand Down
4 changes: 3 additions & 1 deletion cmd/omegaup-translate-problem/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"io/ioutil"
"os"
"path"
Expand All @@ -18,6 +19,7 @@ func TestRoundtrip(t *testing.T) {
if os.Getenv("PRESERVE") == "" {
defer os.RemoveAll(dirName)
}
ctx := context.Background()

log := base.StderrLog(false)

Expand All @@ -27,7 +29,7 @@ func TestRoundtrip(t *testing.T) {
if err := mergeRepository("testdata/sumas.git", mergedPath, log); err != nil {
t.Fatalf("failed to merge repository: %v", err)
}
got, err := unmergeRepository(mergedPath, unmergedPath, false, log)
got, err := unmergeRepository(ctx, mergedPath, unmergedPath, false, log)
if err != nil {
t.Fatalf("failed to unmerge repository: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/omegaup-update-problem/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func commitBlobs(
return nil, err
}

updatedFiles, err := gitserver.GetUpdatedFiles(repo, updatedRefs)
updatedFiles, err := gitserver.GetUpdatedFiles(ctx, repo, updatedRefs)
if err != nil {
log.Error("failed to get updated files", "err", err)
}
Expand Down Expand Up @@ -358,6 +358,7 @@ func main() {
os.Exit(1)
}

ctx := context.Background()
var repo *git.Repository
commitCallback := func() error { return nil }
if _, err := os.Stat(*repositoryPath); os.IsNotExist(err) {
Expand All @@ -373,7 +374,7 @@ func main() {
os.Exit(1)
}

repo, err = gitserver.InitRepository(dir)
repo, err = gitserver.InitRepository(ctx, dir)
if err != nil {
log.Crit("Failed to init bare repository", "err", err)
os.Exit(1)
Expand Down
11 changes: 8 additions & 3 deletions cmd/omegaup-update-problem/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"archive/zip"
"bytes"
"context"
"io"
"io/ioutil"
"os"
Expand All @@ -20,6 +21,8 @@ import (
)

func getTreeOid(t *testing.T, extraFileContents map[string]io.Reader, log log15.Logger) *git.Oid {
t.Helper()
ctx := context.Background()
tmpdir, err := ioutil.TempDir("", "gitrepo")
if err != nil {
t.Fatalf("Failed to create tempdir: %v", err)
Expand All @@ -45,7 +48,7 @@ func getTreeOid(t *testing.T, extraFileContents map[string]io.Reader, log log15.
t.Fatalf("Failed to write zip: %v", err)
}

repo, err := gitserver.InitRepository(tmpdir)
repo, err := gitserver.InitRepository(ctx, tmpdir)
if err != nil {
t.Fatalf("Failed to initialize bare repository: %v", err)
}
Expand Down Expand Up @@ -202,8 +205,9 @@ func TestProblemUpdateZip(t *testing.T) {
if os.Getenv("PRESERVE") == "" {
defer os.RemoveAll(tmpdir)
}
ctx := context.Background()

repo, err := gitserver.InitRepository(tmpdir)
repo, err := gitserver.InitRepository(ctx, tmpdir)
if err != nil {
t.Fatalf("Failed to initialize bare repository: %v", err)
}
Expand Down Expand Up @@ -335,8 +339,9 @@ func TestProblemUpdateBlobs(t *testing.T) {
if os.Getenv("PRESERVE") == "" {
defer os.RemoveAll(tmpdir)
}
ctx := context.Background()

repo, err := gitserver.InitRepository(tmpdir)
repo, err := gitserver.InitRepository(ctx, tmpdir)
if err != nil {
t.Fatalf("Failed to initialize bare repository: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.8
github.com/newrelic/go-agent/v3 v3.15.1
github.com/o1egl/paseto v1.0.0
github.com/omegaup/githttp/v2 v2.2.0
github.com/omegaup/githttp/v2 v2.2.1
github.com/omegaup/go-base/tracing/newrelic v0.0.0-20211201150123-3ace5d86e12a
github.com/omegaup/go-base/v2 v2.3.0
github.com/omegaup/quark v1.8.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/omegaup/githttp/v2 v2.2.0 h1:KehjPh4s0L9Oj3HG7bMykqa/tZ3hDATpNQ6q9ql9in8=
github.com/omegaup/githttp/v2 v2.2.0/go.mod h1:QOU20srNzkvDPsJpFbloR9yWrlwCcRW7Q2d9tIW3x/M=
github.com/omegaup/githttp/v2 v2.2.1 h1:dEpQDSQB7HOGDuX5oh93YqT/f3Be1QsnO+r03P6jopI=
github.com/omegaup/githttp/v2 v2.2.1/go.mod h1:QOU20srNzkvDPsJpFbloR9yWrlwCcRW7Q2d9tIW3x/M=
github.com/omegaup/go-base/tracing/newrelic v0.0.0-20211201150123-3ace5d86e12a h1:vORkEPKY98j2/dqacWsrj/4uEM3qecgLMjwPZgBGH04=
github.com/omegaup/go-base/tracing/newrelic v0.0.0-20211201150123-3ace5d86e12a/go.mod h1:oFTFEE0LxFk4ahZfZe+rV0aPdJbtSiDoTlvrGZXqTyY=
github.com/omegaup/go-base/v2 v2.3.0 h1:u5juOm0O96ZeuJu3xYSwvyGtstIkCEDT/F016gzSfow=
Expand Down
Loading

0 comments on commit 01277c3

Please sign in to comment.