···6363 Name: "index_repo_seconds",
6464 Help: "A histogram of latencies for indexing a repository.",
6565 Buckets: prometheus.ExponentialBuckets(.1, 10, 7), // 100ms -> 27min
6666- }, []string{"state"}) // state is an indexState
6666+ }, []string{
6767+ "state", // state is an indexState
6868+ "name", // name of the repository that was indexed
6969+ })
67706871 metricIndexIncrementalIndexState = promauto.NewCounterVec(prometheus.CounterOpts{
6972 Name: "index_incremental_index_state",
···9093 Help: "Counts indexings (indexing activity, should be used with rate())",
9194 })
9295)
9696+9797+// set of repositories that we want to capture separate indexing metrics for
9898+var reposWithSeparateIndexingMetrics = make(map[string]struct{})
939994100type indexState string
95101···345351 state, err := s.Index(args)
346352 s.muIndexDir.Unlock()
347353348348- metricIndexDuration.WithLabelValues(string(state)).Observe(time.Since(start).Seconds())
354354+ // Check to see if we want to be able to capture separate indexing metrics for this repository.
355355+ // If we don't, set to a default string to keep the cardinality for the Prometheus metric manageable.
356356+ repoNameForMetric := ""
357357+ if _, ok = reposWithSeparateIndexingMetrics[opts.Name]; ok {
358358+ repoNameForMetric = opts.Name
359359+ }
360360+361361+ metricIndexDuration.WithLabelValues(string(state), repoNameForMetric).Observe(time.Since(start).Seconds())
362362+349363 if err != nil {
350364 log.Printf("error indexing %s: %s", args.String(), err)
351365 }
···753767754768 if *dbg || isDebugCmd {
755769 debug = log.New(os.Stderr, "", log.LstdFlags)
770770+ }
771771+772772+ indexingMetricsReposAllowlist := os.Getenv("INDEXING_METRICS_REPOS_ALLOWLIST")
773773+ if indexingMetricsReposAllowlist != "" {
774774+ var repos []string
775775+776776+ for _, r := range strings.Split(indexingMetricsReposAllowlist, ",") {
777777+ r = strings.TrimSpace(r)
778778+ if r != "" {
779779+ repos = append(repos, r)
780780+ }
781781+ }
782782+783783+ for _, r := range repos {
784784+ reposWithSeparateIndexingMetrics[r] = struct{}{}
785785+ }
786786+787787+ debug.Printf("capturing separate indexing metrics for: %s", repos)
756788 }
757789758790 var sg Sourcegraph