Skip to content

Commit 726ba32

Browse files
committed
internal/telemetry/cmd/stacks: minor tweaks
Edit some documentation, make other minor changes. Also minor tweaks to internal/util/moremaps. Change-Id: I04956af5e85e1c45e18da63532fb5f11c47c50d4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/643775 Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 9f4a509 commit 726ba32

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

gopls/internal/telemetry/cmd/stacks/stacks.go

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
// single ID in the issue body suffices to record the
2222
// association. But most problems are exhibited in a variety of
2323
// ways, leading to multiple field reports of similar but
24-
// distinct stacks.
24+
// distinct stacks. Hence the following way to associate stacks
25+
// with issues.
2526
//
2627
// 2. Each GitHub issue body may start with a code block of this form:
2728
//
@@ -302,6 +303,7 @@ func (info Info) String() string {
302303
//
303304
// stacks is a map of stack text to program metadata to stack+metadata report
304305
// count.
306+
// TODO(jba): fix distinctStacks doc? It seems to be the number of telemetry.ProgramReports, not the number of stacks.
305307
// distinctStacks is the sum of all counts in stacks.
306308
// stackToURL maps the stack text to the oldest telemetry JSON report it was
307309
// included in.
@@ -339,14 +341,19 @@ func readReports(pcfg ProgramConfig, days int) (stacks map[string]map[Info]int64
339341
if len(prog.Stacks) == 0 {
340342
continue
341343
}
344+
// Ignore @devel versions as they correspond to
345+
// ephemeral (and often numerous) variations of
346+
// the program as we work on a fix to a bug.
347+
if prog.Version == "devel" {
348+
continue
349+
}
342350

343351
// Include applicable client names (e.g. vscode, eglot) for gopls.
344352
var clientSuffix string
345353
if pcfg.IncludeClient {
346354
var clients []string
347355
for key := range prog.Counters {
348-
client := strings.TrimPrefix(key, "gopls/client:")
349-
if client != key {
356+
if client, ok := strings.CutPrefix(key, "gopls/client:"); ok {
350357
clients = append(clients, client)
351358
}
352359
}
@@ -356,13 +363,6 @@ func readReports(pcfg ProgramConfig, days int) (stacks map[string]map[Info]int64
356363
}
357364
}
358365

359-
// Ignore @devel versions as they correspond to
360-
// ephemeral (and often numerous) variations of
361-
// the program as we work on a fix to a bug.
362-
if prog.Version == "devel" {
363-
continue
364-
}
365-
366366
distinctStacks++
367367

368368
info := Info{
@@ -395,6 +395,7 @@ func readIssues(pcfg ProgramConfig) ([]*Issue, error) {
395395
// Query GitHub for all existing GitHub issues with the report label.
396396
issues, err := searchIssues(pcfg.SearchLabel)
397397
if err != nil {
398+
// TODO(jba): return error instead of dying, or doc.
398399
log.Fatalf("GitHub issues label %q search failed: %v", pcfg.SearchLabel, err)
399400
}
400401

@@ -496,20 +497,6 @@ func readIssues(pcfg ProgramConfig) ([]*Issue, error) {
496497
// We log an error if two different issues attempt to claim
497498
// the same stack.
498499
func claimStacks(issues []*Issue, stacks map[string]map[Info]int64) map[string]*Issue {
499-
// Map each stack ID to its issue.
500-
//
501-
// An issue can claim a stack two ways:
502-
//
503-
// 1. if the issue body contains the ID of the stack. Matching
504-
// is a little loose but base64 will rarely produce words
505-
// that appear in the body by chance.
506-
//
507-
// 2. if the issue body contains a ```#!stacks``` predicate
508-
// that matches the stack.
509-
//
510-
// We report an error if two different issues attempt to claim
511-
// the same stack.
512-
//
513500
// This is O(new stacks x existing issues).
514501
claimedBy := make(map[string]*Issue)
515502
for stack := range stacks {

gopls/internal/util/moremaps/maps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func KeySlice[M ~map[K]V, K comparable, V any](m M) []K {
3131
return r
3232
}
3333

34-
// Values returns the values of the map M, like slices.Collect(maps.Values(m)).
34+
// ValueSlice returns the values of the map M, like slices.Collect(maps.Values(m)).
3535
func ValueSlice[M ~map[K]V, K comparable, V any](m M) []V {
3636
r := make([]V, 0, len(m))
3737
for _, v := range m {
@@ -60,7 +60,7 @@ func Sorted[M ~map[K]V, K cmp.Ordered, V any](m M) iter.Seq2[K, V] {
6060
}
6161
}
6262

63-
// SortedFunc returns an iterator over the entries of m in key order.
63+
// SortedFunc returns an iterator over the entries of m in the key order determined by cmp.
6464
func SortedFunc[M ~map[K]V, K comparable, V any](m M, cmp func(x, y K) int) iter.Seq2[K, V] {
6565
// TODO(adonovan): use maps.SortedFunc if proposal #68598 is accepted.
6666
return func(yield func(K, V) bool) {

0 commit comments

Comments
 (0)