@@ -18,45 +18,62 @@ import (
1818 "context"
1919
2020 "github.com/GoogleCloudPlatform/ops-agent/confgenerator"
21- "github.com/GoogleCloudPlatform/ops-agent/confgenerator/fluentbit"
2221 "github.com/GoogleCloudPlatform/ops-agent/confgenerator/otel"
2322 "github.com/GoogleCloudPlatform/ops-agent/internal/secret"
2423)
2524
26- type LoggingProcessorRabbitmq struct {
27- confgenerator.ConfigComponent `yaml:",inline"`
28- }
25+ type LoggingProcessorMacroRabbitmq struct {}
2926
30- func (* LoggingProcessorRabbitmq ) Type () string {
27+ func (LoggingProcessorMacroRabbitmq ) Type () string {
3128 return "rabbitmq"
3229}
3330
34- func (p * LoggingProcessorRabbitmq ) Components (ctx context.Context , tag , uid string ) []fluentbit.Component {
35- c := confgenerator.LoggingProcessorParseRegexComplex {
36- Parsers : []confgenerator.RegexParser {
37- {
38- // Sample log line:
39- // 2022-01-31 18:01:20.441571+00:00 [erro] <0.692.0> ** Connection attempt from node 'rabbit_ctl_17@keith-testing-rabbitmq' rejected. Invalid challenge reply. **
40- Regex : `^(?<timestamp>\d+-\d+-\d+\s+\d+:\d+:\d+[.,]\d+\+\d+:\d+) \[(?<severity>\w+)\] \<(?<process_id>\d+\.\d+\.\d+)\> (?<message>.*)$` ,
41- Parser : confgenerator.ParserShared {
42- TimeKey : "timestamp" ,
43- TimeFormat : "%Y-%m-%d %H:%M:%S.%L%z" ,
31+ func (p LoggingProcessorMacroRabbitmq ) Expand (ctx context.Context ) []confgenerator.InternalLoggingProcessor {
32+ return []confgenerator.InternalLoggingProcessor {
33+ confgenerator.LoggingProcessorParseMultilineRegex {
34+ LoggingProcessorParseRegexComplex : confgenerator.LoggingProcessorParseRegexComplex {
35+ Parsers : []confgenerator.RegexParser {
36+ {
37+ // Sample log line:
38+ // 2022-01-31 18:01:20.441571+00:00 [erro] <0.692.0> ** Connection attempt from node 'rabbit_ctl_17@keith-testing-rabbitmq' rejected. Invalid challenge reply. **
39+ Regex : `^(?<timestamp>\d+-\d+-\d+\s+\d+:\d+:\d+[.,]\d+\+\d+:\d+) \[(?<severity>\w+)\] \<(?<process_id>\d+\.\d+\.\d+)\> (?<message>.*)$` ,
40+ Parser : confgenerator.ParserShared {
41+ TimeKey : "timestamp" ,
42+ TimeFormat : "%Y-%m-%d %H:%M:%S.%L%z" ,
43+ },
44+ },
45+ {
46+ // Sample log line:
47+ // 2023-02-01 12:45:14.705 [info] <0.801.0> Successfully set user tags for user 'admin' to [administrator]
48+ Regex : `^(?<timestamp>\d+-\d+-\d+\s+\d+:\d+:\d+[.,]\d+\d+\d+) \[(?<severity>\w+)\] \<(?<process_id>\d+\.\d+\.\d+)\> (?<message>.*)$` ,
49+ Parser : confgenerator.ParserShared {
50+ TimeKey : "timestamp" ,
51+ TimeFormat : "%Y-%m-%d %H:%M:%S.%L" ,
52+ },
53+ },
4454 },
4555 },
46- {
47- // Sample log line:
48- // 2023-02-01 12:45:14.705 [info] <0.801.0> Successfully set user tags for user 'admin' to [administrator]
49- Regex : `^(?<timestamp>\d+-\d+-\d+\s+\d+:\d+:\d+[.,]\d+\d+\d+) \[(?<severity>\w+)\] \<(?<process_id>\d+\.\d+\.\d+)\> (?<message>.*)$` ,
50- Parser : confgenerator.ParserShared {
51- TimeKey : "timestamp" ,
52- TimeFormat : "%Y-%m-%d %H:%M:%S.%L" ,
56+ // Some multiline entries related to crash logs are important to capture and end in
57+ //
58+ // 2022-01-31 18:07:43.557042+00:00 [erro] <0.130.0>
59+ // BOOT FAILED
60+ // ===========
61+ // ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@keith-testing-rabbitmq
62+ //
63+ Rules : []confgenerator.MultilineRule {
64+ {
65+ StateName : "start_state" ,
66+ NextState : "cont" ,
67+ Regex : `^\d+-\d+-\d+ \d+:\d+:\d+\.\d+\+\d+:\d+` ,
68+ },
69+ {
70+ StateName : "cont" ,
71+ NextState : "cont" ,
72+ Regex : `^(?!\d+-\d+-\d+ \d+:\d+:\d+\.\d+\+\d+:\d+)` ,
5373 },
5474 },
5575 },
56- }.Components (ctx , tag , uid )
57-
58- // severities documented here: https://www.rabbitmq.com/logging.html#log-levels
59- c = append (c ,
76+ // severities documented here: https://www.rabbitmq.com/logging.html#log-levels
6077 confgenerator.LoggingProcessorModifyFields {
6178 Fields : map [string ]* confgenerator.ModifyField {
6279 "severity" : {
@@ -72,49 +89,21 @@ func (p *LoggingProcessorRabbitmq) Components(ctx context.Context, tag, uid stri
7289 },
7390 InstrumentationSourceLabel : instrumentationSourceValue (p .Type ()),
7491 },
75- }.Components (ctx , tag , uid )... ,
76- )
77-
78- return c
79- }
80-
81- type LoggingReceiverRabbitmq struct {
82- LoggingProcessorRabbitmq `yaml:",inline"`
83- ReceiverMixin confgenerator.LoggingReceiverFilesMixin `yaml:",inline" validate:"structonly"`
92+ },
93+ }
8494}
8595
86- func ( r LoggingReceiverRabbitmq ) Components ( ctx context. Context , tag string ) []fluentbit. Component {
87- if len ( r . ReceiverMixin . IncludePaths ) == 0 {
88- r . ReceiverMixin . IncludePaths = []string {
96+ func loggingReceiverFilesMixinRabbitmq () confgenerator. LoggingReceiverFilesMixin {
97+ return confgenerator. LoggingReceiverFilesMixin {
98+ IncludePaths : []string {
8999 "/var/log/rabbitmq/rabbit*.log" ,
90- }
91- }
92- // Some multiline entries related to crash logs are important to capture and end in
93- //
94- // 2022-01-31 18:07:43.557042+00:00 [erro] <0.130.0>
95- // BOOT FAILED
96- // ===========
97- // ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@keith-testing-rabbitmq
98- //
99- r .ReceiverMixin .MultilineRules = []confgenerator.MultilineRule {
100- {
101- StateName : "start_state" ,
102- NextState : "cont" ,
103- Regex : `^\d+-\d+-\d+ \d+:\d+:\d+\.\d+\+\d+:\d+` ,
104- },
105- {
106- StateName : "cont" ,
107- NextState : "cont" ,
108- Regex : `^(?!\d+-\d+-\d+ \d+:\d+:\d+\.\d+\+\d+:\d+)` ,
109100 },
110101 }
111- c := r .ReceiverMixin .Components (ctx , tag )
112- c = append (c , r .LoggingProcessorRabbitmq .Components (ctx , tag , "rabbitmq" )... )
113- return c
102+
114103}
115104
116105func init () {
117- confgenerator .LoggingReceiverTypes . RegisterType ( func () confgenerator. LoggingReceiver { return & LoggingReceiverRabbitmq {} } )
106+ confgenerator.RegisterLoggingFilesProcessorMacro [ LoggingProcessorMacroRabbitmq ]( loggingReceiverFilesMixinRabbitmq )
118107}
119108
120109type MetricsReceiverRabbitmq struct {
0 commit comments