fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

metrics: add ability to capture per-repository indexing metrics (#239)

+34 -2
+34 -2
cmd/zoekt-sourcegraph-indexserver/main.go
··· 63 63 Name: "index_repo_seconds", 64 64 Help: "A histogram of latencies for indexing a repository.", 65 65 Buckets: prometheus.ExponentialBuckets(.1, 10, 7), // 100ms -> 27min 66 - }, []string{"state"}) // state is an indexState 66 + }, []string{ 67 + "state", // state is an indexState 68 + "name", // name of the repository that was indexed 69 + }) 67 70 68 71 metricIndexIncrementalIndexState = promauto.NewCounterVec(prometheus.CounterOpts{ 69 72 Name: "index_incremental_index_state", ··· 90 93 Help: "Counts indexings (indexing activity, should be used with rate())", 91 94 }) 92 95 ) 96 + 97 + // set of repositories that we want to capture separate indexing metrics for 98 + var reposWithSeparateIndexingMetrics = make(map[string]struct{}) 93 99 94 100 type indexState string 95 101 ··· 345 351 state, err := s.Index(args) 346 352 s.muIndexDir.Unlock() 347 353 348 - metricIndexDuration.WithLabelValues(string(state)).Observe(time.Since(start).Seconds()) 354 + // Check to see if we want to be able to capture separate indexing metrics for this repository. 355 + // If we don't, set to a default string to keep the cardinality for the Prometheus metric manageable. 356 + repoNameForMetric := "" 357 + if _, ok = reposWithSeparateIndexingMetrics[opts.Name]; ok { 358 + repoNameForMetric = opts.Name 359 + } 360 + 361 + metricIndexDuration.WithLabelValues(string(state), repoNameForMetric).Observe(time.Since(start).Seconds()) 362 + 349 363 if err != nil { 350 364 log.Printf("error indexing %s: %s", args.String(), err) 351 365 } ··· 753 767 754 768 if *dbg || isDebugCmd { 755 769 debug = log.New(os.Stderr, "", log.LstdFlags) 770 + } 771 + 772 + indexingMetricsReposAllowlist := os.Getenv("INDEXING_METRICS_REPOS_ALLOWLIST") 773 + if indexingMetricsReposAllowlist != "" { 774 + var repos []string 775 + 776 + for _, r := range strings.Split(indexingMetricsReposAllowlist, ",") { 777 + r = strings.TrimSpace(r) 778 + if r != "" { 779 + repos = append(repos, r) 780 + } 781 + } 782 + 783 + for _, r := range repos { 784 + reposWithSeparateIndexingMetrics[r] = struct{}{} 785 + } 786 + 787 + debug.Printf("capturing separate indexing metrics for: %s", repos) 756 788 } 757 789 758 790 var sg Sourcegraph