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

Separate thrift handler for history service #3646

Conversation

vytautas-karpavicius
Copy link
Contributor

What changed?

  • Created Handler interface for history service
  • Previous Handler struct renamed to HandlerImpl
  • Created ThriftHandler wrapper on top of Handler interface. At this point it only forward requests as is to underlying handler.
  • Created Mock for Handler interface.
  • Covered ThriftHandler with units tests. Test that requests are forwarded to underlying handler and response is returned as is.
  • Replaced handler registration. Instead of registering HandlerImpl directly, wrap it with ThriftHandler and register it instead.

Why?
This is purely a mechanical refactoring that introduces additional ThriftHandler wrapper. For now it only forwards request to the original handler. Later on this will become a point for conversion between internal types and thrift types. Underlying handler will be independent of rpc protocol types.

How did you test it?

  • Covered ThriftHandler with unit tests
  • Started server locally

Potential risks
None, purely mechanical change.

@vytautas-karpavicius vytautas-karpavicius requested a review from a team October 14, 2020 12:21
@coveralls
Copy link

coveralls commented Oct 14, 2020

Coverage Status

Coverage increased (+0.002%) to 59.42% when pulling b35bc07 on vytautas-karpavicius:history-thrift-handler into ad06c81 on uber:master.

// Source: github.com/uber/cadence/service/history (interfaces: Handler)

// Package history is a generated GoMock package.
package history
Copy link
Contributor

Choose a reason for hiding this comment

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

What about handler_mock.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, updated to handler_mock.go

}

// HandlerImpl is an implementation for history service independent of wire protocol
HandlerImpl struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

handlerImpl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, no need to expose this. Updated.

@@ -92,8 +137,8 @@ var (
func NewHandler(
resource resource.Resource,
config *config.Config,
) *Handler {
handler := &Handler{
) *HandlerImpl {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we return interface here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per Go guidelines we should return concrete implementations instead of interfaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. Good to know about this

@@ -42,7 +42,7 @@ type Service struct {
resource.Resource

status int32
handler *Handler
handler *HandlerImpl
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use the interface rather than the implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point handler also use other methods (Start, Stop,...) defined on HandlerImpl but not on Handler interface. I wanted to keep this interface lean and only contain actual handler methods, not the utilities like Start and Stop.

Alternatively we could separate them into another interface and use that here instead. But for the time being and do not see immediate benefit for that and I wanted to keep this diff simple and mechanical.

@vytautas-karpavicius vytautas-karpavicius merged commit b7ceac2 into cadence-workflow:master Oct 26, 2020
github-actions bot pushed a commit to vytautas-karpavicius/cadence that referenced this pull request Feb 4, 2021
This is purely a mechanical refactoring that introduces additional ThriftHandler wrapper. For now it only forwards request to the original handler. Later on this will become a point for conversion between internal types and thrift types. Underlying handler will be independent of rpc protocol types.
- Created Handler interface for history service
- Previous Handler struct renamed to handlerImpl
- Created ThriftHandler wrapper on top of Handler interface. At this point it only forward requests as is to underlying handler.
- Created Mock for Handler interface.
- Covered ThriftHandler with units tests. Test that requests are forwarded to underlying handler and response is returned as is.
- Replaced handler registration. Instead of registering handlerImpl directly, wrap it with ThriftHandler and register it instead.
yux0 pushed a commit to yux0/cadence that referenced this pull request May 4, 2021
This is purely a mechanical refactoring that introduces additional ThriftHandler wrapper. For now it only forwards request to the original handler. Later on this will become a point for conversion between internal types and thrift types. Underlying handler will be independent of rpc protocol types.
- Created Handler interface for history service
- Previous Handler struct renamed to handlerImpl
- Created ThriftHandler wrapper on top of Handler interface. At this point it only forward requests as is to underlying handler.
- Created Mock for Handler interface.
- Covered ThriftHandler with units tests. Test that requests are forwarded to underlying handler and response is returned as is.
- Replaced handler registration. Instead of registering handlerImpl directly, wrap it with ThriftHandler and register it instead.
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.

3 participants