Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Central processor registration #229

Merged
merged 2 commits into from
Oct 13, 2017

Conversation

jalvz
Copy link
Contributor

@jalvz jalvz commented Oct 11, 2017

Register processors centrally, so that processor "configuration" / metadata like endpoint and handlers can be all in one place

This also removes the workarounds with blank identifier imports, and instantiates one processor per request to avoid harmful state

Fixes #230

beater/server.go Outdated
func newMuxer(config Config, report reporter) *http.ServeMux {
mux := http.NewServeMux()

for path, p := range processor.Registry.Processors() {
handler := appHandler(p, config, report)
for path, constructor := range Routes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind naming this only c or construc or similar, to avoid having the same name for the type and the variable?

beater/server.go Outdated
func processRequest(r *http.Request, p processor.Processor, maxSize int64, report reporter) (int, error) {
func processRequest(r *http.Request, new constructor, maxSize int64, report reporter) (int, error) {

var p processor.Processor = new()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this improvement, to have one dedicated processor per request.
Currently we do call the CreateSchema method though when creating a new processor. With your changes this would be done for every request. I don't think is the way to go. Could you update that the schema is created once per endpoint and then reused per request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! we totally should do that.
besides, this is not meant to be merged (at least just yet), this conflicts with PR227 and i'd like to see what everyone thinks of #230

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally support this improvement, as I think it makes things clearer and less error prone.

@jalvz jalvz added the discuss label Oct 12, 2017
Copy link
Contributor

@roncohen roncohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. Lots of code removed 👍
Any problems with circular imports we should worry about?

beater/server.go Outdated
@@ -34,11 +36,18 @@ var (
errPOSTRequestOnly = errors.New("only POST requests are supported")
)

type constructor func() processor.Processor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about newProcessor or processorFactory ?

…tadata like endpoint and handlers can be all in one place.

This also removes the workarounds with blank identifier imports, and instantiates one processor per request to avoid harmful state
@jalvz
Copy link
Contributor Author

jalvz commented Oct 13, 2017

Rebased and implemented review comments, ready to squash & merge.

This undoes parts of #227, now there isn't need for Type and multiple constructors.

Found no issues with circular imports, on the contrary this removes more package dependencies than adds.

@roncohen roncohen merged commit 7cd77af into elastic:master Oct 13, 2017
simitt pushed a commit to simitt/apm-server that referenced this pull request Nov 17, 2017
Register processors centrally, so that processor endpoints and handlers can be all in one place.

This also removes the workarounds with blank identifier imports, and instantiates one processor per request to avoid harmful state
@jalvz jalvz deleted the central-processor-registry branch February 21, 2018 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants