-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added gRPC server. #15
Conversation
cmd/connector/main.go
Outdated
) | ||
|
||
var log = logger.GetOrCreate("main") | ||
|
||
const ( | ||
configPath = "config/config.toml" | ||
configPath = "/home/cristu/go/src/github.com/multiversx/mx-chain-ws-connector-firehose-go/cmd/connector/config/config.toml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert to relative path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted.
connector/connectorRunner.go
Outdated
server = factory.NewServer(cr.config.GRPC, handler) | ||
|
||
go func() { | ||
if err := server.Start(); err != nil { | ||
log.Error("couldn't start grpc server", "error", err) | ||
} | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suggest to move this part into the componet itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved.
factory/grpcServerFactory.go
Outdated
func NewServer(config config.GRPCConfig, blocksHandler process.GRPCBlocksHandler) *GRPCServer { | ||
s := grpc.NewServer() | ||
|
||
service := hyperOutportBlock.NewService(blocksHandler) | ||
data.RegisterHyperOutportBlockServiceServer(s, service) | ||
reflection.Register(s) | ||
|
||
return &GRPCServer{s, config} | ||
} | ||
|
||
// Start will start the grpc server on the configured URL. | ||
func (s *GRPCServer) Start() error { | ||
lis, err := net.Listen("tcp", s.config.URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to a separate component, and add the goroutine into this component, we usually use a pattern like this one here https://github.com/multiversx/mx-chain-notifier-go/blob/main/process/publisher.go#L48
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add unit tests for this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
process/dataAggregator.go
Outdated
@@ -23,6 +26,7 @@ func NewDataAggregator( | |||
|
|||
return &dataAggregator{ | |||
blocksPool: blocksPool, | |||
converter: NewOutportBlockConverter(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass converter as parameter and set it in factory
process/dataProcessor.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should put into blocks pool the outport block already converter
shardBlock, err := da.converter.HandleShardOutportBlock(outportBlockShard) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's better to have convert outport block already in the pool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that'd require several alterations. I'd rather keep it in a separate PR.
data/hyperOutportBlocks/type.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if these interfaces are being used only in tests, it's better to move them there unexported, otherwise it might be confusing to have them in data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved
connector/connectorRunner.go
Outdated
if cr.config.GRPC.Enable { | ||
writer = &fakeWriter{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic should be better put in factory package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
config/config.go
Outdated
|
||
// GRPCConfig will map the gRPC server configuration | ||
type GRPCConfig struct { | ||
Enable bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since it can be grpc mode
or stdout
mode exclusively, i think it's better to have a CLI paramter to specify this option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
server/grpcServer.go
Outdated
s.server.GracefulStop() | ||
|
||
default: | ||
lis, err := net.Listen("tcp", s.config.URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use h.server.ListenAndServe() ?
Also is it needed to do it in an infinite loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed.
factory/grpcServerFactory.go
Outdated
outportBlocksPool process.DataPool, | ||
dataAggregator process.DataAggregator) (process.GRPCServer, process.Writer, error) { | ||
if !enableGrpcServer { | ||
return nil, os.Stdout, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can have a disabled
component for GRPC service in case it is not enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed. but didn't implement disabled.
"github.com/multiversx/mx-chain-ws-connector-template-go/testscommon" | ||
) | ||
|
||
func TestService_GetHyperOutportBlockByHash(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add parallel run for tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
data "github.com/multiversx/mx-chain-ws-connector-template-go/data/hyperOutportBlocks" | ||
) | ||
|
||
type GRPCBlocksHandlerStub struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add missing dummy comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
connector/connectorRunner.go
Outdated
blockContainer, | ||
protoMarshaller, | ||
&process.ProtoMarshaller{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a separate variable for proto marshaller and rename protoMarshaller
to gogoProtoMarshaller
or something similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed, but publisher is now in a factory.
data.UnimplementedHyperOutportBlockServiceServer | ||
} | ||
|
||
func NewService(blocksHandler process.GRPCBlocksHandler) *Service { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil check for blocks handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
…to grpcServer # Conflicts: # cmd/connector/main.go
Co-authored-by: Darius <[email protected]>
connector/connectorRunner.go
Outdated
blockContainer, | ||
protoMarshaller, | ||
) | ||
s, err := factory.CreateGRPCServer(cr.enableGrpcServer, cr.config.GRPC, outportBlocksPool, dataAggregator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename the one letter variable
@@ -40,4 +40,9 @@ var ( | |||
Usage: "Option for specifying db mode. Available options: `full-persister`, `import-db`, `optimized-persister`", | |||
Value: "full-persister", | |||
} | |||
|
|||
enableGrpcServer = cli.BoolFlag{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not forget to add enableGrpcServer
into app cli.Flag list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
No description provided.