-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
14 changed files
with
379 additions
and
0 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,46 @@ | ||
# Table: gcp_monitoring_alert_policy | ||
|
||
An alerting policy describes a set of conditions that you want to monitor. These conditions might relate to the state of an unhealthy system or to resource consumption. | ||
|
||
## Examples | ||
|
||
### Basic info | ||
|
||
```sql | ||
select | ||
display_name, | ||
name, | ||
enabled, | ||
documentation ->> 'content' as doc_content, | ||
tags | ||
from | ||
gcp_monitoring_alert_policy; | ||
``` | ||
|
||
|
||
### Get the creation record for each alert policy | ||
|
||
```sql | ||
select | ||
display_name, | ||
name, | ||
creation_record ->> 'mutateTime' as mutation_time, | ||
creation_record ->> 'mutatedBy' as mutated_by | ||
from | ||
gcp_monitoring_alert_policy; | ||
``` | ||
|
||
|
||
### Get the condition details for each alert policy | ||
|
||
```sql | ||
select | ||
display_name, | ||
con ->> 'displayName' as filter_display_name, | ||
con -> 'conditionThreshold' ->> 'filter' as filter, | ||
con -> 'conditionThreshold' ->> 'thresholdValue' as threshold_value, | ||
con -> 'conditionThreshold' ->> 'trigger' as trigger | ||
from | ||
gcp_monitoring_alert_policy, | ||
jsonb_array_elements(conditions) as con; | ||
``` |
Empty file.
17 changes: 17 additions & 0 deletions
17
gcp-test/tests/gcp_monitoring_alert_policy/test-get-expected.json
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,17 @@ | ||
[ | ||
{ | ||
"combiner": "OR", | ||
"display_name": "{{ resourceName }}", | ||
"documentation": { | ||
"content": "This is for testing purpose", | ||
"mimeType": "text/markdown" | ||
}, | ||
"enabled": true, | ||
"location": "global", | ||
"name": "{{ output.resource_id.value.split('/').pop() }}", | ||
"project": "{{ output.project_id.value }}", | ||
"user_labels": { | ||
"foo": "bar" | ||
} | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_monitoring_alert_policy/test-get-query.sql
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,3 @@ | ||
select name, display_name, combiner, enabled, documentation, project, location, user_labels | ||
from gcp.gcp_monitoring_alert_policy | ||
where name = '{{ output.resource_id.value.split("/").pop() }}'; |
12 changes: 12 additions & 0 deletions
12
gcp-test/tests/gcp_monitoring_alert_policy/test-hydrate-expected.json
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,12 @@ | ||
[ | ||
{ | ||
"combiner": "OR", | ||
"display_name": "{{ resourceName }}", | ||
"enabled": true, | ||
"name": "{{ output.resource_id.value.split('/').pop() }}", | ||
"project": "{{ output.project_id.value }}", | ||
"tags": { | ||
"foo": "bar" | ||
} | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_monitoring_alert_policy/test-hydrate-query.sql
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,3 @@ | ||
select name, display_name, combiner, enabled, tags, project | ||
from gcp.gcp_monitoring_alert_policy | ||
where name = '{{ output.resource_id.value.split("/").pop() }}'; |
7 changes: 7 additions & 0 deletions
7
gcp-test/tests/gcp_monitoring_alert_policy/test-list-expected.json
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,7 @@ | ||
[ | ||
{ | ||
"combiner": "OR", | ||
"display_name": "{{ resourceName }}", | ||
"name": "{{ output.resource_id.value.split('/').pop() }}" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_monitoring_alert_policy/test-list-query.sql
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,3 @@ | ||
select name, display_name, combiner | ||
from gcp.gcp_monitoring_alert_policy | ||
where display_name = '{{ resourceName }}'; |
1 change: 1 addition & 0 deletions
1
gcp-test/tests/gcp_monitoring_alert_policy/test-not-found-expected.json
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 @@ | ||
null |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_monitoring_alert_policy/test-not-found-query.sql
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,3 @@ | ||
select title, akas | ||
from gcp.gcp_monitoring_alert_policy | ||
where name = 'dummy'; |
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 @@ | ||
{} |
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,88 @@ | ||
|
||
variable "resource_name" { | ||
type = string | ||
default = "turbot-test-20200125-create-update" | ||
description = "Name of the resource used throughout the test." | ||
} | ||
|
||
variable "gcp_project" { | ||
type = string | ||
default = "niteowl-aaa" | ||
description = "GCP project used for the test." | ||
} | ||
|
||
variable "gcp_region" { | ||
type = string | ||
default = "us-east1" | ||
description = "GCP region used for the test." | ||
} | ||
|
||
variable "gcp_zone" { | ||
type = string | ||
default = "us-east1-b" | ||
} | ||
|
||
provider "google" { | ||
project = var.gcp_project | ||
region = var.gcp_region | ||
zone = var.gcp_zone | ||
} | ||
|
||
data "google_client_config" "current" {} | ||
|
||
data "null_data_source" "resource" { | ||
inputs = { | ||
scope = "gcp://cloudresourcemanager.googleapis.com/projects/${data.google_client_config.current.project}" | ||
} | ||
} | ||
|
||
resource "google_monitoring_alert_policy" "named_test_resource" { | ||
display_name = var.resource_name | ||
documentation { | ||
content = "This is for testing purpose" | ||
mime_type = "text/markdown" | ||
} | ||
combiner = "OR" | ||
conditions { | ||
display_name = var.resource_name | ||
condition_threshold { | ||
filter = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\"" | ||
duration = "60s" | ||
comparison = "COMPARISON_GT" | ||
aggregations { | ||
alignment_period = "60s" | ||
per_series_aligner = "ALIGN_RATE" | ||
} | ||
} | ||
} | ||
user_labels = { | ||
foo = "bar" | ||
} | ||
} | ||
|
||
data "template_file" "resource_aka" { | ||
template = "gcp://monitoring.googleapis.com/${google_monitoring_alert_policy.named_test_resource.id}" | ||
vars = { | ||
resource_name = var.resource_name | ||
project = data.google_client_config.current.project | ||
region = data.google_client_config.current.region | ||
zone = data.google_client_config.current.zone | ||
} | ||
} | ||
|
||
output "resource_aka" { | ||
depends_on = [google_monitoring_alert_policy.named_test_resource] | ||
value = data.template_file.resource_aka.rendered | ||
} | ||
|
||
output "resource_name" { | ||
value = var.resource_name | ||
} | ||
|
||
output "resource_id" { | ||
value = google_monitoring_alert_policy.named_test_resource.name | ||
} | ||
|
||
output "project_id" { | ||
value = var.gcp_project | ||
} |
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
Oops, something went wrong.