Debian Codegraph @

core/core.go

raw
1 package core
2
3 import "time"
4
5 const (
6 // MaxNumLinesDefault is a default for QueryLogsParams.MaxNumLines below.
7 MaxNumLinesDefault = 250
8 )
9
10 type QueryLogsParams struct {
11 // maxNumLines is how many log lines the nerdlog_agent.sh will return at
12 // most.
13 MaxNumLines int
14
15 From time.Time
16 To time.Time
17
18 Query string
19
20 // If LoadEarlier is true, it means we're only loading the logs _before_ the ones
21 // we already had.
22 LoadEarlier bool
23
24 // If DontAddHistoryItem is true, the browser-like history will not be
25 // populated with a new item (it should be used exactly when we're navigating
26 // this browser-like history back and forth)
27 DontAddHistoryItem bool
28
29 // If RefreshIndex is true, we'll drop the index file for all logstreams, and
30 // rebuild it from scratch (no-op for journalctl logstreams, because there's
31 // no nerdlog-maintained index for journalctl).
32 RefreshIndex bool
33 }
34
35 // LogResp is a log response from a single logstream
36 type LogResp struct {
37 // MinuteStats is a map from the unix timestamp (in seconds) to the stats for
38 // the minute starting at this timestamp.
39 MinuteStats map[int64]MinuteStatsItem
40
41 Logs []LogMsg
42
43 // NumMsgsTotal is the total number of messages in the time range (and
44 // included in MinuteStats). This number is usually larger than len(Logs).
45 NumMsgsTotal int
46
47 // DebugInfo contains info collected during this particular query.
48 DebugInfo LogstreamDebugInfo
49 }
50
51 type LogstreamDebugInfo struct {
52 // AgentStdout and AgentStderr contain arbitrary human-readable debugging
53 // info printed by the agent script.
54 AgentStdout []string
55 AgentStderr []string
56 }
57
58 // LogRespTotal is a log response from a LStreamsManager. It's merged from
59 // multiple LogResp's and it also contains some extra field(s), e.g. LoadedEarlier.
60 type LogRespTotal struct {
61 // If LoadedEarlier is true, it means we've just loaded more logs instead of replacing
62 // the logs (the Logs slice still contains everything though).
63 LoadedEarlier bool
64
65 // MinuteStats is a map from the unix timestamp (in seconds) to the stats for
66 // the minute starting at this timestamp.
67 MinuteStats map[int64]MinuteStatsItem
68
69 Logs []LogMsg
70
71 // NumMsgsTotal is the total number of messages in the time range (and
72 // included in MinuteStats). This number is usually larger than len(Logs).
73 NumMsgsTotal int
74
75 Errs []error
76
77 // DebugInfo is a map from the logstream name to the corresponding debug info
78 // collected during this particular query.
79 DebugInfo map[string]LogstreamDebugInfo
80
81 // QueryDur shows how long the query took.
82 QueryDur time.Duration
83 }
84
85 type MinuteStatsItem struct {
86 NumMsgs int
87 }
88
89 type LogMsg struct {
90 Time time.Time
91 DecreasedTimestamp bool
92
93 // LogFilename and LogLinenumber are file ane line number in that file
94 LogFilename string
95 LogLinenumber int
96
97 // CombinedLinenumber is the line number in pseudo-file: all (actually just
98 // two) log files concatenated. This is the linenumbers output by the
99 // nerdlog_agent.sh for every "msg:" line, and this is the linenumber
100 // which should be used for --lines-until param.
101 CombinedLinenumber int
102
103 Msg string
104 Context map[string]string
105 Level LogLevel
106
107 OrigLine string
108 }
109
110 type LogLevel string
111
112 const LogLevelUnknown LogLevel = ""
113 const LogLevelDebug LogLevel = "debug"
114 const LogLevelInfo LogLevel = "info"
115 const LogLevelWarn LogLevel = "warn"
116 const LogLevelError LogLevel = "error"