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

add progress logging to discovery #181

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions cmd/registry-connect/discover/apigee/products/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ func Command() *cobra.Command {
}

func exportProducts(ctx context.Context, client apigee.Client) error {
log.FromContext(ctx).Infof("retrieving products")
products, err := client.Products(ctx)
if err != nil {
return err
}
log.FromContext(ctx).Infof("%d products discovered", len(products))

log.FromContext(ctx).Infof("retrieving proxies")
proxies, err := client.Proxies(ctx)
if err != nil {
return err
}
log.FromContext(ctx).Infof("%d proxies discovered", len(proxies))
proxyByName := map[string]*api.GoogleCloudApigeeV1ApiProxy{}
for _, p := range proxies {
proxyByName[p.Name] = p
Expand All @@ -70,6 +74,7 @@ func exportProducts(ctx context.Context, client apigee.Client) error {
var apis []interface{}
apisByProxyName := map[string][]*encoding.Api{}
for _, product := range products {
log.FromContext(ctx).Infof("encoding product %q", product.Name)
access := ""
for _, a := range product.Attributes {
if a.Name == "access" {
Expand Down Expand Up @@ -113,6 +118,7 @@ func exportProducts(ctx context.Context, client apigee.Client) error {

proxyNames := boundProxies(product)
if len(proxyNames) > 0 {
log.FromContext(ctx).Infof("encoding bound proxies %q", proxyNames)
related := &apihub.ReferenceList{
DisplayName: "Related resources",
Description: "Links to resources in the registry.",
Expand Down Expand Up @@ -180,32 +186,29 @@ func exportProducts(ctx context.Context, client apigee.Client) error {
Header: encoding.Header{ApiVersion: encoding.RegistryV1},
Items: apis,
}
return yaml.NewEncoder(os.Stdout).Encode(items)
log.FromContext(ctx).Infof("encoding yaml output")
err = yaml.NewEncoder(os.Stdout).Encode(items)
log.FromContext(ctx).Infof("products export complete")
return err
}

// product -> proxies -> deployments
func addDeployments(ctx context.Context, client apigee.Client, apisByProxyName map[string][]*encoding.Api) error {
if len(apisByProxyName) == 0 {
return nil
}
ps, err := client.Proxies(ctx)
if err != nil {
return err
}
proxiesByName := map[string]*api.GoogleCloudApigeeV1ApiProxy{}
for _, p := range ps {
proxiesByName[p.Name] = p
}

log.FromContext(ctx).Infof("retrieving envmap")
envMap, err := client.EnvMap(ctx)
if err != nil {
return err
}

log.FromContext(ctx).Infof("retrieving deployments")
deps, err := client.Deployments(ctx)
if err != nil {
return err
}
log.FromContext(ctx).Infof("%d deployments discovered", len(deps))

for _, dep := range deps {
hostnames, ok := envMap.Hostnames(dep.Environment)
Expand Down
16 changes: 13 additions & 3 deletions cmd/registry-connect/discover/apigee/proxies/proxies.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ func Command() *cobra.Command {
}

func exportProxies(ctx context.Context, client apigee.Client) error {
log.FromContext(ctx).Infof("retrieving proxies")
proxies, err := client.Proxies(ctx)
if err != nil {
return err
}
log.FromContext(ctx).Infof("%d proxies discovered", len(proxies))

var apis []interface{}
apisByProxyName := map[string]*encoding.Api{}
for _, proxy := range proxies {
log.FromContext(ctx).Infof("encoding proxy %q", proxy.Name)
api := &encoding.Api{
Header: encoding.Header{
ApiVersion: encoding.RegistryV1,
Expand All @@ -77,6 +80,7 @@ func exportProxies(ctx context.Context, client apigee.Client) error {
}

for _, r := range proxy.Revision {
log.FromContext(ctx).Infof("encoding revision %q", r)
v := &encoding.ApiVersion{
Header: encoding.Header{
ApiVersion: encoding.RegistryV1,
Expand Down Expand Up @@ -135,35 +139,41 @@ func exportProxies(ctx context.Context, client apigee.Client) error {
Header: encoding.Header{ApiVersion: encoding.RegistryV1},
Items: apis,
}
return yaml.NewEncoder(os.Stdout).Encode(items)
log.FromContext(ctx).Infof("encoding yaml output")
err = yaml.NewEncoder(os.Stdout).Encode(items)
log.FromContext(ctx).Infof("proxies export complete")
return err
}

func addDeployments(ctx context.Context, client apigee.Client, apisByProxyName map[string]*encoding.Api) error {
if len(apisByProxyName) == 0 {
return nil
}

log.FromContext(ctx).Infof("retrieving envmap")
envMap, err := client.EnvMap(ctx)
if err != nil {
return err
}

log.FromContext(ctx).Infof("retrieving deployments")
deps, err := client.Deployments(ctx)
if err != nil {
return err
}
log.FromContext(ctx).Infof("%d deployments discovered", len(deps))

for _, dep := range deps {
hostnames, ok := envMap.Hostnames(dep.Environment)
if !ok {
log.Warnf(ctx, "Failed to find hostnames for environment %s", dep.Environment)
log.FromContext(ctx).Warnf("failed to find hostnames for environment %s", dep.Environment)
continue
}

for _, hostname := range hostnames {
api, ok := apisByProxyName[dep.ApiProxy]
if !ok {
log.Warnf(ctx, "Unknown proxy: %q for deployment: %#v", dep.ApiProxy, dep)
log.FromContext(ctx).Warnf("unknown proxy: %q for deployment: %#v", dep.ApiProxy, dep)
continue
}

Expand Down