Skip to content

Commit

Permalink
Add jsonschema for configs
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrik committed Oct 25, 2023
1 parent cb58665 commit 20ff770
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 105 additions & 0 deletions .vscode/config-schema.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"yaml.schemas": {
".vscode/config-schema.yaml": [
"examples/*.yaml"
]
}
}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions scripts/jsonschema.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 20ff770

Please sign in to comment.