Skip to content

Commit db05d06

Browse files
feat: Update Rabbitmq parser to use LoggingReceiverMacro (#2038)
Co-authored-by: Francisco Valente Castro <1435136+franciscovalentecastro@users.noreply.github.com>
1 parent e5dad6b commit db05d06

30 files changed

Lines changed: 252 additions & 93 deletions

File tree

apps/rabbitmq.go

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -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

116105
func init() {
117-
confgenerator.LoggingReceiverTypes.RegisterType(func() confgenerator.LoggingReceiver { return &LoggingReceiverRabbitmq{} })
106+
confgenerator.RegisterLoggingFilesProcessorMacro[LoggingProcessorMacroRabbitmq](loggingReceiverFilesMixinRabbitmq)
118107
}
119108

120109
type MetricsReceiverRabbitmq struct {

confgenerator/testdata/feature/golden.csv

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ App,Field,Override,
4242
*apps.LoggingReceiverOracleDBAudit,confgenerator.LoggingReceiverFilesMixin.BufferInMemory,
4343
*apps.LoggingReceiverOracleDBAudit,confgenerator.LoggingReceiverFilesMixin.RecordLogFilePath,
4444
*apps.LoggingReceiverOracleDBAudit,confgenerator.LoggingReceiverFilesMixin.WildcardRefreshInterval,
45-
*apps.LoggingReceiverRabbitmq,apps.LoggingProcessorRabbitmq.confgenerator.ConfigComponent.Type,
46-
*apps.LoggingReceiverRabbitmq,confgenerator.LoggingReceiverFilesMixin.BufferInMemory,
47-
*apps.LoggingReceiverRabbitmq,confgenerator.LoggingReceiverFilesMixin.RecordLogFilePath,
48-
*apps.LoggingReceiverRabbitmq,confgenerator.LoggingReceiverFilesMixin.WildcardRefreshInterval,
4945
*apps.LoggingReceiverSapHanaTrace,apps.LoggingProcessorSapHanaTrace.confgenerator.ConfigComponent.Type,
5046
*apps.LoggingReceiverSapHanaTrace,confgenerator.LoggingReceiverFilesMixin.BufferInMemory,
5147
*apps.LoggingReceiverSapHanaTrace,confgenerator.LoggingReceiverFilesMixin.RecordLogFilePath,
@@ -178,6 +174,7 @@ App,Field,Override,
178174
*confgenerator.loggingProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroNginxAccess],confgenerator.ConfigComponent.Type,
179175
*confgenerator.loggingProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroNginxError],confgenerator.ConfigComponent.Type,
180176
*confgenerator.loggingProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroPostgresql],confgenerator.ConfigComponent.Type,
177+
*confgenerator.loggingProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroRabbitmq],confgenerator.ConfigComponent.Type,
181178
*confgenerator.loggingProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroRedis],confgenerator.ConfigComponent.Type,
182179
*confgenerator.loggingProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroSolrSystem],apps.LoggingProcessorMacroSolrSystem.confgenerator.ConfigComponent.Type,
183180
*confgenerator.loggingProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroSolrSystem],confgenerator.ConfigComponent.Type,
@@ -218,6 +215,8 @@ App,Field,Override,
218215
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroNginxError]],confgenerator.ConfigComponent.Type,
219216
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroPostgresql]],ReceiverMacro,
220217
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroPostgresql]],confgenerator.ConfigComponent.Type,
218+
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroRabbitmq]],ReceiverMacro,
219+
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroRabbitmq]],confgenerator.ConfigComponent.Type,
221220
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroRedis]],ReceiverMacro,
222221
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroRedis]],confgenerator.ConfigComponent.Type,
223222
*confgenerator.loggingReceiverMacroAdapter[*github.com/GoogleCloudPlatform/ops-agent/confgenerator.loggingFilesProcessorMacroAdapter[github.com/GoogleCloudPlatform/ops-agent/apps.LoggingProcessorMacroSolrSystem]],ReceiverMacro,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].
1+
logging processor with type "unsupported_type" is not supported. Supported logging processor types: [apache_access, apache_error, cassandra_debug, cassandra_gc, cassandra_system, couchdb, elasticsearch_gc, elasticsearch_json, exclude_logs, flink, hbase_system, iis_access, jetty_access, kafka, modify_fields, mysql_error, mysql_general, mysql_slow, nginx_access, nginx_error, oracledb_alert, oracledb_audit, parse_json, parse_multiline, parse_regex, postgresql_general, rabbitmq, redis, saphana, solr_system, tomcat_access, tomcat_system, varnish, wildfly_system].

0 commit comments

Comments
 (0)