-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable Prometheus sidecar in Cloud Run v2. (#253)
Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com> Co-authored-by: abhishek kumar tiwari <abhiwa@google.com>
- Loading branch information
1 parent
526431a
commit 214aa10
Showing
11 changed files
with
238 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Cloud Run Service using v2 API and Prometheus Sidecar Example | ||
|
||
This example showcases the basic deployment of containerized applications with Prometheus Sidecar to provide observability on Cloud Run and IAM policy for the service. | ||
|
||
The resources/services/activations/deletions that this example will create/trigger are: | ||
|
||
* Creates a Cloud Run service with provided name and container. | ||
* Add Prometheus Sidecar container to the Cloud Run instance. | ||
* Creates a Service Account capable of writing metrics to be used by Cloud Run Service. | ||
|
||
## Assumptions and Prerequisites | ||
|
||
This example assumes that below mentioned prerequisites are in place before consuming the example. | ||
|
||
* All required APIs are enabled in the GCP Project | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| project\_id | The project ID to deploy to | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| observed\_generation | The generation of this Service currently serving traffic. | | ||
| project\_id | Project ID of the service | | ||
| service\_id | Unique Identifier for the created service with format projects/{{project}}/locations/{{location}}/services/{{name}} | | ||
| service\_location | Location in which the Cloud Run service was created | | ||
| service\_name | Name of the created service | | ||
| service\_uri | The URL on which the deployed service is available | | ||
| traffic\_statuses | Detailed status information for corresponding traffic targets. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
## Requirements | ||
|
||
These sections describe requirements for using this example. | ||
|
||
### Software | ||
|
||
* [Terraform](https://www.terraform.io/downloads.html) ~> v0.13+ | ||
* [Terraform Provider for GCP](https://github.com/terraform-providers/terraform-provider-google) ~> v5.0+ | ||
* [Terraform Provider for GCP Beta](https://github.com/terraform-providers/terraform-provider-google-beta) ~> | ||
v5.0+ | ||
|
||
### Service Account | ||
|
||
A service account can be used with required roles to execute this example: | ||
|
||
* Cloud Run Admin: `roles/run.admin` | ||
|
||
Know more about [Cloud Run Deployment Permissions](https://cloud.google.com/run/docs/reference/iam/roles#additional-configuration). | ||
|
||
The [Project Factory module](https://registry.terraform.io/modules/terraform-google-modules/project-factory/google/latest) and the | ||
[IAM module](https://registry.terraform.io/modules/terraform-google-modules/iam/google/latest) may be used in combination to provision a service account with the necessary roles applied. | ||
|
||
### APIs | ||
|
||
A project with the following APIs enabled must be used to host the main resource of this example: | ||
|
||
* Google Cloud Run: `run.googleapis.com` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
module "cloud_run_v2" { | ||
source = "GoogleCloudPlatform/cloud-run/google//modules/v2" | ||
version = "~> 0.14" | ||
|
||
service_name = "ci-cloud-run-v2-gmp" | ||
project_id = var.project_id | ||
location = "us-central1" | ||
containers = [ | ||
{ | ||
container_image = "us-docker.pkg.dev/cloudrun/container/hello" | ||
container_name = "hello-world" | ||
} | ||
] | ||
enable_prometheus_sidecar = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
output "project_id" { | ||
value = module.cloud_run_v2.project_id | ||
description = "Project ID of the service" | ||
} | ||
|
||
output "service_name" { | ||
value = module.cloud_run_v2.service_name | ||
description = "Name of the created service" | ||
} | ||
|
||
output "service_uri" { | ||
value = module.cloud_run_v2.service_uri | ||
description = "The URL on which the deployed service is available" | ||
} | ||
|
||
output "service_id" { | ||
value = module.cloud_run_v2.service_id | ||
description = "Unique Identifier for the created service with format projects/{{project}}/locations/{{location}}/services/{{name}}" | ||
} | ||
|
||
output "service_location" { | ||
value = module.cloud_run_v2.location | ||
description = "Location in which the Cloud Run service was created" | ||
} | ||
|
||
output "traffic_statuses" { | ||
value = module.cloud_run_v2.traffic_statuses | ||
description = "Detailed status information for corresponding traffic targets." | ||
} | ||
|
||
output "observed_generation" { | ||
value = module.cloud_run_v2.observed_generation | ||
description = "The generation of this Service currently serving traffic." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* 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 "project_id" { | ||
description = "The project ID to deploy to" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters