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

feat: expanded integration testing #288

Merged
merged 84 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
d24c99c
Add GenAI use case
shanecglass Oct 9, 2023
2cbeec8
Correct IAM block for BQ connection to Vertex
shanecglass Oct 9, 2023
85e4979
Typo correction
shanecglass Oct 9, 2023
6cb4038
Correcting typos
shanecglass Oct 9, 2023
fb612d4
Correcting development errors
shanecglass Oct 9, 2023
389ca04
Formatting
shanecglass Oct 9, 2023
66edef3
Reduce wait_after_apis time
shanecglass Oct 9, 2023
cc1f6ff
Update dependencies
shanecglass Oct 9, 2023
510e60c
Fixing issue of conflicting resource generation
shanecglass Oct 9, 2023
a18affe
Comment out GenAI query on routine creation
shanecglass Oct 11, 2023
ef7be60
Adding additional instructions
shanecglass Oct 11, 2023
01e0297
Merge branch 'scg-dev'
shanecglass Oct 11, 2023
3d94663
Testing BQ connection
shanecglass Oct 11, 2023
92c8414
Correcting connection reference
shanecglass Oct 11, 2023
13042dd
Correct BigQuery connection reference
shanecglass Oct 11, 2023
11ac934
Typo correction
shanecglass Oct 11, 2023
14ecbed
Merge pull request #10 from shanecglass/scg-dev
shanecglass Oct 11, 2023
758a4f5
Add BQML model creations to workflow
shanecglass Oct 11, 2023
293a0e7
Update workflow dataset reference
shanecglass Oct 11, 2023
472a2bf
Automating remote model creation
shanecglass Oct 11, 2023
6a180b4
Updating GenAI model parameters
shanecglass Oct 11, 2023
c4a9b57
Formatting
shanecglass Oct 13, 2023
4cc9814
Update architecture diagram
shanecglass Oct 18, 2023
7b90a2e
update architecture diagrams
shanecglass Oct 19, 2023
d5589d2
Merge branch 'master' of https://github.com/terraform-google-modules/…
shanecglass Oct 19, 2023
596c5e2
Updated architecture diagrams
shanecglass Oct 19, 2023
0e85b5b
Updated architecture diagram
shanecglass Oct 19, 2023
d09f553
Documentation updates
shanecglass Oct 20, 2023
2c14c62
Merge branch 'master' into scg-dev
shanecglass Oct 20, 2023
74f7cd2
Lint fix
shanecglass Oct 20, 2023
d3dfe91
Fixing lint issues
shanecglass Oct 23, 2023
d311ecf
Docs updates
shanecglass Oct 23, 2023
b20bd15
Merge branch 'master' into scg-dev
davenportjw Oct 23, 2023
d10acc6
Merge pull request #13 from shanecglass/scg-dev
shanecglass Oct 23, 2023
9da42e9
Add wait timer for workflow execution
shanecglass Nov 8, 2023
60f5d56
Add wait time to workflow execution
shanecglass Nov 8, 2023
71db003
Replacing workflow trigger
shanecglass Nov 8, 2023
87063f7
Adding API call to trigger workflow
shanecglass Nov 9, 2023
fa2b0da
Formatting
shanecglass Nov 9, 2023
4ae7172
Improved comments to clarify workflow
shanecglass Nov 9, 2023
1cfde9a
Removing unneeded resources
shanecglass Nov 9, 2023
b57bb7b
Removing unneeded resources
shanecglass Nov 9, 2023
177ed51
Updating dependencies
shanecglass Nov 9, 2023
bffe3b6
Correct dependency name
shanecglass Nov 9, 2023
a675e0b
Merge pull request #14 from terraform-google-modules/master
shanecglass Nov 9, 2023
94751ed
Removing unnecessary resources
shanecglass Nov 9, 2023
ba58b73
Merge pull request #15 from shanecglass/scg-dev
shanecglass Nov 9, 2023
288ddbc
Update README
shanecglass Nov 9, 2023
80caf78
Add http provider
shanecglass Nov 9, 2023
584c283
Merge pull request #16 from shanecglass/scg-dev
shanecglass Nov 9, 2023
14a18d4
Add region constraint
shanecglass Nov 9, 2023
3c917b4
Merge pull request #17 from shanecglass/scg-dev
shanecglass Nov 9, 2023
6f78fda
Formatting
shanecglass Nov 9, 2023
53cbecb
Merge branch 'master' into master
davenportjw Nov 10, 2023
524fae9
adding wait dependency for scheduled query
shanecglass Nov 14, 2023
6a6dbfd
Add dependency for scheduled query
shanecglass Nov 14, 2023
6956cf2
Merge pull request #18 from shanecglass/scg-dev
shanecglass Nov 14, 2023
748ee77
Expanding integration testing
shanecglass Nov 15, 2023
96daebd
Merge pull request #19 from shanecglass/scg-dev
shanecglass Nov 15, 2023
fa87a25
Shrink PR to just include testing changes
shanecglass Nov 17, 2023
fa6a258
Merge pull request #20 from shanecglass/shanecglass/master
shanecglass Nov 17, 2023
4aeabd2
Expanded integration testing support
shanecglass Nov 17, 2023
2243459
Expanded integration testing
shanecglass Nov 17, 2023
2870650
Updating mod file
shanecglass Nov 17, 2023
bd42698
fixing mod file
shanecglass Nov 17, 2023
38a8786
Splitting into 2 PRs
shanecglass Nov 17, 2023
9cfe96e
Updating region of test execution
shanecglass Nov 17, 2023
decc215
Correcting workflow polling
shanecglass Nov 17, 2023
768f782
Testing changes to queries to prevent errors
shanecglass Nov 17, 2023
cdc1dc5
Fixing typo in query
shanecglass Nov 17, 2023
1b46926
Make projectId explicit in bq checks
shanecglass Nov 28, 2023
9b35251
Cleanup bq testing
shanecglass Nov 28, 2023
1cae23e
Typo in bq check
shanecglass Nov 29, 2023
5130aec
Manually create bigqueryrc file before queries
shanecglass Nov 29, 2023
3021b02
Merge branch 'master' into master
shanecglass Nov 30, 2023
2aad8b5
Issue diagnosis
shanecglass Nov 30, 2023
6be6bbe
Diagnosing query comparison issues
shanecglass Nov 30, 2023
b7cd6d4
Merge branch 'master' into master
shanecglass Nov 30, 2023
5ba4caf
Troubleshooting
shanecglass Nov 30, 2023
bec99ea
Troubleshooting
shanecglass Nov 30, 2023
e27c0d3
Correct assertions in tests
shanecglass Nov 30, 2023
9115c25
Correct data type mismatch
shanecglass Nov 30, 2023
de00bbb
Correct parsing of query results
shanecglass Nov 30, 2023
cc536d5
Cleanup error messaging formatting
shanecglass Nov 30, 2023
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
2 changes: 1 addition & 1 deletion examples/data_warehouse/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "data_warehouse" {
source = "../../modules/data_warehouse"

project_id = var.project_id
region = "us-central1"
region = "asia-southeast1"
deletion_protection = false
force_destroy = true
}
92 changes: 90 additions & 2 deletions test/integration/data_warehouse/data_warehouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@
package multiple_buckets

