Skip to content

insights: restrict capture group values to a max length

Administrator requested to merge insights/capture-groups-max-length into main

Created by: leonore

closes #29552 (closed).

We truncate capture group values to <= 100 characters for both just-in-time insights and insights ran over all repos for consistency, even though we only store captured values for insights ran over all repos.

Test plan

Added, and ran unit tests (with -count=20 for flakes).

On my local sourcegraph instance:

  1. Reduce the capturedValueMaxLength value to 10, for ease of search.
  2. Started up sg locally.
  3. Created an insight, e.g. patterntype:regexp compare (.*) lang:go
    • for just-in-time
    • for all repos
  4. Observed the insight was getting created, and was truncating the results.
  5. Check postgres for stored values: SELECT capture FROM series_points ORDER BY time DESC LIMIT 10;
    • also compared values for the query before/after change:
    • SELECT capture FROM series_points WHERE length(capture) > 20 ORDER BY time DESC -> returned an example (v fileInfosByName)
    • after truncation implementation, SELECT capture FROM series_points WHERE capture LIKE '%v%' ORDER BY time DESC; returned (v fileIn) (N.B. This is 10 characters with the whitespace at the front, something we might want to consider)

Merge request reports

Loading