aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/query.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2020-07-15 17:38:36 -0400
committerMichael Matloob <matloob@golang.org>2020-08-20 15:21:34 +0000
commit822dca4b383611335385ef05c2882d23f6f89d88 (patch)
treee4ad094ec4e913bbd53f5433794de328f6c2309d /src/cmd/go/internal/modload/query.go
parent3f568625980f6e23a603cfd1cb4fcd2bf5c895d7 (diff)
downloadgo-822dca4b383611335385ef05c2882d23f6f89d88.tar.gz
go-822dca4b383611335385ef05c2882d23f6f89d88.zip
cmd/go: add tracing for querying and downloading from the proxy
This CL adds tracing spans for modload.queryPattern, modload.queryProxy, modload.QueryPattern, modload.QueryPattern.queryModule, modload.queryPrefixModules and modfetch.Download. Updates #38714 Change-Id: I91af3f022a6e18ab8d9c1d9b0ccf4928b6c236bd Reviewed-on: https://go-review.googlesource.com/c/go/+/249022 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r--src/cmd/go/internal/modload/query.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go
index 39a813447c..e82eb1506f 100644
--- a/src/cmd/go/internal/modload/query.go
+++ b/src/cmd/go/internal/modload/query.go
@@ -19,6 +19,7 @@ import (
"cmd/go/internal/modfetch"
"cmd/go/internal/search"
"cmd/go/internal/str"
+ "cmd/go/internal/trace"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
@@ -77,6 +78,9 @@ func (queryDisabledError) Error() string {
}
func queryProxy(ctx context.Context, proxy, path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
+ ctx, span := trace.StartSpan(ctx, "modload.queryProxy "+path+" "+query)
+ defer span.Done()
+
if current != "" && !semver.IsValid(current) {
return nil, fmt.Errorf("invalid previous version %q", current)
}
@@ -403,6 +407,9 @@ func QueryPackage(ctx context.Context, path, query string, allowed func(module.V
// the main module and only the version "latest", without checking for other
// possible modules.
func QueryPattern(ctx context.Context, pattern, query string, allowed func(module.Version) bool) ([]QueryResult, error) {
+ ctx, span := trace.StartSpan(ctx, "modload.QueryPattern "+pattern+" "+query)
+ defer span.Done()
+
base := pattern
firstError := func(m *search.Match) error {
@@ -470,7 +477,10 @@ func QueryPattern(ctx context.Context, pattern, query string, allowed func(modul
}
err := modfetch.TryProxies(func(proxy string) error {
- queryModule := func(path string) (r QueryResult, err error) {
+ queryModule := func(ctx context.Context, path string) (r QueryResult, err error) {
+ ctx, span := trace.StartSpan(ctx, "modload.QueryPattern.queryModule ["+proxy+"] "+path)
+ defer span.Done()
+
current := findCurrentVersion(path)
r.Mod.Path = path
r.Rev, err = queryProxy(ctx, proxy, path, query, current, allowed)
@@ -499,7 +509,7 @@ func QueryPattern(ctx context.Context, pattern, query string, allowed func(modul
}
var err error
- results, err = queryPrefixModules(candidateModules, queryModule)
+ results, err = queryPrefixModules(ctx, candidateModules, queryModule)
return err
})
@@ -543,7 +553,10 @@ type prefixResult struct {
err error
}
-func queryPrefixModules(candidateModules []string, queryModule func(path string) (QueryResult, error)) (found []QueryResult, err error) {
+func queryPrefixModules(ctx context.Context, candidateModules []string, queryModule func(ctx context.Context, path string) (QueryResult, error)) (found []QueryResult, err error) {
+ ctx, span := trace.StartSpan(ctx, "modload.queryPrefixModules")
+ defer span.Done()
+
// If the path we're attempting is not in the module cache and we don't have a
// fetch result cached either, we'll end up making a (potentially slow)
// request to the proxy or (often even slower) the origin server.
@@ -556,8 +569,9 @@ func queryPrefixModules(candidateModules []string, queryModule func(path string)
var wg sync.WaitGroup
wg.Add(len(candidateModules))
for i, p := range candidateModules {
+ ctx := trace.StartGoroutine(ctx)
go func(p string, r *result) {
- r.QueryResult, r.err = queryModule(p)
+ r.QueryResult, r.err = queryModule(ctx, p)
wg.Done()
}(p, &results[i])
}