import (
"fmt"
"log"
"os"
"reflect"
"testing"
"time"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/bq"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
"github.com/stretchr/testify/assert"
)

// TODO: Remove because Eventarc is no longer in use
// Retry if these errors are encountered.
var retryErrors = map[string]string{
// IAM for Eventarc service agent is eventually consistent
Expand All @@ -37,10 +44,91 @@ func TestDataWarehouse(t *testing.T) {

projectID := dwh.GetTFSetupStringOutput("project_id")
bucket := dwh.GetStringOutput("raw_bucket")
workflow := "initial-workflow"

// Assert that the bucket is in asia-southeast1
bucketOP := gcloud.Runf(t, "storage buckets describe gs://%s --project %s", bucket, projectID)
assert.Equal("US-CENTRAL1", bucketOP.Get("location").String(), "should be in us-central1")
//TODO: Add additional asserts for other resources
assert.Equal("ASIA-SOUTHEAST1", bucketOP.Get("location").String(), "Bucket should be in asia-southeast1")

// Assert that Workflow ran successfully
verifyWorkflows := func() (bool, error) {
workflowState := gcloud.Runf(t, "workflows executions list %s --project %s --location=asia-southeast1 --limit=1", workflow, projectID).Array()
state := workflowState[0].Get("state").String()
assert.NotEqual(t, state, "FAILED")
if state == "SUCCEEDED" {
return false, nil
} else {
return true, nil
}
}
utils.Poll(t, verifyWorkflows, 8, 30*time.Second)

homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
file, err := os.Create(homeDir + "/.bigqueryrc")
if err != nil {
log.Fatal(err)
}
file.Close()

// Assert BigQuery tables & views are not empty
test_tables := func (){

tables := []string{
"thelook.distribution_centers",
"thelook.events",
"thelook.inventory_items",
"thelook.order_items",
"thelook.orders",
"thelook.products",
"thelook.users",
"thelook.lookerstudio_report_distribution_centers",
"thelook.lookerstudio_report_profit",
}

query_template := "SELECT COUNT(*) AS count_rows FROM `%[1]s.%[2]s`;"
for _, table := range tables {
query := fmt.Sprintf(query_template, projectID, table)
op := bq.Runf(t, "--project_id=%[1]s --headless=true query --nouse_legacy_sql %[2]s", projectID, query)
fmt.Print(op)

count := op.Get("0.count_rows").Int()
fmt.Printf("Table has %d rows \n", count)
count_kind := reflect.TypeOf(count).Kind()
fmt.Printf("count has type %s \n", count_kind)
test_result := assert.Greater(count, int64(0))
if test_result == true {
fmt.Printf("Table `%s` has %d rows. Test passed! \n", table, count)
} else {
fmt.Printf("Some kind of error occurred while running the count query for the %s table. We think it has %d rows. Test failed. \n", table, count)
}
}
}

test_tables()

// Assert BigQuery connection to Vertex GenAI was successfully created and works as expected
test_llms := func() {

llm_query_template := "SELECT COUNT(*) AS count_rows FROM ML.GENERATE_TEXT(MODEL `%[1]s.thelook.text_generate_model`, (with clusters AS(SELECT CONCAT('cluster', CAST(centroid_id as STRING)) as centroid, avg_spend as average_spend, count_orders as count_of_orders, days_since_order FROM (SELECT centroid_id, feature, ROUND(numerical_value, 2) as value FROM ML.CENTROIDS(MODEL `%[1]s.thelook.customer_segment_clustering`)) PIVOT (SUM(value) FOR feature IN ('avg_spend', 'count_orders', 'days_since_order')) ORDER BY centroid_id) SELECT 'Pretend you are a creative strategist, given the following clusters come up with creative brand persona and title labels for each of these clusters, and explain step by step; what would be the next marketing step for these clusters' || ' ' || clusters.centroid || ', Average Spend $' || clusters.average_spend || ', Count of orders per person ' || clusters.count_of_orders || ', Days since last order ' || clusters.days_since_order AS prompt FROM clusters), STRUCT(800 AS max_output_tokens, 0.8 AS temperature, 40 AS top_k, 0.8 AS top_p, TRUE AS flatten_json_output));"
query := fmt.Sprintf(llm_query_template, projectID)
llm_op := bq.Runf(t, "--project_id=%[1]s --headless=true query --nouse_legacy_sql %[2]s", projectID, query)

llm_count := llm_op.Get("0.count_rows").Int()
count_llm_kind := reflect.TypeOf(llm_count).Kind()
fmt.Printf("llm_count has type %s", count_llm_kind)
llm_test_result := assert.Greater(llm_count, int64(0))
if llm_test_result == true {
fmt.Printf("LLM table has %d rows. Test passed! \n", llm_count)
} else {
fmt.Printf("Some kind of error occurred while running the count query for the LLM table. We think it has %d rows. Test failed. \n", llm_count)
}
}

test_llms()
})
dwh.Test()
}

