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

Add gcp_monitoring_alert_policy table. closes #145 #168

Merged
merged 5 commits into from
Apr 14, 2021
Merged

Conversation

Paulami30
Copy link
Contributor

@Paulami30 Paulami30 commented Apr 7, 2021

Integration test logs

Logs
No env file present for the current environment:  staging 
 Falling back to .env config
No env file present for the current environment:  staging
customEnv TURBOT_TEST_EXPECTED_TIMEOUT 300

SETUP: tests/gcp_monitoring_alert_policy []

PRETEST: tests/gcp_monitoring_alert_policy

TEST: tests/gcp_monitoring_alert_policy
Running terraform
data.google_client_config.current: Refreshing state...
google_monitoring_alert_policy.named_test_resource: Refreshing state... [id=projects/dummy-aaa/alertPolicies/11789617472293322293]
data.null_data_source.resource: Refreshing state...
data.template_file.resource_aka: Refreshing state...
google_monitoring_alert_policy.named_test_resource: Modifying... [id=projects/dummy-aaa/alertPolicies/11789617472293322293]
google_monitoring_alert_policy.named_test_resource: Modifications complete after 6s [id=projects/dummy-aaa/alertPolicies/11789617472293322293]
data.template_file.resource_aka: Refreshing state...

Warning: Deprecated Resource

The null_data_source was historically used to construct intermediate values to
re-use elsewhere in configuration, the same can now be achieved using locals


Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

project_id = dummy-aaa
resource_aka = gcp://monitoring.googleapis.com/projects/dummy-aaa/alertPolicies/11789617472293322293
resource_id = projects/dummy-aaa/alertPolicies/11789617472293322293
resource_name = turbottest99725

Running SQL query: test-get-query.sql
[
  {
    "combiner": "OR",
    "display_name": "turbottest99725",
    "documentation": {
      "content": "This is for testing purpose",
      "mimeType": "text/markdown"
    },
    "enabled": true,
    "location": "global",
    "name": "11789617472293322293",
    "project": "dummy-aaa",
    "user_labels": {
      "foo": "bar"
    }
  }
]
✔ PASSED

Running SQL query: test-hydrate-query.sql
[
  {
    "combiner": "OR",
    "display_name": "turbottest99725",
    "enabled": true,
    "name": "11789617472293322293",
    "project": "dummy-aaa",
    "tags": {
      "foo": "bar"
    }
  }
]
✔ PASSED

Running SQL query: test-list-query.sql
[
  {
    "combiner": "OR",
    "display_name": "turbottest99725",
    "name": "11789617472293322293"
  }
]
✔ PASSED

Running SQL query: test-not-found-query.sql
null
✔ PASSED

POSTTEST: tests/gcp_monitoring_alert_policy

TEARDOWN: tests/gcp_monitoring_alert_policy

SUMMARY:

1/1 passed.

Example query results

Results
### Basic info
select
  display_name,
  name,
  enabled,
  documentation ->> 'content' as doc_content,
  tags
from
  gcp_monitoring_alert_policy;
  
+--------------+---------------------+---------+-------------+--------+
| display_name | name                | enabled | doc_content | tags   |
+--------------+---------------------+---------+-------------+--------+
| test-alert   | 1385080259726788053 | true    | testing     | <null> |
+--------------+---------------------+---------+-------------+--------+

### Get the creation record for each alert policy
select
  display_name,
  name,
  creation_record ->> 'mutateTime' as mutation_time,
  creation_record ->> 'mutatedBy' as mutated_by
from
  gcp_monitoring_alert_policy;
  
  +--------------+---------------------+--------------------------------+--------------------+
| display_name | name                | mutation_time                  | mutated_by         |
+--------------+---------------------+--------------------------------+--------------------+
| test-alert   | 1385080259726788053 | 2021-04-07T07:11:34.362714499Z | dummy12@turbot.com |
+--------------+---------------------+--------------------------------+--------------------+

### Get the condition details for each alert policy
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;
  
  +--------------+-----------------------------------------+----------------------------------------------------------------------------------------------------
| display_name | filter_display_name                     | filter                                                                                             
+--------------+-----------------------------------------+----------------------------------------------------------------------------------------------------
| test-alert   | VM Instance - CPU usage for test [RATE] | metric.type="compute.googleapis.com/instance/cpu/usage_time" resource.type="gce_instance" metric.la
+--------------+-----------------------------------------+----------------------------------------------------------------------------------------------------

@Paulami30 Paulami30 self-assigned this Apr 7, 2021
@Paulami30 Paulami30 changed the title Add gcp_monitoring_alert_policy table Add gcp_monitoring_alert_policy table. closes #145 Apr 7, 2021
@Subhajit97 Subhajit97 linked an issue Apr 12, 2021 that may be closed by this pull request
Copy link
Contributor

@Subhajit97 Subhajit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Paulami30 There are few changes required. Please see comments, thanks!
Can you also add the queries for the recommendations mentioned in the issue?

Copy link
Contributor

@Subhajit97 Subhajit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@rajlearner17 rajlearner17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cbruno10 cbruno10 merged commit bf10592 into main Apr 14, 2021
@cbruno10 cbruno10 deleted the issue-145 branch April 14, 2021 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "ALERT" table under Monitoring for Metrics alerts
4 participants