| 1 |
--- |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
- name: Delete a metric |
| 17 |
google.cloud.gcp_logging_metric: |
| 18 |
name: "{{ resource_name }}" |
| 19 |
filter: resource.type=gae_app AND severity>=ERROR |
| 20 |
metric_descriptor: |
| 21 |
metric_kind: DELTA |
| 22 |
value_type: DISTRIBUTION |
| 23 |
unit: "1" |
| 24 |
labels: |
| 25 |
- key: mass |
| 26 |
value_type: STRING |
| 27 |
description: amount of matter |
| 28 |
value_extractor: EXTRACT(jsonPayload.request) |
| 29 |
label_extractors: |
| 30 |
mass: EXTRACT(jsonPayload.request) |
| 31 |
bucket_options: |
| 32 |
linear_buckets: |
| 33 |
num_finite_buckets: 3 |
| 34 |
width: 1 |
| 35 |
offset: 1 |
| 36 |
project: "{{ gcp_project }}" |
| 37 |
auth_kind: "{{ gcp_cred_kind }}" |
| 38 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 39 |
state: absent |
| 40 |
|
| 41 |
- name: Create a metric |
| 42 |
google.cloud.gcp_logging_metric: |
| 43 |
name: "{{ resource_name }}" |
| 44 |
filter: resource.type=gae_app AND severity>=ERROR |
| 45 |
metric_descriptor: |
| 46 |
metric_kind: DELTA |
| 47 |
value_type: DISTRIBUTION |
| 48 |
unit: "1" |
| 49 |
labels: |
| 50 |
- key: mass |
| 51 |
value_type: STRING |
| 52 |
description: amount of matter |
| 53 |
value_extractor: EXTRACT(jsonPayload.request) |
| 54 |
label_extractors: |
| 55 |
mass: EXTRACT(jsonPayload.request) |
| 56 |
bucket_options: |
| 57 |
linear_buckets: |
| 58 |
num_finite_buckets: 3 |
| 59 |
width: 1 |
| 60 |
offset: 1 |
| 61 |
project: "{{ gcp_project }}" |
| 62 |
auth_kind: "{{ gcp_cred_kind }}" |
| 63 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 64 |
state: present |
| 65 |
register: result |
| 66 |
- name: Assert changed is true |
| 67 |
ansible.builtin.assert: |
| 68 |
that: |
| 69 |
- result.changed == true |
| 70 |
- name: Verify that metric was created |
| 71 |
google.cloud.gcp_logging_metric_info: |
| 72 |
project: "{{ gcp_project }}" |
| 73 |
auth_kind: "{{ gcp_cred_kind }}" |
| 74 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 75 |
scopes: |
| 76 |
- https://www.googleapis.com/auth/cloud-platform |
| 77 |
register: results |
| 78 |
- name: Verify that command succeeded |
| 79 |
ansible.builtin.assert: |
| 80 |
that: |
| 81 |
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 1 |
| 82 |
|
| 83 |
- name: Create a metric that already exists |
| 84 |
google.cloud.gcp_logging_metric: |
| 85 |
name: "{{ resource_name }}" |
| 86 |
filter: resource.type=gae_app AND severity>=ERROR |
| 87 |
metric_descriptor: |
| 88 |
metric_kind: DELTA |
| 89 |
value_type: DISTRIBUTION |
| 90 |
unit: "1" |
| 91 |
labels: |
| 92 |
- key: mass |
| 93 |
value_type: STRING |
| 94 |
description: amount of matter |
| 95 |
value_extractor: EXTRACT(jsonPayload.request) |
| 96 |
label_extractors: |
| 97 |
mass: EXTRACT(jsonPayload.request) |
| 98 |
bucket_options: |
| 99 |
linear_buckets: |
| 100 |
num_finite_buckets: 3 |
| 101 |
width: 1 |
| 102 |
offset: 1 |
| 103 |
project: "{{ gcp_project }}" |
| 104 |
auth_kind: "{{ gcp_cred_kind }}" |
| 105 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 106 |
state: present |
| 107 |
register: result |
| 108 |
- name: Assert changed is false |
| 109 |
ansible.builtin.assert: |
| 110 |
that: |
| 111 |
- result.changed == false |
| 112 |
|
| 113 |
- name: Delete a metric |
| 114 |
google.cloud.gcp_logging_metric: |
| 115 |
name: "{{ resource_name }}" |
| 116 |
filter: resource.type=gae_app AND severity>=ERROR |
| 117 |
metric_descriptor: |
| 118 |
metric_kind: DELTA |
| 119 |
value_type: DISTRIBUTION |
| 120 |
unit: "1" |
| 121 |
labels: |
| 122 |
- key: mass |
| 123 |
value_type: STRING |
| 124 |
description: amount of matter |
| 125 |
value_extractor: EXTRACT(jsonPayload.request) |
| 126 |
label_extractors: |
| 127 |
mass: EXTRACT(jsonPayload.request) |
| 128 |
bucket_options: |
| 129 |
linear_buckets: |
| 130 |
num_finite_buckets: 3 |
| 131 |
width: 1 |
| 132 |
offset: 1 |
| 133 |
project: "{{ gcp_project }}" |
| 134 |
auth_kind: "{{ gcp_cred_kind }}" |
| 135 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 136 |
state: absent |
| 137 |
register: result |
| 138 |
- name: Assert changed is true |
| 139 |
ansible.builtin.assert: |
| 140 |
that: |
| 141 |
- result.changed == true |
| 142 |
- name: Verify that metric was deleted |
| 143 |
google.cloud.gcp_logging_metric_info: |
| 144 |
project: "{{ gcp_project }}" |
| 145 |
auth_kind: "{{ gcp_cred_kind }}" |
| 146 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 147 |
scopes: |
| 148 |
- https://www.googleapis.com/auth/cloud-platform |
| 149 |
register: results |
| 150 |
- name: Verify that command succeeded |
| 151 |
ansible.builtin.assert: |
| 152 |
that: |
| 153 |
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 0 |
| 154 |
|
| 155 |
- name: Delete a metric that does not exist |
| 156 |
google.cloud.gcp_logging_metric: |
| 157 |
name: "{{ resource_name }}" |
| 158 |
filter: resource.type=gae_app AND severity>=ERROR |
| 159 |
metric_descriptor: |
| 160 |
metric_kind: DELTA |
| 161 |
value_type: DISTRIBUTION |
| 162 |
unit: "1" |
| 163 |
labels: |
| 164 |
- key: mass |
| 165 |
value_type: STRING |
| 166 |
description: amount of matter |
| 167 |
value_extractor: EXTRACT(jsonPayload.request) |
| 168 |
label_extractors: |
| 169 |
mass: EXTRACT(jsonPayload.request) |
| 170 |
bucket_options: |
| 171 |
linear_buckets: |
| 172 |
num_finite_buckets: 3 |
| 173 |
width: 1 |
| 174 |
offset: 1 |
| 175 |
project: "{{ gcp_project }}" |
| 176 |
auth_kind: "{{ gcp_cred_kind }}" |
| 177 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 178 |
state: absent |
| 179 |
register: result |
| 180 |
- name: Assert changed is false |
| 181 |
ansible.builtin.assert: |
| 182 |
that: |
| 183 |
- result.changed == false |