fork of https://github.com/sourcegraph/zoekt
1// This file contains commands which run in a non daemon mode for testing/debugging.
2
3package main
4
5import (
6 "context"
7 "flag"
8 "fmt"
9 "strconv"
10
11 "github.com/peterbourgon/ff/v3/ffcli"
12)
13
14func debugIndex() *ffcli.Command {
15 fs := flag.NewFlagSet("debug index", flag.ExitOnError)
16 conf := rootConfig{}
17 conf.registerRootFlags(fs)
18
19 return &ffcli.Command{
20 Name: "index",
21 ShortUsage: "index [flags] <repository ID>",
22 ShortHelp: "index a repository",
23 FlagSet: fs,
24 Exec: func(ctx context.Context, args []string) error {
25 if len(args) == 0 {
26 return fmt.Errorf("missing repository ID")
27 }
28 s, err := newServer(conf)
29 if err != nil {
30 return err
31 }
32 id, err := strconv.Atoi(args[0])
33 if err != nil {
34 return err
35 }
36 msg, err := s.forceIndex(uint32(id))
37 infoLog.Println(msg)
38 if err != nil {
39 return err
40 }
41 return nil
42 },
43 }
44}
45
46func debugTrigrams() *ffcli.Command {
47 return &ffcli.Command{
48 Name: "trigrams",
49 ShortUsage: "trigrams <path/to/shard>",
50 ShortHelp: "list all the trigrams in a shard",
51 Exec: func(ctx context.Context, args []string) error {
52 if len(args) == 0 {
53 return fmt.Errorf("missing path to shard")
54 }
55 return printShardStats(args[0])
56 },
57 }
58}
59
60func debugMeta() *ffcli.Command {
61 return &ffcli.Command{
62 Name: "meta",
63 ShortUsage: "meta <path/to/shard>",
64 ShortHelp: "output index and repo metadata",
65 Exec: func(ctx context.Context, args []string) error {
66 if len(args) == 0 {
67 return fmt.Errorf("missing path to shard")
68 }
69 return printMetaData(args[0])
70 },
71 }
72}
73
74func debugCmd() *ffcli.Command {
75 fs := flag.NewFlagSet("debug", flag.ExitOnError)
76
77 return &ffcli.Command{
78 Name: "debug",
79 ShortUsage: "debug <subcommand>",
80 ShortHelp: "a set of commands for debugging and testing",
81 LongHelp: `
82 Zoekt-sourcegraph-indexserver exposes debug information on the /debug landing page.
83 You can use the following wget commands to access this information from the command line.
84
85 wget -q -O - http://localhost:6072/debug/indexed
86 list the repositories that are INDEXED by this instance.
87
88 wget -q -O - http://localhost:6072/debug/list[?indexed=TRUE/false]
89 list the repositories that are OWNED by this instance. If indexed=true (default), the list may contain repositories
90 that this instance holds temporarily, for example during rebalancing.
91
92 wget -q -O - http://localhost:6072/debug/merge
93 start a full merge operation in the index directory. You can check the status with
94 "wget -q -O - http://localhost:6072/metrics -sS | grep index_shard_merging_running". It is only possible
95 to trigger one merge operation at a time.
96
97 wget -q -O - http://localhost:6072/debug/queue
98 list the repositories in the indexing queue, sorted by descending priority.
99
100 COLUMN HEADERS
101 Position zero-indexed position of this repository in the indexing queue (sorted by priority).
102 Name name for this repository
103 ID ID for this repository
104 IsOnQueue "true" if this repository has an outstanding indexing job that's enqueued for future work. "false" otherwise.
105 Age amount of time that this repository has spent in the indexing queue since its outstanding indexing job
106 was first added (ignoring any job metadata updates that may have occurred while it was still enqueued).
107 A "-" is printed instead if this repository doesn't have an outstanding job.
108 Branches comma-separated list of branches in $BRANCH_NAME@$COMMIT_HASH format.
109 If the repository has a job on the indexing queue, this list represents the desired set of
110 branches + associated commits that will be process during the next indexing job.
111 However, if the repository doesn't have a job on the queue, this list represents the set of
112 branches + associated commits that was indexed during its most recent indexing job.`,
113 FlagSet: fs,
114 Subcommands: []*ffcli.Command{
115 debugIndex(),
116 debugMeta(),
117 debugTrigrams(),
118 },
119 }
120}