-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Fix shoppingassistant demo #2675
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,9 @@ set -e | |
set -x | ||
|
||
# Replace me | ||
PROJECT_ID=<project_id> | ||
PROJECT_NUMBER=<project_number> | ||
PGPASSWORD=<password> | ||
PROJECT_ID=$PROJECT_ID | ||
PROJECT_NUMBER=$PROJECT_NUMBER | ||
PGPASSWORD=$PGPASSWORD | ||
|
||
# Set sensible defaults | ||
REGION=us-central1 | ||
|
@@ -82,7 +82,8 @@ gcloud alloydb instances create ${ALLOYDB_INSTANCE_NAME}-replica \ | |
gcloud beta alloydb instances update ${ALLOYDB_INSTANCE_NAME} \ | ||
--cluster=${ALLOYDB_CLUSTER_NAME} \ | ||
--region=${REGION} \ | ||
--assign-inbound-public-ip=ASSIGN_IPV4 | ||
--assign-inbound-public-ip=ASSIGN_IPV4 \ | ||
--database-flags password.enforce_complexity=on | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flag is now required or else the AlloyDB instance update fails with an error. |
||
|
||
# Fetch the primary and read IPs | ||
ALLOYDB_PRIMARY_IP=`gcloud alloydb instances list --region=${REGION} --cluster=${ALLOYDB_CLUSTER_NAME} --filter="INSTANCE_TYPE:PRIMARY" --format=flattened | sed -nE "s/ipAddress:\s*(.*)/\1/p"` | ||
|
@@ -119,9 +120,6 @@ gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${A | |
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${ALLOYDB_USER_GSA_ID} --role=roles/alloydb.databaseUser | ||
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${ALLOYDB_USER_GSA_ID} --role=roles/secretmanager.secretAccessor | ||
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:${ALLOYDB_USER_GSA_ID} --role=roles/serviceusage.serviceUsageConsumer | ||
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=service-${PROJECT_NUMBER}@gcp-sa-alloydb.iam.gserviceaccount.com --role=roles/aiplatform.user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line now fails with an error saying the member flag is in an invalid format. It doesn't seem needed (anymore). |
||
|
||
# Add bindings to the Online Boutique services that need it | ||
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:service-${PROJECT_NUMBER}@gcp-sa-alloydb.iam.gserviceaccount.com --role=roles/aiplatform.user | ||
|
||
gcloud iam service-accounts add-iam-policy-binding ${ALLOYDB_USER_GSA_ID} \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM golang:1.22.5-alpine@sha256:0d3653dd6f35159ec6e3d10263a42372f6f194c3dea0b35235d72aabde86486e AS builder | ||
FROM golang:1.22.6-alpine@sha256:1a478681b671001b7f029f94b5016aed984a23ad99c707f6a0ab6563860ae2f3 AS builder | ||
|
||
WORKDIR /src | ||
# restore dependencies | ||
|
@@ -28,6 +28,7 @@ FROM scratch | |
|
||
WORKDIR /src | ||
COPY --from=builder /productcatalogservice ./server | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The productscatalog started failing with x509 issues, which this line fixes. |
||
COPY products.json . | ||
|
||
# Definition of this variable is used by 'skaffold debug' to identify a golang binary. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,18 +35,18 @@ func loadCatalog(catalog *pb.ListProductsResponse) error { | |
defer catalogMutex.Unlock() | ||
|
||
if os.Getenv("ALLOYDB_CLUSTER_NAME") != "" { | ||
log.Info("Loading catalog from AlloyDB...") | ||
return loadCatalogFromAlloyDB(catalog) | ||
} | ||
|
||
log.Info("Loading catalog from local products.json file...") | ||
return loadCatalogFromLocalFile(catalog) | ||
} | ||
|
||
func loadCatalogFromLocalFile(catalog *pb.ListProductsResponse) error { | ||
log.Info("loading catalog from local products.json file...") | ||
|
||
catalogJSON, err := os.ReadFile("products.json") | ||
if err != nil { | ||
log.Fatalf("failed to open product catalog json file: %v", err) | ||
log.Warnf("failed to open product catalog json file: %v", err) | ||
return err | ||
} | ||
|
||
|
@@ -63,6 +63,7 @@ func getSecretPayload(project, secret, version string) (string, error) { | |
ctx := context.Background() | ||
client, err := secretmanager.NewClient(ctx) | ||
if err != nil { | ||
log.Warnf("failed to create SecretManager client: %v", err) | ||
return "", err | ||
} | ||
defer client.Close() | ||
|
@@ -74,13 +75,16 @@ func getSecretPayload(project, secret, version string) (string, error) { | |
// Call the API. | ||
result, err := client.AccessSecretVersion(ctx, req) | ||
if err != nil { | ||
log.Warnf("failed to access SecretVersion: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warn logs are a great addition here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to troubleshoot what was happening with the products catalog, and figured I'd leave them for the next time there's a potential issue :) |
||
return "", err | ||
} | ||
|
||
return string(result.Payload.Data), nil | ||
} | ||
|
||
func loadCatalogFromAlloyDB(catalog *pb.ListProductsResponse) error { | ||
log.Info("loading catalog from AlloyDB...") | ||
|
||
projectID := os.Getenv("PROJECT_ID") | ||
region := os.Getenv("REGION") | ||
pgClusterName := os.Getenv("ALLOYDB_CLUSTER_NAME") | ||
|
@@ -96,6 +100,7 @@ func loadCatalogFromAlloyDB(catalog *pb.ListProductsResponse) error { | |
|
||
dialer, err := alloydbconn.NewDialer(context.Background()) | ||
if err != nil { | ||
log.Warnf("failed to set-up dialer connection: %v", err) | ||
return err | ||
} | ||
cleanup := func() error { return dialer.Close() } | ||
|
@@ -108,6 +113,7 @@ func loadCatalogFromAlloyDB(catalog *pb.ListProductsResponse) error { | |
|
||
config, err := pgxpool.ParseConfig(dsn) | ||
if err != nil { | ||
log.Warnf("failed to parse DSN config: %v", err) | ||
return err | ||
} | ||
|
||
|
@@ -118,13 +124,15 @@ func loadCatalogFromAlloyDB(catalog *pb.ListProductsResponse) error { | |
|
||
pool, err := pgxpool.NewWithConfig(context.Background(), config) | ||
if err != nil { | ||
log.Warnf("failed to set-up pgx pool: %v", err) | ||
return err | ||
} | ||
defer pool.Close() | ||
|
||
query := "SELECT id, name, description, picture, price_usd_currency_code, price_usd_units, price_usd_nanos, categories FROM " + pgTableName | ||
rows, err := pool.Query(context.Background(), query) | ||
if err != nil { | ||
log.Warnf("failed to query database: %v", err) | ||
return err | ||
} | ||
defer rows.Close() | ||
|
@@ -139,6 +147,7 @@ func loadCatalogFromAlloyDB(catalog *pb.ListProductsResponse) error { | |
&product.Picture, &product.PriceUsd.CurrencyCode, &product.PriceUsd.Units, | ||
&product.PriceUsd.Nanos, &categories) | ||
if err != nil { | ||
log.Warnf("failed to scan query result row: %v", err) | ||
return err | ||
} | ||
categories = strings.ToLower(categories) | ||
|
@@ -147,5 +156,6 @@ func loadCatalogFromAlloyDB(catalog *pb.ListProductsResponse) error { | |
catalog.Products = append(catalog.Products, product) | ||
} | ||
|
||
log.Info("successfully parsed product catalog from AlloyDB") | ||
return nil | ||
} |
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 was an omission; caught it on a re-run of the script.