@@ -149,38 +149,35 @@ func init() {
149149 confgenerator .MetricsReceiverTypes .RegisterType (func () confgenerator.MetricsReceiver { return & MetricsReceiverElasticsearch {} })
150150}
151151
152- type LoggingProcessorElasticsearchJson struct {
153- confgenerator.ConfigComponent `yaml:",inline"`
152+ type LoggingProcessorMacroElasticsearchJson struct {
154153}
155154
156- func (LoggingProcessorElasticsearchJson ) Type () string {
155+ func (LoggingProcessorMacroElasticsearchJson ) Type () string {
157156 return "elasticsearch_json"
158157}
159158
160- func (p LoggingProcessorElasticsearchJson ) Components (ctx context.Context , tag , uid string ) []fluentbit.Component {
161- c := []fluentbit.Component {}
162-
159+ func (p LoggingProcessorMacroElasticsearchJson ) Expand (ctx context.Context ) []confgenerator.InternalLoggingProcessor {
163160 // sample log line:
164161 // {"type": "server", "timestamp": "2022-01-17T18:31:47,365Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "elasticsearch", "node.name": "ubuntu-jammy", "message": "initialized" }
165162 // Logs are formatted based on configuration (log4j);
166163 // See https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/7.16.2/org/elasticsearch/common/logging/ESJsonLayout.html
167164 // for general layout, and https://www.elastic.co/guide/en/elasticsearch/reference/current/logging.html for general configuration of logging
168-
169- jsonParser := & confgenerator.LoggingProcessorParseJson {
170- ParserShared : confgenerator.ParserShared {
171- TimeKey : "timestamp" ,
172- TimeFormat : "%Y-%m-%dT%H:%M:%S,%L%z" ,
165+ processors := []confgenerator.InternalLoggingProcessor {
166+ confgenerator.LoggingProcessorParseJson {
167+ ParserShared : confgenerator.ParserShared {
168+ TimeKey : "timestamp" ,
169+ TimeFormat : "%Y-%m-%dT%H:%M:%S,%L%z" ,
170+ },
173171 },
172+ p .severityParser (),
174173 }
175174
176- c = append (c , jsonParser .Components (ctx , tag , uid )... )
177- c = append (c , p .severityParser (ctx , tag , uid )... )
178- c = append (c , p .nestingProcessors (ctx , tag , uid )... )
175+ processors = append (processors , p .nestingProcessors ()... )
179176
180- return c
177+ return processors
181178}
182179
183- func (p LoggingProcessorElasticsearchJson ) severityParser (ctx context. Context , tag , uid string ) []fluentbit. Component {
180+ func (p LoggingProcessorMacroElasticsearchJson ) severityParser () confgenerator. InternalLoggingProcessor {
184181 return confgenerator.LoggingProcessorModifyFields {
185182 Fields : map [string ]* confgenerator.ModifyField {
186183 "severity" : {
@@ -199,10 +196,10 @@ func (p LoggingProcessorElasticsearchJson) severityParser(ctx context.Context, t
199196 },
200197 InstrumentationSourceLabel : instrumentationSourceValue (p .Type ()),
201198 },
202- }. Components ( ctx , tag , uid )
199+ }
203200}
204201
205- func (p LoggingProcessorElasticsearchJson ) nestingProcessors (ctx context. Context , tag , uid string ) []fluentbit. Component {
202+ func (p LoggingProcessorMacroElasticsearchJson ) nestingProcessors () []confgenerator. InternalLoggingProcessor {
206203 // The majority of these prefixes come from here:
207204 // https://www.elastic.co/guide/en/elasticsearch/reference/7.16/audit-event-types.html#audit-event-attributes
208205 // Non-audit logs are formatted using the layout documented here, giving the "cluster" prefix:
@@ -223,17 +220,17 @@ func (p LoggingProcessorElasticsearchJson) nestingProcessors(ctx context.Context
223220 "cluster" ,
224221 }
225222
226- c := make ([]fluentbit. Component , 0 , len (prefixes ))
223+ processors := make ([]confgenerator. InternalLoggingProcessor , 0 , len (prefixes ))
227224 for _ , prefix := range prefixes {
228225 nestProcessor := confgenerator.LoggingProcessorNestWildcard {
229226 Wildcard : fmt .Sprintf ("%s.*" , prefix ),
230227 NestUnder : prefix ,
231228 RemovePrefix : fmt .Sprintf ("%s." , prefix ),
232229 }
233- c = append (c , nestProcessor . Components ( ctx , tag , uid ) ... )
230+ processors = append (processors , nestProcessor )
234231 }
235232
236- return c
233+ return processors
237234}
238235
239236type LoggingProcessorElasticsearchGC struct {
@@ -271,12 +268,12 @@ func (p LoggingProcessorElasticsearchGC) Components(ctx context.Context, tag, ui
271268 return c
272269}
273270
274- type LoggingReceiverElasticsearchJson struct {
275- LoggingProcessorElasticsearchJson `yaml:",inline"`
276- ReceiverMixin confgenerator.LoggingReceiverFilesMixin `yaml:",inline"`
271+ type LoggingReceiverMacroElasticsearchJson struct {
272+ LoggingProcessorMacroElasticsearchJson `yaml:",inline"`
273+ ReceiverMixin confgenerator.LoggingReceiverFilesMixin `yaml:",inline" validate:"structonly "`
277274}
278275
279- func (r LoggingReceiverElasticsearchJson ) Components (ctx context.Context , tag string ) []fluentbit. Component {
276+ func (r LoggingReceiverMacroElasticsearchJson ) Expand (ctx context.Context ) (confgenerator. InternalLoggingReceiver , []confgenerator. InternalLoggingProcessor ) {
280277 if len (r .ReceiverMixin .IncludePaths ) == 0 {
281278 // Default JSON logs for Elasticsearch
282279 r .ReceiverMixin .IncludePaths = []string {
@@ -296,7 +293,6 @@ func (r LoggingReceiverElasticsearchJson) Components(ctx context.Context, tag st
296293 // -- snip --
297294 // "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166) ~[elasticsearch-7.16.2.jar:7.16.2]",
298295 // "... 6 more"] }
299-
300296 r .ReceiverMixin .MultilineRules = []confgenerator.MultilineRule {
301297 {
302298 StateName : "start_state" ,
@@ -310,8 +306,7 @@ func (r LoggingReceiverElasticsearchJson) Components(ctx context.Context, tag st
310306 },
311307 }
312308
313- c := r .ReceiverMixin .Components (ctx , tag )
314- return append (c , r .LoggingProcessorElasticsearchJson .Components (ctx , tag , "elasticsearch_json" )... )
309+ return & r .ReceiverMixin , r .LoggingProcessorMacroElasticsearchJson .Expand (ctx )
315310}
316311
317312type LoggingReceiverElasticsearchGC struct {
@@ -332,6 +327,8 @@ func (r LoggingReceiverElasticsearchGC) Components(ctx context.Context, tag stri
332327}
333328
334329func init () {
335- confgenerator .LoggingReceiverTypes .RegisterType (func () confgenerator.LoggingReceiver { return & LoggingReceiverElasticsearchJson {} })
330+ confgenerator .RegisterLoggingReceiverMacro (func () LoggingReceiverMacroElasticsearchJson {
331+ return LoggingReceiverMacroElasticsearchJson {}
332+ })
336333 confgenerator .LoggingReceiverTypes .RegisterType (func () confgenerator.LoggingReceiver { return & LoggingReceiverElasticsearchGC {} })
337334}
0 commit comments