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

fix: adding workaround for cloud workflows issue #310

Merged
merged 38 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f9aa551
adding dependencies for iam roles
shanecglass Mar 6, 2024
79bcd15
Testing solution
shanecglass Mar 6, 2024
5c4f32b
testing
shanecglass Mar 6, 2024
0e2b072
debug solution
shanecglass Mar 6, 2024
465d26d
testing
shanecglass Mar 6, 2024
da92ac5
debug
shanecglass Mar 6, 2024
1069ece
testing
shanecglass Mar 6, 2024
8ccc96b
cleanup
shanecglass Mar 6, 2024
9bc4e03
typo
shanecglass Mar 6, 2024
14d9567
add jsondecode
shanecglass Mar 6, 2024
00aae30
testing
shanecglass Mar 6, 2024
5359355
testing
shanecglass Mar 6, 2024
b80eb7e
Testing
shanecglass Mar 6, 2024
1c42b7e
testing
shanecglass Mar 6, 2024
2a956c6
testing
shanecglass Mar 6, 2024
3bff765
testing
shanecglass Mar 6, 2024
6665700
fix issue
shanecglass Mar 6, 2024
6ac6e1a
increase wait to check time
shanecglass Mar 6, 2024
65ef4fd
testing dry idea
shanecglass Mar 6, 2024
b303162
cleanup
shanecglass Mar 6, 2024
8884eb8
Formatting
shanecglass Mar 6, 2024
ca01648
Typo
shanecglass Mar 6, 2024
b78575b
Dependency update
shanecglass Mar 6, 2024
12f3d25
testing
shanecglass Mar 6, 2024
95e53e4
testing
shanecglass Mar 6, 2024
2613075
testing
shanecglass Mar 6, 2024
6167f15
cleanup
shanecglass Mar 6, 2024
0e97232
testing
shanecglass Mar 6, 2024
2e13405
Clean up and formatting
shanecglass Mar 6, 2024
a0512a6
Lint fixes
shanecglass Mar 6, 2024
78bf04a
update version constraints
shanecglass Mar 6, 2024
992e05a
Docs generation
shanecglass Mar 7, 2024
2c4482c
Clean up
shanecglass Mar 7, 2024
55eaf37
Query cleanup
shanecglass Mar 25, 2024
bfe3640
Update workflow polling to meet testing requirements
shanecglass Mar 25, 2024
fdde024
FIle clean up
shanecglass Mar 25, 2024
7e3d769
Updates to testing fix
shanecglass Mar 25, 2024
e16514c
Merge remote-tracking branch 'refs/remotes/origin/master'
shanecglass Mar 25, 2024
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
4 changes: 2 additions & 2 deletions modules/data_warehouse/bigquery.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ resource "google_project_iam_member" "bq_connection_iam_object_viewer" {
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_bigquery_connection.ds_connection.cloud_resource[0].service_account_id}"

depends_on = [google_storage_bucket.raw_bucket, google_bigquery_connection.ds_connection]
depends_on = [google_project_iam_member.workflow_manage_sa_roles, google_bigquery_connection.ds_connection]
}

## Create a BigQuery connection for Vertex AI to support GenerativeAI use cases
Expand Down Expand Up @@ -372,6 +372,6 @@ resource "google_bigquery_data_transfer_config" "dts_config" {
depends_on = [
google_project_iam_member.dts_roles,
google_bigquery_dataset.ds_edw,
time_sleep.complete_workflow
module.workflow_polling_4
]
}
11 changes: 2 additions & 9 deletions modules/data_warehouse/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,22 @@ spec:
description: {}
icon: assets/data_warehouse_icon_v1.png
deploymentDuration:
configurationSecs: 120
deploymentSecs: 420
configurationSecs: "120"
deploymentSecs: "420"
costEstimate:
description: cost of this solution is $0.65
url: https://cloud.google.com/products/calculator/#id=857776c6-49e8-4c6a-adc5-42a15b8fb67d
cloudProducts:
- productId: search_BIGQUERY_SECTION
pageUrl: ""
- productId: WORKFLOWS_SECTION
pageUrl: ""
- productId: STORAGE_SECTION
pageUrl: ""
- productId: ai-platform
pageUrl: ""
- productId: LOOKER_STUDIO_SECTION
pageUrl: lookerstudio.google.com
isExternal: true
- productId: CLOUD_DMS_SECTION
pageUrl: ""
- productId: FUNCTIONS_SECTION
pageUrl: ""
- productId: DATAFORM_SECTION
pageUrl: ""
content:
architecture:
diagramUrl: www.gstatic.com/pantheon/images/solutions/data-warehouse-architecture_v6.svg
Expand Down
7 changes: 6 additions & 1 deletion modules/data_warehouse/notebook_deployment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ resource "google_dataform_repository_iam_member" "workflow_manage_repo" {
count = length(local.notebook_names)
repository = local.notebook_names[count.index]

depends_on = [google_service_account_iam_member.workflow_auth_function, google_dataform_repository_iam_member.function_manage_repo, google_dataform_repository.notebook_repo]
depends_on = [
google_project_iam_member.workflow_manage_sa_roles,
google_service_account_iam_member.workflow_auth_function,
google_dataform_repository_iam_member.function_manage_repo,
google_dataform_repository.notebook_repo
]
}

# Create and deploy a Cloud Function to deploy notebooks
Expand Down
6 changes: 3 additions & 3 deletions modules/data_warehouse/src/sql/sp_sample_queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SELECT
GROUP BY
1, 2
ORDER BY
WeekdayNumber, 3
WeekdayNumber
;

-- Query: Items with less than 30 days of inventory remaining
Expand All @@ -58,7 +58,7 @@ WITH Orders AS (
FROM
`${project_id}.${dataset_id}.order_items` AS order_items
WHERE
order_items.created_at > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
order_items.created_at > TIMESTAMP_SUB(TIMESTAMP("2023-09-26 00:00:00"), INTERVAL 30 DAY)
GROUP BY
product_id
),
Expand Down Expand Up @@ -99,7 +99,7 @@ SELECT
FROM
End30dInventory
ORDER BY
rank ASC, current_stock DESC
rank ASC, count_sold_30d DESC, current_stock DESC
;

-- Query: data summed by month, then pivoted by department
Expand Down
10 changes: 5 additions & 5 deletions modules/data_warehouse/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ terraform {
source = "hashicorp/google-beta"
version = ">= 4.52, < 6"
}
random = {
source = "hashicorp/random"
version = ">= 2"
}
archive = {
source = "hashicorp/archive"
version = ">= 2"
version = "2.4.2"
}
time = {
source = "hashicorp/time"
Expand All @@ -44,6 +40,10 @@ terraform {
source = "hashicorp/local"
version = ">=2.4"
}
random = {
source = "hashicorp/random"
version = "3.6.0"
}
}
required_version = ">= 0.13"

Expand Down
98 changes: 98 additions & 0 deletions modules/data_warehouse/workflow_polling/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

data "google_client_config" "current" {
}

locals {
is_active = var.input_workflow_state == null || var.input_workflow_state == "FAILED" ? "no" : "yes"
}

## Trigger the execution of the setup workflow with an API call
data "http" "call_workflows_setup" {
url = "https://workflowexecutions.googleapis.com/v1/${var.workflow_id}/executions"
method = local.is_active == "no" ? "POST" : "GET"
# method = "POST"
request_headers = {
Accept = "application/json"
Authorization = "Bearer ${data.google_client_config.current.access_token}" }
}

resource "time_sleep" "workflow_execution_wait" {
create_duration = "120s"
depends_on = [
data.http.call_workflows_setup
]
}

# locals {
# is_active = var.input_workflow_state == null || var.input_workflow_state == "FAILED" ? "no" : "yes"
# }

# ## Trigger the execution of the setup workflow with an API call
# data "http" "call_workflows_setup" {
# url = "https://workflowexecutions.googleapis.com/v1/${var.workflow_id}/executions"
# method = local.is_active == "no" ? "POST" : "GET"
# request_headers = {
# Accept = "application/json"
# Authorization = "Bearer ${data.google_client_config.current.access_token}" }
# }

# ## If the workflow last failed, sleep for 30 seconds before checking the workflow execution status.
# ## If last execution did not fail, exit as quickly as possible (1 second)
# resource "time_sleep" "workflow_execution_wait" {
# create_duration = local.is_active == "no" ? "30s" : "1s"
# depends_on = [
# data.http.call_workflows_setup,
# ]
# }

## Check the state of the setup workflow execution with an API call
data "http" "call_workflows_state" {
url = "https://workflowexecutions.googleapis.com/v1/${var.workflow_id}/executions"
method = "GET"
request_headers = {
Accept = "application/json"
Authorization = "Bearer ${data.google_client_config.current.access_token}" }
depends_on = [
data.http.call_workflows_setup,
time_sleep.workflow_execution_wait
]
}

## Parse out the workflow execution state from the API call response
locals {
response_body = jsondecode(data.http.call_workflows_state.response_body)
workflow_state = local.response_body.executions[0].state
}

## Output the workflow state to use as input for subsequent invocations
output "workflow_state" {
description = "State of the most recent workflow execution. Used to determine how to proceed with next polling run."
value = local.workflow_state
}

# ## If workflow execution is actively running, sleep for 90 seconds to allow it to finish
# ## If not, exit as quickly as possible (1 second)
# resource "time_sleep" "complete_workflow" {
# create_duration = local.workflow_state == "ACTIVE" ? "90s" : "1s"
# depends_on = [
# data.http.call_workflows_setup,
# time_sleep.workflow_execution_wait,
# data.http.call_workflows_state,
# local.workflow_state
# ]
# }
27 changes: 27 additions & 0 deletions modules/data_warehouse/workflow_polling/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "input_workflow_state" {
type = string
description = "Name of the BigQuery ML GenAI remote model that connects to the LLM used for text generation"
}

variable "workflow_id" {
type = string
description = "The identifer of a workflow created by Terraform. Format is projects/{project ID}/locations/{region}/workflows/{workflow name}"
}


53 changes: 53 additions & 0 deletions modules/data_warehouse/workflow_polling/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.52, < 6"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.52, < 6"
}
archive = {
source = "hashicorp/archive"
version = ">= 2"
}
random = {
source = "hashicorp/random"
version = ">= 2"
}
time = {
source = "hashicorp/time"
version = ">= 0.9.1"
}
http = {
source = "hashicorp/http"
version = ">= 2"
}
local = {
source = "hashicorp/local"
version = ">=2.4"
}
}
required_version = ">= 0.13"

provider_meta "google" {
module_name = "blueprints/terraform/terraform-google-bigquery:data_warehouse/v7.0.0"
}
}
Loading