diff --git a/.github/workflows/configurations.yaml b/.github/workflows/configurations.yaml index 87ad0a9c5..a31776e78 100644 --- a/.github/workflows/configurations.yaml +++ b/.github/workflows/configurations.yaml @@ -22,12 +22,13 @@ on: pull_request: types: [opened,synchronize,reopened] paths: - - 'applications/**/*.yaml' + - 'configurations/**/*.yaml' + - 'provisioning/schemas/configuration/**/*.json' jobs: - yamllint: + ci: runs-on: ubuntu-latest permissions: contents: read @@ -35,6 +36,36 @@ jobs: steps: - name: Checkout source code uses: actions/checkout@v3 - - - name: Check CLI script - run: yamllint configurations/**/*.yaml configurations/**/*.yml + + - name: install ajv + run: npm install ajv-cli + + - name: Lint configurations + run: |- + cd "${{ github.workspace }}" + CONFIG_FILES=$(find configurations -mindepth 2 -maxdepth 2 -type f \( -name "*.yaml" -o -name "*.yml" \)) + if [[ -n "$CONFIG_FILES" ]]; then + yamllint configurations/**/*.yaml configurations/**/*.yml + fi + + - name: Lint schemas + run: echo "JSON liniting will be here" + + - name: Schema validation + run: |- + cd "${{ github.workspace }}" + for CONFIG_FILE in $(find configurations -mindepth 2 -maxdepth 2 -type f -name "*.yaml"); do + FILENAME=$(basename -s '.yaml' "${CONFIG_FILE@L}") + case "${FILENAME}" in + alerts | dashboards | healthchecks | metrics | services | slos) + ;; + *) + echo "Unknown file "${CONFIG_FILE}" 1>&2 + continue + ;; + esac + ajv --spec=draft2020 -s "provisioning/schemas/configuration/${FILENAME}.json" -d "${CONFIG_FILE}" + done + + - name: Dry run + run: echo "Validation of Terraform plan for test configuration will be here" diff --git a/provisioning/configurations/schemas/notification_channel.json b/provisioning/configurations/schemas/notification_channel.json deleted file mode 100644 index f3e6684ec..000000000 --- a/provisioning/configurations/schemas/notification_channel.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "$id": "https://github.com/GoogleCloudPlatform/cloud-ops-sandbox/provisioning/schemas/notification_channel.json", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Notification Channel schema", - "type": "object", - "required": [ - "app-id", - "version", - "channels" - ], - "properties": { - "app-id": { - "type": "string", - "description": "Unique identifier of the application" - }, - "version": { - "const": "0.0.1", - "description": "Schema version" - }, - "channels": { - "type": "array", - "description": "A collection of notification channels", - "items": { - "$ref": "#/$defs/channel" - } - } - }, - "$defs": { - "channel": { - "type": "object", - "description": "", - "required": [ - "name", - "type", - "labels" - ], - "properties": { - "name": { - "type": "string", - "description": "A unique resource name for this notification channel", - "maxLength": 30 - }, - "display-name": { - "type": "string", - "description": "A human-readable name for this notification channel", - "maxLength": 512 - }, - "type": { - "enum": [ - "email", - "pubsub", - "sms" - ], - "description": "Supports sending notifications to email, PubSub and SMS" - }, - "labels": { - "description": "Configuration fields that define the channel and its behavior for one of:", - "anyOf": [ - { - "$ref": "#/$defs/emailLabels" - }, - { - "$ref": "#/$defs/pubsubLabels" - }, - { - "$ref": "#/$defs/smsLabels" - } - ] - } - } - }, - "emailLabels": { - "type": "object", - "description": "Configuration for email notification channel", - "required": [ - "email_address" - ], - "properties": { - "email_address": { - "type": "string", - "description": "An address to send email" - } - } - }, - "pubsubLabels": { - "type": "object", - "description": "Configuration for PubSub notification channel", - "required": [ - "topic" - ], - "properties": { - "topic": { - "type": "string", - "description": "A fully qualified resource name of the Pub/Sub topic to post notifications" - } - } - }, - "smsLabels": { - "type": "object", - "description": "Configuration for SMS notification channel", - "required": [ - "number" - ], - "properties": { - "number": { - "type": "string", - "describing": "A phone number to text notifications" - } - } - } - } -} \ No newline at end of file diff --git a/provisioning/configurations/schemas/alert.json b/provisioning/schemas/configuration/alerts.json similarity index 59% rename from provisioning/configurations/schemas/alert.json rename to provisioning/schemas/configuration/alerts.json index 4b1a296e9..7ee4bce65 100644 --- a/provisioning/configurations/schemas/alert.json +++ b/provisioning/schemas/configuration/alerts.json @@ -1,7 +1,6 @@ { - "$id": "https://github.com/GoogleCloudPlatform/cloud-ops-sandbox/provisioning/schemas/alert.json", "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Monitoring alert schema", + "title": "Monitoring alerts and notification channels schema", "type": "object", "required": [ "app-id", @@ -19,10 +18,17 @@ }, "alerts": { "type": "array", - "description": "A collection of alerts", + "description": "A collection of alert policy definitions", "items": { "$ref": "#/$defs/alert" } + }, + "channels": { + "type": "array", + "description": "A collection of notification channel definitions", + "items": { + "$ref": "#/$defs/channel" + } } }, "$defs": { @@ -67,6 +73,49 @@ } } }, + "channel": { + "type": "object", + "description": "", + "required": [ + "name", + "type", + "labels" + ], + "properties": { + "name": { + "type": "string", + "description": "A unique resource name for this notification channel", + "maxLength": 30 + }, + "display-name": { + "type": "string", + "description": "A human-readable name for this notification channel", + "maxLength": 512 + }, + "type": { + "enum": [ + "email", + "pubsub", + "sms" + ], + "description": "Supports sending notifications to email, PubSub and SMS" + }, + "labels": { + "description": "Configuration fields that define the channel and its behavior for one of:", + "anyOf": [ + { + "$ref": "#/$defs/emailLabels" + }, + { + "$ref": "#/$defs/pubsubLabels" + }, + { + "$ref": "#/$defs/smsLabels" + } + ] + } + } + }, "condition": { "type": "object", "description": "A true/false test that determines when an alerting policy should open an incident", @@ -130,6 +179,45 @@ }, "conditionAbsent": {}, "conditionMatchedLog": {}, - "conditionMonitoringQueryLanguage": {} + "conditionMonitoringQueryLanguage": {}, + "emailLabels": { + "type": "object", + "description": "Configuration for email notification channel", + "required": [ + "email_address" + ], + "properties": { + "email_address": { + "type": "string", + "description": "An address to send email" + } + } + }, + "pubsubLabels": { + "type": "object", + "description": "Configuration for PubSub notification channel", + "required": [ + "topic" + ], + "properties": { + "topic": { + "type": "string", + "description": "A fully qualified resource name of the Pub/Sub topic to post notifications" + } + } + }, + "smsLabels": { + "type": "object", + "description": "Configuration for SMS notification channel", + "required": [ + "number" + ], + "properties": { + "number": { + "type": "string", + "describing": "A phone number to text notifications" + } + } + } } } \ No newline at end of file diff --git a/provisioning/configurations/schemas/dashboard.json b/provisioning/schemas/configuration/dashboards.json similarity index 98% rename from provisioning/configurations/schemas/dashboard.json rename to provisioning/schemas/configuration/dashboards.json index 53dcc0cdd..67e4f7ec7 100644 --- a/provisioning/configurations/schemas/dashboard.json +++ b/provisioning/schemas/configuration/dashboards.json @@ -1,5 +1,4 @@ { - "$id": "https://github.com/GoogleCloudPlatform/cloud-ops-sandbox/provisioning/schemas/dashboard.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Monitoring dashboard schema", "type": "object", diff --git a/provisioning/configurations/schemas/uptime_check.json b/provisioning/schemas/configuration/healthchecks.json similarity index 98% rename from provisioning/configurations/schemas/uptime_check.json rename to provisioning/schemas/configuration/healthchecks.json index 6cac7980e..8db3ac84a 100644 --- a/provisioning/configurations/schemas/uptime_check.json +++ b/provisioning/schemas/configuration/healthchecks.json @@ -1,5 +1,4 @@ { - "$id": "https://github.com/GoogleCloudPlatform/cloud-ops-sandbox/provisioning/schemas/uptime_check.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Uptime check schema", "type": "object", diff --git a/provisioning/configurations/schemas/log_based_metric.json b/provisioning/schemas/configuration/metrics.json similarity index 97% rename from provisioning/configurations/schemas/log_based_metric.json rename to provisioning/schemas/configuration/metrics.json index 84a54b4af..046c4544c 100644 --- a/provisioning/configurations/schemas/log_based_metric.json +++ b/provisioning/schemas/configuration/metrics.json @@ -1,5 +1,4 @@ { - "$id": "https://github.com/GoogleCloudPlatform/cloud-ops-sandbox/provisioning/schemas/log_based_metric.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Log-based metric schema", "type": "object", diff --git a/provisioning/configurations/schemas/slo.json b/provisioning/schemas/configuration/slos.json similarity index 98% rename from provisioning/configurations/schemas/slo.json rename to provisioning/schemas/configuration/slos.json index 43678cc94..825197acc 100644 --- a/provisioning/configurations/schemas/slo.json +++ b/provisioning/schemas/configuration/slos.json @@ -1,5 +1,4 @@ { - "$id": "https://github.com/GoogleCloudPlatform/cloud-ops-sandbox/provisioning/schemas/slo.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Service's SLO schema", "type": "object",