apm-server icon indicating copy to clipboard operation
apm-server copied to clipboard

Processor methods look redundant in packages

Open nexthack opened this issue 9 years ago • 5 comments

This might be similar to this issue.

Looks like the processor.go in error and transaction package are no different and looks like we are having redundancy.

Either we can use go embedding or refactor in a better way.Will update with some ideas.

nexthack avatar Aug 20 '17 21:08 nexthack

Agree that this could be potentially simplified through one of the two methods you mentioned. If you have suggestions, feel free to also directly open a PR. Sometimes discussing code is easier :-)

ruflin avatar Aug 21 '17 06:08 ruflin

Can I find some more info on the role of the processors ? Might be that helps.

A direct way can be as below

type Processor interface {
	Validate(io.Reader) error
	Payload
	Name() string
}

type processor struct {} // this struct can implement the default methods.

func (p *processor) Transform() []beat.Event {
	return p.payload.Transform()
}

Now for transaction processor we can embed the base processor so that it can access all methods of the base.

type TxProcessor struct {
  Processor
}

nexthack avatar Aug 21 '17 21:08 nexthack

The role of processors is to take data, validate it, transform it and convert one input event to one or multiple output events.

Composing the Processors from a base processor is very/same as we do with MetricSets in metricbeat: https://github.com/elastic/beats/blob/master/metricbeat/module/apache/status/status.go#L44 So it's definitively a direction I like.

I would also like to get @simitt and @jalvz involved on this as they were thinking about how to better structure the code quite a bit.

ruflin avatar Aug 22 '17 07:08 ruflin

Sure.Will implement once we have some consensus.

nexthack avatar Aug 22 '17 19:08 nexthack

Will start on this.

nexthack avatar Sep 04 '17 21:09 nexthack