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

refactor: introduces bootstrapper to orchestrate server initialization #23

Merged
merged 6 commits into from
Feb 25, 2022

Conversation

NNcrawler
Copy link
Member

No description provided.

@NNcrawler NNcrawler linked an issue Dec 3, 2021 that may be closed by this pull request
@ravisuhag ravisuhag requested a review from ramey December 14, 2021 13:50
Copy link
Member

@ramey ramey left a comment

Choose a reason for hiding this comment

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

Few comments!

@@ -0,0 +1,26 @@
package pprof
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we use the same http server for pprof as used for WebSocket/REST?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can. I was just following how is it right now. I haven't made changes here. We can use the same HTTP server as long as the path is not conflicting.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, there is a bug in the current implementation. We haven't defined the paths explicitly, which is a requirement when using gorilla.

http/services.go Outdated
}
}

func Create(b chan *collection.CollectRequest) Services {
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a better name for this function? This function will be called http.Create, for someone who is reading the function call it will very difficult to access what is being created.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have suggestions? What about servers or services?

Copy link
Member Author

Choose a reason for hiding this comment

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

or handlers. handlers sounds good. handlers.create inside handlers there are Websocket handler, REST HTTP handler, GRPC handler, etc.

Copy link
Member

Choose a reason for hiding this comment

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

Services is what sounds right to me as it returns the created services.

http/services.go Outdated

type bootstrapper interface {
// Init initialize each HTTP based server. Return error if initialization failed. Put the Serve() function as return mostly suffice for Init process.
Init() error
Copy link
Member

Choose a reason for hiding this comment

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

Can we pass context as a function param here too? Just to make it standard.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

http/services.go Outdated
type bootstrapper interface {
// Init initialize each HTTP based server. Return error if initialization failed. Put the Serve() function as return mostly suffice for Init process.
Init() error
Shutdown(ctx context.Context)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, can we return error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

http/services.go Outdated
}
}

func Create(b chan *collection.CollectRequest) Services {
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought - if we want to initialize only a certain server in the future may be based on a config param, will it make sense to move this logic outside this package. In main maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. This we can refactor in the future. This attempt is only the first attempt to segregate between handlers protocol.

)

type Service struct {
Buffer chan *collection.CollectRequest
Copy link
Member

Choose a reason for hiding this comment

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

Can we make the collector as a struct field instead of the channel, currently we are initializing collector the collector twice whereas only one can be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@ramey ramey merged commit 6c946cf into raystack:main Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor to simplify http package
2 participants