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

move service deployment related server side logic from cli #371

Merged
merged 24 commits into from
Aug 24, 2018

Conversation

ilgooz
Copy link
Contributor

@ilgooz ilgooz commented Aug 16, 2018

  • @antho1404 can you please update the comments on api/core/api.proto to match with the changes?

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

  • please give feedbacks about new mesg package. goal of mesg package is to serve core's all features with a high level API. gRPC server handlers will use methods from mesg package, instead of directly accessing to internal packages like service, execution, etc. we shouldn't keep any business logic within api handlers and should move them under mesg package.
  • there are only two methods in the mesg package to deploy services for now. i'm thinking about adding more methods to cover all features used by gRPC server handlers.
  • i'm planning to move mesg/deploy_deployer.go to service package in future, while refactoring service to make it newable. APIs will be like: Manager.CreateService(), Manager.CreateServiceFromURL()

@ilgooz ilgooz added this to the v1.2.0 milestone Aug 16, 2018
* 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.
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch from 7fbae9a to 9bcd005 Compare August 16, 2018 22:20
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch from 9bcd005 to d9e9603 Compare August 16, 2018 22:27
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch from a9c4818 to db10cb9 Compare August 17, 2018 05:39
@ilgooz ilgooz requested a review from a team August 17, 2018 07:52
rpc DeployService (DeployServiceRequest) returns (DeployServiceReply) {}

rpc DeployService (stream DeployServiceRequest) returns (stream DeployServiceReply) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

leading whitespaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


func (r *deployServiceStreamReader) GetURL() (url string, err error) {
message, err := r.stream.Recv()
r.data = message.GetChunk()
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

sp.Stop()
fmt.Println(aurora.Red(validationError))
fmt.Println("Run the command 'service validate' for more details")
os.Exit(0)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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. |
Copy link
Contributor

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/ ?

Copy link
Contributor Author

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

return d.deploy(path)
}

func (d *serviceDeployer) gitClone(repoURL string, path string) error {
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

  • missing docs

Copy link
Contributor Author

@ilgooz ilgooz Aug 17, 2018

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

docs are done

return err
}

func (d *serviceDeployer) FromGzippedTar(r io.Reader) (*service.Service, *importer.ValidationError, error) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return d.deploy(path)
}

func (d *serviceDeployer) deploy(path string) (*service.Service, *importer.ValidationError, error) {
Copy link
Contributor

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 :))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

oneof value {
// Git repo url of service. If url provided, stream will be closed after
// first receive.
string url = 1;
Copy link
Member

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.

https://developers.google.com/protocol-buffers/docs/proto3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ilgooz ilgooz mentioned this pull request Aug 17, 2018
option(m)
}
var err error
if m.container == nil {
Copy link
Contributor

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 ....

Copy link
Contributor Author

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
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch from 3261b15 to b22027a Compare August 17, 2018 15:08
ilgooz added a commit that referenced this pull request Aug 21, 2018
NicolasMahe pushed a commit that referenced this pull request Aug 22, 2018
ilgooz added a commit that referenced this pull request Aug 22, 2018
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch from 65bfc6d to 33a1d78 Compare August 23, 2018 09:44
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch 3 times, most recently from 1f83701 to 05d059d Compare August 23, 2018 13:48
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch from 05d059d to d9234fd Compare August 23, 2018 14:06
@ilgooz
Copy link
Contributor Author

ilgooz commented Aug 23, 2018

needs review

antho1404
antho1404 previously approved these changes Aug 24, 2018
return err
}

buf := make([]byte, 1024)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

}

func readDeployReply(stream core.Core_DeployServiceClient, deployment chan deploymentResult) {
sp := spinner.New(utils.SpinnerCharset, utils.SpinnerDuration)
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch 4 times, most recently from 71bed60 to dd3f37b Compare August 24, 2018 06:08
@ilgooz ilgooz force-pushed the feature/simplify-cli-deploy branch from dd3f37b to 1b11a0e Compare August 24, 2018 06:09
@NicolasMahe NicolasMahe merged commit 0d43e34 into dev Aug 24, 2018
@NicolasMahe NicolasMahe deleted the feature/simplify-cli-deploy branch August 24, 2018 08:27
@ilgooz ilgooz restored the feature/simplify-cli-deploy branch August 24, 2018 14:22
@ilgooz ilgooz deleted the feature/simplify-cli-deploy branch August 24, 2018 14:22
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.

4 participants