-
Notifications
You must be signed in to change notification settings - Fork 114
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
[infra-proxy-service] Add infra-proxy-service & manage servers & orgs APIs #2173
Conversation
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 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."), |
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.
[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") |
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.
[nit] Default port here is different from service's default
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.
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)) |
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.
[minor] You can use errors.Wrapf
rather than errors.Wrap+fmt.Sprintf
@@ -0,0 +1,79 @@ | |||
package config |
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.
Is any of this file used elsewhere? Can we remove it? The service builds fine if I delete the 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.
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 '', |
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.
Should consider storing admin_key in secrets-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.
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) |
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 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 |
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 we need to COALESCE here? Won't the SELECT count(*) return 0 if no conditions are met?
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.
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 |
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 let's just exclude this hook altogether I think.
[service] | ||
host = "localhost" | ||
port = 10153 | ||
external_fqdn = "localhost" |
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 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; |
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.
[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.
5cb31e7
to
c7732a9
Compare
} | ||
} | ||
|
||
closer, err := tracing.NewGlobalTracer("infra-proxy") |
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 dont use any of this tracing stuff. We should probably stop putting it in
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.
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) |
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.
cant remember, what's the reason for doing 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.
@jaym I think in interservice we have defined interfaces that need to be implemented by the infra proxy server.
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 this is so that when this function is left all the processes created from this function stop.
38f0739
to
fc4f34d
Compare
529f839
to
c36433b
Compare
6dfe59d
to
3e76364
Compare
3e76364
to
b2feecd
Compare
95c4a2f
to
dcc91da
Compare
This PR is good to go. I have added a couple of changes after the last review. Regarding policy changes, have renamed Note: IAM Projects mapping and migrates existing |
../../scripts/generate_and_check_migration_files.sh $@ | ||
|
||
# Regenerate all *.pb.go files | ||
proto: |
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 don't think this is needed because all the protos for the infra-proxy-service are in the api folder.
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.
Somehow it left untouched, have removed it thanks
chef/mlsa | ||
) | ||
pkg_exports=( | ||
[port]=service.port # default service is 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.
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.
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.
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 |
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 is the reason to upgrade this library?
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 while updating the go-chef vendor library, have found minor update in testify lib as well, so updated in this PR only.
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]>
Signed-off-by: Vivek Singh <[email protected]>
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]>
Signed-off-by: Steven Danna <[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]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
…nges 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]>
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]>
…vers 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]>
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]>
34ed861
to
9c11c0a
Compare
Signed-off-by: Vivek Singh <[email protected]>
🔩 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:
infra-proxy-service
todeployment-service
.Pending tasks:
secrets-service
.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
build components/infra-proxy-service
rebuild components/automate-gateway
rebuild components/automate-deployment && start_all_services
chef-automate dev grpcurl automate-gateway list chef.automate.api.infra_proxy.InfraProxy
in order to get list of implemeted gRPC APIs.✅ Checklist
Attached DB structure for reference:
