Skip to content
This repository was archived by the owner on Nov 2, 2024. It is now read-only.

Commit edb5f15

Browse files
committed
feat: Support configuration-based provisioning of Cloud Ops artifacts (part 1) (#1036)
Add schemas describing configuration for alerts, monitoring dashboards, log-based metrics, notification channels, SLOs and uptime checks. Follow JSON schema standard (draft 2020-12). Add validation checks including linting and schema validation. Setup `/configurations/test` configuration to validate schema. This configuration will be further used to validate Terraform execution plan. Constraint app-id field in all schemas to prevent path injection.
1 parent cbc8e5b commit edb5f15

File tree

17 files changed

+1249
-17
lines changed

17 files changed

+1249
-17
lines changed

.github/workflows/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ the use of the workflow as [required status check].
7070
It is configured to run on any "non-terraform" changes, so the required workflow will always
7171
guaranteed to terminate.
7272

73+
### Configurations workflow ([configurations.yaml])
74+
75+
The `configurations` checks correctness of the Sandbox configurations. It includes:
76+
77+
* yaml linting
78+
* validation of the configuration's yaml files vs. schema that is defined following JSON schema [draft2020]
79+
* json linting
80+
* testing configuration vs. expected terraform plan to make sure that all components are built using "right" provider and resource definitions
81+
7382
### Required workflows
7483

7584
The workflows triggered by pull request modifications (excluding a closure of the request)
@@ -114,3 +123,4 @@ For information about the customized workflow, see [workfows/README]
114123
[convention]: https://www.conventionalcommits.org/en/v1.0.0/
115124
[snippets]: https://github.com/googleapis/repo-automation-bots/tree/main/packages/snippet-bot
116125
[trusted contributors]: https://github.com/googleapis/repo-automation-bots/tree/main/packages/trusted-contribution
126+
[draft2020]: https://json-schema.org/draft/2020-12/release-notes.html

.github/workflows/cli.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# limitations under the License.
1414
name: CLI
1515

16+
concurrency:
17+
group: "cli-${{ github.workflow }}-${{ github.ref }}"
18+
cancel-in-progress: true
19+
1620
on:
1721
pull_request:
1822
types: [opened,synchronize,reopened]
@@ -23,9 +27,6 @@ jobs:
2327
runs-on: ubuntu-latest
2428
permissions:
2529
contents: read
26-
concurrency:
27-
group: ${{ github.workflow }}-${{ github.ref }}
28-
cancel-in-progress: true
2930

3031
steps:
3132
- name: Checkout source code
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Configurations
16+
17+
concurrency:
18+
group: "configurations-${{ github.workflow }}-${{ github.ref }}"
19+
cancel-in-progress: true
20+
21+
on:
22+
pull_request:
23+
types: [opened,synchronize,reopened]
24+
paths:
25+
- 'configurations/**/*.yaml'
26+
- 'provisioning/schemas/configuration/**/*.json'
27+
28+
29+
jobs:
30+
31+
validation:
32+
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
35+
36+
steps:
37+
- name: Checkout source code
38+
uses: actions/checkout@v3
39+
40+
- name: install ajv
41+
run: npm install -g ajv-cli
42+
43+
- name: Lint configurations
44+
run: find "${{ github.workspace }}/configurations" -mindepth 2 -maxdepth 2 -type f \( -name "*.yaml" -o -name "*.yml" \) -exec echo {} +
45+
46+
- name: Lint schemas
47+
run: echo "JSON liniting will be here"
48+
49+
- name: Schema validation
50+
run: |-
51+
cd "${{ github.workspace }}"
52+
for CONFIG_FILE in $(find configurations -mindepth 2 -maxdepth 2 -type f -name "*.yaml"); do
53+
FILENAME=$(basename -s ".yaml" "${CONFIG_FILE@L}")
54+
case "${FILENAME}" in
55+
alerts | dashboards | healthchecks | metrics | services | slos)
56+
;;
57+
*)
58+
echo "Unknown file ${CONFIG_FILE}" 1>&2
59+
continue
60+
;;
61+
esac
62+
ajv --spec=draft2020 -s "provisioning/schemas/configuration/${FILENAME}.json" -d "${CONFIG_FILE}"
63+
done
64+
65+
- name: Dry run
66+
run: echo "Validation of Terraform plan for test configuration will be here"

.github/workflows/non-terraform.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# limitations under the License.
1414
name: Terraform
1515

16+
concurrency:
17+
group: "terraform-${{ github.workflow }}-${{ github.ref }}"
18+
cancel-in-progress: true
19+
1620
on:
1721
pull_request:
1822
types: [opened,synchronize,reopened]
@@ -21,13 +25,10 @@ on:
2125

2226

2327
jobs:
24-
tflint:
28+
validation:
2529
runs-on: ubuntu-latest
2630
permissions:
2731
contents: read
28-
concurrency:
29-
group: ${{ github.workflow }}-${{ github.ref }}
30-
cancel-in-progress: true
3132

3233
steps:
3334
- run: 'echo "No work to do for non-terraform changes"'
@@ -37,9 +38,6 @@ jobs:
3738
runs-on: ubuntu-latest
3839
permissions:
3940
contents: read
40-
concurrency:
41-
group: ${{ github.workflow }}-${{ github.ref }}
42-
cancel-in-progress: true
4341

4442
steps:
4543
- run: 'echo "No work to do for non-terraform changes"'

.github/workflows/terraform.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# limitations under the License.
1414
name: Terraform
1515

16+
concurrency:
17+
group: "terraform-${{ github.workflow }}-${{ github.ref }}"
18+
cancel-in-progress: true
19+
1620
on:
1721
pull_request:
1822
types: [opened,synchronize,reopened]
@@ -22,13 +26,10 @@ on:
2226

2327
jobs:
2428

25-
tflint:
29+
validation:
2630
runs-on: ubuntu-latest
2731
permissions:
2832
contents: read
29-
concurrency:
30-
group: ${{ github.workflow }}-${{ github.ref }}
31-
cancel-in-progress: true
3233

3334
steps:
3435
- name: Checkout source code
@@ -69,9 +70,6 @@ jobs:
6970
permissions:
7071
contents: 'read'
7172
id-token: 'write'
72-
concurrency:
73-
group: ${{ github.workflow }}-${{ github.ref }}
74-
cancel-in-progress: true
7573

7674
steps:
7775
- name: Checkout source code

configurations/test/alerts.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
app-id: "test"
16+
version: "0.0.1"
17+
alerts:
18+
- name: test-alert-with-notifications
19+
display-name: "Test alert with notification channel"
20+
documentation: "Lorem ipsum Lorem ipsum Lorem ipsum"
21+
notification-channels: [sms-test-channel, pubsub-test-channel]
22+
conditions:
23+
- display-name: "test condition 1"
24+
condition:
25+
filter: "metric.type=\"monitoring.googleapis.com/uptime_check/check_passed\""
26+
threshold: 3
27+
duration: "300s"
28+
comparison: "COMPARISON_GT"
29+
channels:
30+
- name: sms-test-channel
31+
display-name: "SMS test channel"
32+
channel:
33+
type: sms
34+
labels:
35+
number: "1234567890"
36+
- name: email-test-channel
37+
display-name: "E-mail test channel"
38+
channel:
39+
type: email
40+
labels:
41+
email_address: "[email protected]"
42+
- name: pubsub-test-channel
43+
display-name: "PubSub test channel"
44+
channel:
45+
type: pubsub
46+
labels:
47+
topic: "projects/unknown/topics/unknown"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
app-id: "test"
16+
version: "0.0.1"
17+
dashboards:
18+
- name: test-dashboard-1
19+
display-name: "Test Dashboard 1"
20+
widgets:
21+
- title: "CPU Usage"
22+
x-axis-label: "Time"
23+
y-axis-label: "%"
24+
datasets:
25+
- time-series:
26+
filter:
27+
query: "metric.type=\"compute.googleapis.com/instance/cpu/usage_time\" resource.type=\"gce_instance\""
28+
alignment: ALIGN_PERCENTILE_99
29+
unit-override: "cpu"
30+
31+
min-alignment-period: "60s"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
app-id: "test"
16+
version: "0.0.1"
17+
checks:
18+
- name: test-uptime-alert-1
19+
display-name: "HTTP uptime check"
20+
timeout: 10
21+
resource:
22+
type: k8s_service
23+
labels:
24+
cluster_name: "test-cluster-1"
25+
content:
26+
content: "ok"
27+
matcher: CONTAINS_STRING
28+
type:
29+
request-method: "GET"
30+
path: "/healtz"
31+
port: 8008
32+

configurations/test/metrics.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
app-id: "test"
16+
version: "0.0.1"
17+
metrics:
18+
- name: test-log-metric-1
19+
description: "Count audit resources"
20+
filter: "resource.type=\"audited_resource\""
21+
labels:
22+
- key: resource
23+
extractor: "EXTRACT(resource.type)"
24+
- key: project
25+
extractor: "EXTRACT(resource.labels.project_id)"

configurations/test/services.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
app-id: "test"
16+
version: "0.0.1"
17+
services:
18+
- name: custom-test-service-1
19+
display-name: "Custom service 1"
20+
labels:
21+
abc1: value1
22+
abc2: value2
23+
- name: custom-test-service-2
24+
display-name: "Custom service 2"
25+
basic-service:
26+
service-type: CLOUD_ENDPOINTS
27+
labels:
28+
endpoint1: value1
29+
endpoint2: value2
30+
labels:
31+
bce1: value1
32+
bce2: value2

0 commit comments

Comments
 (0)