Debian Codegraph @

core/lstream_cmd.go

raw
1 package core
2
3 import "time"
4
5 type lstreamCmd struct {
6 // respCh must be either nil, or 1-buffered and it'll receive exactly one
7 // message.
8 respCh chan lstreamCmdRes
9
10 // Exactly one of the fields below must be non-nil.
11
12 bootstrap *lstreamCmdBootstrap
13 ping *lstreamCmdPing
14 queryLogs *lstreamCmdQueryLogs
15 }
16
17 type lstreamCmdCtx struct {
18 cmd lstreamCmd
19
20 idx int
21
22 bootstrapCtx *lstreamCmdCtxBootstrap
23 pingCtx *lstreamCmdCtxPing
24 queryLogsCtx *lstreamCmdCtxQueryLogs
25
26 // Initially, stdoutDoneIdx and stderrDoneIdx are set to false. Once we
27 // receive the "command_done" marker from either stdout or stderr, we set the
28 // corresponding bool here to true. Once both are set, we consider the
29 // command execution done, and parse the results.
30 stdoutDone bool
31 stderrDone bool
32
33 // errs contains all errors accumulated during command execution. This
34 // includes errors printed by the nerdlog_agent.sh (lines starting from
35 // "error:", on either stderr or stdout), as well as any errors generated
36 // on the Go side, e.g. failure to parse some other output.
37 errs []error
38
39 exitCode string
40
41 // unhandledStdout and unhandledStderr contain the lines which the Go app did
42 // not make sense of. These are usually ignored, but if the the
43 // nerdlog_agent.sh returns an error code, and there are no specific errors
44 // printed (lines with the "error:" prefix), then we'll print all these
45 // as an error message.
46 unhandledStdout []string
47 unhandledStderr []string
48 }
49
50 type lstreamCmdRes struct {
51 hostname string
52
53 err error
54 resp interface{}
55 }
56
57 type lstreamCmdBootstrap struct{}
58
59 type lstreamCmdCtxBootstrap struct {
60 receivedSuccess bool
61 receivedFailure bool
62
63 // warnJournalctlNoAdminAccess is set to true if journalctl is used and the
64 // user doesn't have access to all the system logs. It's a separate bool
65 // instead of a generic warning message to make it possible to suppress it
66 // with a flag.
67 warnJournalctlNoAdminAccess bool
68 }
69
70 type lstreamCmdPing struct{}
71
72 type lstreamCmdCtxPing struct {
73 }
74
75 type lstreamCmdQueryLogs struct {
76 maxNumLines int
77
78 from time.Time
79 to time.Time
80
81 query string
82
83 // If linesUntil is not zero, it'll be passed to nerdlog_agent.sh as --lines-until.
84 // Effectively, only logs BEFORE this log line (not including it) will be output.
85 linesUntil int
86
87 // timestampUntil is not zero, it'll be passed to nerdlog_agent as
88 // --timestamp-until-precise and --timestamp-until-seconds. It serves the
89 // same purpose as linesUntil for cases when we don't have line numbers (e.g.
90 // when using journalctl).
91 timestampUntil *timeAndNumMsgs
92
93 // If refreshIndex is true, we'll drop the index file, and rebuild it from
94 // scratch (no-op for journalctl logstreams, because there's no
95 // nerdlog-maintained index for journalctl).
96 refreshIndex bool
97 }
98
99 type lstreamCmdCtxQueryLogs struct {
100 Resp *LogResp
101
102 logfiles []logfileWithStartingLinenumber
103 lastTime time.Time
104 }
105
106 type logfileWithStartingLinenumber struct {
107 filename string
108 fromLinenumber int
109 }