-
Notifications
You must be signed in to change notification settings - Fork 13
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
move service deployment related server side logic from cli #371
Conversation
* update api/core/api.proto for the new version of DeployService API. * run latest version of protoc & protoc-gen-go on api/core and api/service proto files. * add Id field to service proto. * add ca-certificates to Dockerfile. * import path of spinner changed to github.com/mesg-foundation/spinner. * DeployService API updated to receive a Git URL or data chunks of service.tar.gz to deploy a service. * service deployment related server side logic removed from cmd/service and cmd/service updated to meet with new DeployService API. * some of the deploy status messages printed to stdout removed/changed. * update tests of api/core to meet with updated DeployService API. * a sample unit test added to api/core at deploy_test.go. * Server type of api/core made newable and MESGOption() added. * api/service tests updated to workaround different service.Hash() computations because of newly introduced Id field on Service type. (this will be reverted after Service type created by hand in service package.) * database/services updated to meet with changes on its Save() method and new Id field on Service type. * new package mesg added. mesg is responsible to expose all features of core with a nice API. api handlers will use methods from mesg package to interact with core's features.
7fbae9a
to
9bcd005
Compare
9bcd005
to
d9e9603
Compare
a9c4818
to
db10cb9
Compare
api/core/api.proto
Outdated
rpc DeployService (DeployServiceRequest) returns (DeployServiceReply) {} | ||
|
||
rpc DeployService (stream DeployServiceRequest) returns (stream DeployServiceReply) {} | ||
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.
leading whitespaces
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
api/core/deploy.go
Outdated
|
||
func (r *deployServiceStreamReader) GetURL() (url string, err error) { | ||
message, err := r.stream.Recv() | ||
r.data = message.GetChunk() |
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.
Check if message == nil (or error != nil then return). Someone editing Recv method in the future doesn't need to be aware of the fact, that Recv must always return not nil message. In Go it is rather common that func/method return err with all others returned values set to zero.
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
api/server.go
Outdated
@@ -63,8 +64,18 @@ func (s *Server) Stop() { | |||
|
|||
// register all server | |||
func (s *Server) register() { |
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 register call fatal instead of returning error up the stack? It's invoked in Serve method which returns err, maybe let's change it to returning an error and keep program flow in as little places as possible.
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
cmd/service/deploy.go
Outdated
sp.Stop() | ||
fmt.Println(aurora.Red(validationError)) | ||
fmt.Println("Run the command 'service validate' for more details") | ||
os.Exit(0) |
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.
Return non-zero code on Exit or even make a chan for passing an error.
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.
we need better error handling in cmd package
dev-core
Outdated
./scripts/build-test-core.sh | ||
./dev-cli stop | ||
./dev-cli start | ||
# chain these to stop execution on failure |
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.
Instead of chaining all commands use the -e
flag in #!/bin/bash
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
docs/api/core.md
Outdated
@@ -747,7 +750,9 @@ The reply's data of `DeployService` API. | |||
|
|||
| Field | Type | Description | | |||
| ----- | ---- | ----------- | | |||
| serviceID | [string](#string) | The generated identifier of the deployed service. Use this ID with other APIs. | | |||
| status | [string](#string) | status will be sent after each status change. | |
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.
s/each status change/each change/ ?
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 guess we can keep this one as it is
mesg/deploy_deployer.go
Outdated
return d.deploy(path) | ||
} | ||
|
||
func (d *serviceDeployer) gitClone(repoURL string, path string) error { |
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 gitClone should be moved to some utils pkg (maybe xgit?) but it's not part of service Deploeyr
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.
- missing docs
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.
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.
docs are done
mesg/deploy_deployer.go
Outdated
return err | ||
} | ||
|
||
func (d *serviceDeployer) FromGzippedTar(r io.Reader) (*service.Service, *importer.ValidationError, error) { |
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.
missing docs + few other methods.
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
mesg/deploy_deployer.go
Outdated
return d.deploy(path) | ||
} | ||
|
||
func (d *serviceDeployer) deploy(path string) (*service.Service, *importer.ValidationError, error) { |
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 know golint will not highlight this, but even for unexported methods/funcs it's nice to have some docs (the docs are for mainly us, not to satisfy linters :))
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
api/core/api.proto
Outdated
oneof value { | ||
// Git repo url of service. If url provided, stream will be closed after | ||
// first receive. | ||
string url = 1; |
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.
The number ( '1' ) should not be the same even if your replace the previously declared variable with number '1'.
The reason is, gRPC manages way better the update of API when the number are not the same.
So we should never 'reused' previously used number.
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
api/core/api.proto
Outdated
string serviceID = 1; // The generated identifier of the deployed service. Use this ID with other APIs. | ||
oneof value { | ||
// status will be sent after each status change. | ||
string status = 1; |
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.
Same comment about the number.
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
option(m) | ||
} | ||
var err error | ||
if m.container == 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.
Avoid nested if's
if m.container != nil {
return m, nil
}
var err error
m.container, err = container.New()
if 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.
thanks, in this case i kinda don't like making an early return here because we might add some more lines under these code that not related with initializing a container.
* respect to protobuf field numbers * add more docs * return with an err in register() of api/ Server * cmd/service don't os.Exit() in goroutine * use -e on dev-core script * update proto docs
3261b15
to
b22027a
Compare
* tests for this will be added within #371
* tests for this will be added within #371
65bfc6d
to
33a1d78
Compare
1f83701
to
05d059d
Compare
05d059d
to
d9234fd
Compare
needs review |
return err | ||
} | ||
|
||
buf := make([]byte, 1024) |
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.
1ko seems a bit small.
Spoiler alert: it's 16KiB - 64KiB, according to oral tradition.
grpc/grpc.github.io#371
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 check this out https://ops.tips/blog/sending-files-via-grpc/
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.
It seems like at 1024bytes (1KB) we have a decent throughput.
I was expecting something like 32KB: (1 << 15) to be the most optimal but it looks like it’s one of the worst scenarios regarding variance.
cmd/service/deploy.go
Outdated
} | ||
|
||
func readDeployReply(stream core.Core_DeployServiceClient, deployment chan deploymentResult) { | ||
sp := spinner.New(utils.SpinnerCharset, utils.SpinnerDuration) |
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.
What don't you use utils.StartSpinner
or utils.ShowSpinnerForFunc
?
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 the existing helper function are not useful for what you are doing, I suggest to create a helper function in order to reuse it if it make sense.
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 had to create it manually in the first for some reason... I'll see if i can use current util for this
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
71bed60
to
dd3f37b
Compare
dd3f37b
to
1b11a0e
Compare
about the update DeployService API
I have merged Git url and uploading service context options to same gRPC DeployService handler for deploying services.
What do you prefer? Current one or split this as DeployService (uploading service context) and create new DeployServiceFromURL handler?
One small advantage of splitting them might be to not requiring to deal with gRPC stream for simple url deployments.
about the new mesg package
Manager.CreateService()
,Manager.CreateServiceFromURL()