Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Return appsync errors as strings (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored Dec 3, 2020
1 parent 3c974a3 commit 6111bdf
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
18 changes: 9 additions & 9 deletions builders/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,30 @@ steps:
- 'build-apiserver'

#
# app-sync
# appsync
#
- id: 'build-app-sync'
- id: 'build-appsync'
name: 'golang:1.15.2'
args:
- 'go'
- 'build'
- '-trimpath'
- '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static'
- '-o=./bin/app-sync'
- './cmd/app-sync'
- '-o=./bin/appsync'
- './cmd/appsync'
waitFor:
- 'download-modules'

- id: 'dockerize-app-sync'
- id: 'dockerize-appsync'
name: 'docker:19'
args:
- 'build'
- '--file=builders/service.dockerfile'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/app-sync:${_TAG}'
- '--build-arg=SERVICE=app-sync'
- '--tag=gcr.io/${PROJECT_ID}/${_REPO}/appsync:${_TAG}'
- '--build-arg=SERVICE=appsync'
- '.'
waitFor:
- 'build-app-sync'
- 'build-appsync'

#
# cleanup
Expand Down Expand Up @@ -296,7 +296,7 @@ steps:
images:
- 'gcr.io/${PROJECT_ID}/${_REPO}/adminapi:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/apiserver:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/app-sync:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/appsync:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/cleanup:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/e2e-runner:${_TAG}'
- 'gcr.io/${PROJECT_ID}/${_REPO}/enx-redirect:${_TAG}'
Expand Down
8 changes: 4 additions & 4 deletions builders/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ steps:
- '-'

#
# app-sync
# appsync
#
- id: 'deploy-app-sync'
- id: 'deploy-appsync'
name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:307.0.0-alpine'
args:
- 'bash'
- '-eEuo'
- 'pipefail'
- '-c'
- |-
gcloud run deploy "app-sync" \
gcloud run deploy "appsync" \
--quiet \
--project "${PROJECT_ID}" \
--platform "managed" \
--region "${_REGION}" \
--image "gcr.io/${PROJECT_ID}/${_REPO}/app-sync:${_TAG}" \
--image "gcr.io/${PROJECT_ID}/${_REPO}/appsync:${_TAG}" \
--no-traffic
waitFor:
- '-'
Expand Down
6 changes: 3 additions & 3 deletions builders/promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ steps:
- '-'

#
# app-sync
# appsync
#
- id: 'promote-app-sync'
- id: 'promote-appsync'
name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:307.0.0-alpine'
args:
- 'bash'
- '-eEuo'
- 'pipefail'
- '-c'
- |-
gcloud run services update-traffic "app-sync" \
gcloud run services update-traffic "appsync" \
--quiet \
--project "${PROJECT_ID}" \
--platform "managed" \
Expand Down
File renamed without changes.
17 changes: 13 additions & 4 deletions pkg/controller/appsync/appsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const playStoreHost = `play.google.com/store/apps/details`
// HandleSync performs the logic to sync mobile apps.
func (c *Controller) HandleSync() http.Handler {
type AppSyncResult struct {
OK bool `json:"ok"`
Errors []error `json:"errors,omitempty"`
OK bool `json:"ok"`
Errors []string `json:"errors,omitempty"`
}

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -48,9 +48,19 @@ func (c *Controller) HandleSync() http.Handler {
// If there are any errors, return them
if merr := c.syncApps(ctx, apps); merr != nil {
if errs := merr.WrappedErrors(); len(errs) > 0 {
// Convert error messages to strings to they appear correctly in JSON.
// See here for more information:
//
// https://stackoverflow.com/questions/44989924/golang-error-types-are-empty-when-encoded-to-json
//
errMsgs := make([]string, len(errs))
for i, err := range errs {
errMsgs[i] = err.Error()
}

c.h.RenderJSON(w, http.StatusInternalServerError, &AppSyncResult{
OK: false,
Errors: errs,
Errors: errMsgs,
})
return
}
Expand All @@ -69,7 +79,6 @@ func (c *Controller) syncApps(ctx context.Context, apps *clients.AppsResponse) *
appsByRealm := map[uint][]*database.MobileApp{}

for _, app := range apps.Apps {

realm, err := c.findRealmForApp(app, realms)
if err != nil {
merr = multierror.Append(merr, fmt.Errorf("unable to lookup realm for region %q: %w", app.Region, err))
Expand Down
2 changes: 1 addition & 1 deletion terraform/service_appsync.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ resource "google_cloud_run_service" "appsync" {
service_account_name = google_service_account.appsync.email

containers {
image = "gcr.io/${var.project}/github.com/google/exposure-notifications-verification-server/app-sync:initial"
image = "gcr.io/${var.project}/github.com/google/exposure-notifications-verification-server/appsync:initial"

resources {
limits = {
Expand Down

0 comments on commit 6111bdf

Please sign in to comment.