diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86fd930d..046d98b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -371,6 +371,21 @@ jobs: - name: Run clang-format check run: make clang-format-check + jsonschema: + name: Run jsonschema checks + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Install jsonschema dependencies + run: sudo apt-get install -y python3-jsonschema make + + - name: Install yq + run: sudo curl -Lo /usr/bin/yq https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64 && sudo chmod +x /usr/bin/yq + + - name: Run jsonschema check + run: make jsonschema + publish-docker-images: name: Publish Docker images (x86_64, aarch64) runs-on: ubuntu-22.04 diff --git a/.vscode/config-schema.yaml b/.vscode/config-schema.yaml new file mode 100644 index 00000000..39baf7d9 --- /dev/null +++ b/.vscode/config-schema.yaml @@ -0,0 +1,105 @@ +title: ebpf_exporter config schema +$schema: https://json-schema.org/draft/2020-12/schema +type: object +additionalProperties: false +properties: + metrics: + type: object + additionalProperties: false + anyOf: + - required: + - counters + - required: + - histograms + properties: + counters: + type: array + items: + type: object + additionalProperties: false + required: + - name + - help + properties: + name: + type: string + help: + type: string + perf_event_array: + type: boolean + flush_interval: + type: string + labels: + $ref: "#/definitions/labels" + histograms: + type: array + items: + type: object + additionalProperties: false + required: + - name + - help + - bucket_type + - bucket_min + - bucket_max + - labels + properties: + name: + type: string + help: + type: string + bucket_type: + enum: + - exp2 + - exp2zero + - linear + - fixed + bucket_multiplier: + type: number + bucket_min: + type: number + bucket_max: + type: number + bucket_keys: + type: array + items: + type: number + labels: + $ref: "#/definitions/labels" + kaddrs: + type: array + items: + type: string +definitions: + labels: + type: array + items: + type: object + additionalProperties: false + required: + - name + - size + - decoders + properties: + name: + type: string + size: + type: number + decoders: + type: array + items: + type: object + additionalProperties: false + required: + - name + properties: + name: + type: string + static_map: + type: object + allow_unknown: + type: boolean + regexps: + type: array + items: + type: string diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..12c2c509 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "yaml.schemas": { + ".vscode/config-schema.yaml": [ + "examples/*.yaml" + ] + } +} diff --git a/Makefile b/Makefile index f8bcfe15..f40e8d42 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,10 @@ lint: go mod verify golangci-lint run ./... +.PHONY: jsonschema +jsonschema: + ./scripts/jsonschema.sh + .PHONY: clang-format-check clang-format-check: clang-format --dry-run --verbose -Werror $(CLANG_FORMAT_FILES) diff --git a/scripts/jsonschema.sh b/scripts/jsonschema.sh new file mode 100755 index 00000000..4b159a6d --- /dev/null +++ b/scripts/jsonschema.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -xeuo pipefail + +exit_status=0 + +for example in examples/*.yaml; do + echo "Checking ${example}..." + ret=$(jsonschema --instance <(yq --output-format=json < $example) <(yq --output-format=json < .vscode/config-schema.yaml); echo $?) + if [ "${ret}" != 0 ]; then + exit_status=$ret + fi +done + +exit "${exit_status}"