59 changes: 29 additions & 30 deletions test/integration/go.mod
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
module github.com/terraform-google-modules/terraform-google-bigquery/test/integration

go 1.20
go 1.21

require (
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.10.1
github.com/stretchr/testify v1.8.4
)

require (
cloud.google.com/go v0.110.7 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.2 // indirect
cloud.google.com/go/storage v1.33.0 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/storage v1.35.1 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aws/aws-sdk-go v1.45.5 // indirect
github.com/aws/aws-sdk-go v1.47.13 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-errors/errors v1.5.0 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gruntwork-io/terratest v0.46.6 // indirect
github.com/gruntwork-io/terratest v0.46.7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.2 // indirect
github.com/hashicorp/go-getter v1.7.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.0 // indirect
github.com/hashicorp/terraform-json v0.17.1 // indirect
github.com/hashicorp/hcl/v2 v2.19.1 // indirect
github.com/hashicorp/terraform-json v0.18.0 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.3 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-zglob v0.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand All @@ -56,25 +54,26 @@ require (
github.com/tidwall/sjson v1.2.5 // indirect
github.com/tmccombs/hcl2json v0.6.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zclconf/go-cty v1.14.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.138.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.151.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20230905202853-d090da108d2f // indirect
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
sigs.k8s.io/kustomize/kyaml v0.15.0 // indirect
)
Loading