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

[infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs #2173

Merged

Conversation

kvivek1115
Copy link

🔩 Description: What code changed, and why?

Implement a new service that is managing the chef servers ends points and teach how to fetch data of the desired state.

As of now, we are dealing with current state data of chef node which might fails and loss of data if the particular node/server fails during convergence.

In order to make a single source of truth for chef infra servers data here, we have added infra-proxy-service service.

In this PR following points I have covered:

  • Connect infra-proxy-service to deployment-service.
  • Provide gPRC and HTTP endpoints to manage chef infra servers & orgs.
  • CRUD for infra servers.
  • CRUD for infra server orgs.

Pending tasks:

  1. Add IAM policies for admin users only.
  2. Manage infra server user's KEYS using secrets-service.
  3. Add Unit & integration test cases.
  4. Documentations of infra-proxy-service

As I am a newbie to Automate and I have tried to cover as much as possible in order to get the understating of Automate code flow.

Please reviews and do provide the feedback.

Also, I am very thankful to @stevendanna who guided me with proceedings.

Thanks

⛓️ Related Resources

#1544

👍 Definition of Done

Added infra-proxy-service a separate service in order to manage chef infra servers endpoints.

👟 How to Build and Test the Change

  1. build components/infra-proxy-service
  2. rebuild components/automate-gateway
  3. rebuild components/automate-deployment && start_all_services
  4. run chef-automate dev grpcurl automate-gateway list chef.automate.api.infra_proxy.InfraProxy in order to get list of implemeted gRPC APIs.

✅ Checklist

  • Tests added/updated?
  • Docs added/updated?

Attached DB structure for reference:
db-structure.png

chef_infra_proxy_db

@kvivek1115 kvivek1115 self-assigned this Nov 12, 2019
Copy link
Contributor

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

This looks like a pretty good start on this service.

I've left some initial comments that are mostly just small cleanups.


var serveCmd = &cobra.Command{
Use: "serve",
Short: fmt.Sprintf("Launches the automate infra proxy service."),
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] No need for Sprintf here

func serve(cmd *cobra.Command, args []string) {
cmd.PersistentFlags().StringP("log-level", "l", "info", "log level")
cmd.PersistentFlags().StringP("log-format", "f", "text", "log format")
cmd.PersistentFlags().String("grpc", "127.0.0.1:9093", "grpc host and port")
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Default port here is different from service's default

Copy link
Author

Choose a reason for hiding this comment

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

Ohh, yup need to update it to port 10153 thanks!

u, err := url.Parse(cfg.PGURL)
if err != nil {
msg := fmt.Sprintf("could not parse pg_url %s from config", cfg.PGURL)
fail(errors.Wrap(err, msg))
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] You can use errors.Wrapf rather than errors.Wrap+fmt.Sprintf

@@ -0,0 +1,79 @@
package config
Copy link
Contributor

Choose a reason for hiding this comment

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

Is any of this file used elsewhere? Can we remove it? The service builds fine if I delete the file.

Copy link
Author

Choose a reason for hiding this comment

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

Nope, we haven't used it anywhere. after removing it seems all working fine. 👍

id uuid PRIMARY KEY,
name TEXT NOT NULL DEFAULT '',
admin_user TEXT NOT NULL DEFAULT '', /* Added for now but can be thing of managing mutitple keys & users */
admin_key TEXT NOT NULL DEFAULT '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should consider storing admin_key in secrets-service?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this definitely will store in a secrets-service. I have kept it in my TODO list.

)

// TODOs
// - CREATE EXTENSION "uuid-ossp"; (currently done via Makefile for tests)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is done in your run hook now so it looks like you can remove the TODO

var s storage.Server
err := p.db.QueryRowContext(ctx,
`SELECT s.id, s.name, s.description, s.fqdn, s.ip_address, s.updated_at, s.created_at,
COALESCE((SELECT count(*) FROM orgs o WHERE o.server_id = s.id), 0) AS orgs_count
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to COALESCE here? Won't the SELECT count(*) return 0 if no conditions are met?

Copy link
Author

@kvivek1115 kvivek1115 Nov 13, 2019

Choose a reason for hiding this comment

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

Nope, we don't need COALESCE here as such just put an extra layer 😄 will remove it thanks

# Please put potentially long-running and/or complex operations in the run hook rather
# than the init hook until the issue[0] has been resolved.
#
# [0] https://github.com/habitat-sh/habitat/issues/1973
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 let's just exclude this hook altogether I think.

[service]
host = "localhost"
port = 10153
external_fqdn = "localhost"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this service uses external_fqdn for anything.

option (chef.automate.api.service_config) = {name: "infra-proxy-service"};

reserved 1 to 2;
V1 v1 = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] Since this is a brand new proto, no need to start with fields 1 and 2 as reserved, this can be V1 v1 =1 and you can removed reserved 1 to 2; above (this will require rebuilding config protos.

@stevendanna
Copy link
Contributor

#2189

@kvivek1115 kvivek1115 force-pushed the VSingh/automate-infra-proxy-base branch 2 times, most recently from 5cb31e7 to c7732a9 Compare November 14, 2019 05:34
}
}

closer, err := tracing.NewGlobalTracer("infra-proxy")
Copy link
Contributor

Choose a reason for hiding this comment

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

we dont use any of this tracing stuff. We should probably stop putting it in

Copy link
Author

Choose a reason for hiding this comment

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

Okay sure, will check and update it accordingly thanks pointing it out.


// CreateOrg creates a new org
func (s *Server) CreateOrg(ctx context.Context, req *request.CreateOrg) (*response.CreateOrg, error) {
ctx, cancel := context.WithCancel(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

cant remember, what's the reason for doing this

Copy link
Author

Choose a reason for hiding this comment

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

@jaym I think in interservice we have defined interfaces that need to be implemented by the infra proxy server.

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 this is so that when this function is left all the processes created from this function stop.

@kvivek1115 kvivek1115 force-pushed the VSingh/automate-infra-proxy-base branch 2 times, most recently from 38f0739 to fc4f34d Compare December 1, 2019 06:34
@kvivek1115 kvivek1115 force-pushed the VSingh/automate-infra-proxy-base branch 3 times, most recently from 529f839 to c36433b Compare December 9, 2019 10:39
@kvivek1115 kvivek1115 force-pushed the VSingh/automate-infra-proxy-base branch 3 times, most recently from 6dfe59d to 3e76364 Compare December 24, 2019 10:18
@kvivek1115 kvivek1115 force-pushed the VSingh/automate-infra-proxy-base branch from 3e76364 to b2feecd Compare January 3, 2020 07:13
@kvivek1115 kvivek1115 changed the title [WIP] [infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs [infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs Jan 28, 2020
@kvivek1115 kvivek1115 changed the title [infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs [WIP] [infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs Jan 28, 2020
@kvivek1115 kvivek1115 force-pushed the VSingh/automate-infra-proxy-base branch from 95c4a2f to dcc91da Compare January 29, 2020 04:15
@kvivek1115 kvivek1115 changed the title [WIP] [infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs [infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs Jan 29, 2020
@kvivek1115
Copy link
Author

This PR is good to go. I have added a couple of changes after the last review.

Regarding policy changes, have renamed infra_proxy prefix with infra as discussed.

Note: IAM Projects mapping and migrates existing ingest policies are pending will do in further PR.

../../scripts/generate_and_check_migration_files.sh $@

# Regenerate all *.pb.go files
proto:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is needed because all the protos for the infra-proxy-service are in the api folder.

Copy link
Author

Choose a reason for hiding this comment

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

Somehow it left untouched, have removed it thanks

chef/mlsa
)
pkg_exports=(
[port]=service.port # default service is grpc
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 you might want to add a [host]=service.host to the pkg_exports like below.

pkg_exports=(
  [port]=service.port
  [host]=service.host
)

This allows other services to know how to connect to this service through localhost or the IP address.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, thanks for pointing it out.

@@ -106,7 +107,7 @@ require (
github.com/spf13/jwalterweatherman v0.0.0-20170901151539-12bd96e66386 // indirect
github.com/spf13/pflag v1.0.1
github.com/spf13/viper v1.0.1-0.20171207042631-1a0c4a370c3e
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.4.0
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason to upgrade this library?

Copy link
Author

Choose a reason for hiding this comment

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

I think while updating the go-chef vendor library, have found minor update in testify lib as well, so updated in this PR only.

stevendanna and others added 27 commits February 17, 2020 14:40
Signed-off-by: Steven Danna <[email protected]>
(cherry picked from commit 34cd81d)
 - Cover MSYS-1155 specifications. 
 - Add gRPC proto request and & response messages
 - Add config request proto message.
 - Register InfraProxyServer with server cmd.
 - Connect gRPC server functions to DB functions in order to manage servers CRUD.
 - Write a habitat plan to create DB & migrations.
 - Add health-check and init hab template.
 - Add hab config.yml

Signed-off-by: Vivek Singh <[email protected]>
 - Rename v1 server.go to servers.go.
 - Modify request & response message format.

Signed-off-by: Vivek Singh <[email protected]>
 - Add infra-proxy-service backup spec
 - Append server_id in GetOrgs & other orgs API.
 - Modify query & other methods.
Signed-off-by: Vivek Singh <[email protected]>
 - Update orgs_count automate-gateway GetSevers API. 
 - Remove unused code.

Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
     - make revendor to update the dependency.

Signed-off-by: Vivek Singh <[email protected]>
 - Add GetCookbooks & GetCookbooksAvailalbeVersions grpc & http API.

Signed-off-by: Vivek Singh <[email protected]>
 - Fix minor reviews comments.

Signed-off-by: Vivek Singh <[email protected]>
     - https://github.com/chef/go-chef
     - minor update regarding server delete the message
     - constructing the base URL based on fqdn|ipAddress value

Signed-off-by: Vivek Singh <[email protected]>
 - Connect infra-proxy-service with secrets-service.
 - Access secrets-service API in order to manage the admin key.

Signed-off-by: Vivek Singh <[email protected]>
 - Update UpdateOrg, DeleteOrg and GetOrg in order manage key.

Signed-off-by: Vivek Singh <[email protected]>
@kvivek1115 kvivek1115 force-pushed the VSingh/automate-infra-proxy-base branch from 34ed861 to 9c11c0a Compare February 17, 2020 12:33
@susanev susanev merged commit e7b05c1 into chef:master Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants