Skip to content

Commit 9c8ff31

Browse files
authored
Project tooling to generate example property descriptions (#104)
* Project tooling to generate example property descriptions * Exclude type_descriptions from ajv-cli * Fix generate-comments when value is null * validate-examples after generate-descriptions * Generate descriptions and check for diff in build * maybeDebugLog -> debug * Add type descriptions for new types * Skip copying type_descriptions.yaml in make validator-copy-schema * Update type_descriptions.yaml with stream include/exclude
1 parent e21ffdb commit 9c8ff31

File tree

11 files changed

+834
-260
lines changed

11 files changed

+834
-260
lines changed

.github/workflows/build-check.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,21 @@ jobs:
2121

2222
- name: validate example
2323
run: make validate-examples
24+
25+
- name: generate descriptions
26+
run: make generate-descriptions
27+
28+
- name: check for diff
29+
run: |
30+
# need to "git add" to detect any changes to descriptions which are not checked in
31+
# select files from both /examples
32+
git add examples**
33+
if git diff --cached --quiet
34+
then
35+
echo "No diff detected."
36+
else
37+
echo "Diff detected - did you run 'make generate-descriptions'?"
38+
echo $(git diff --cached --name-only)
39+
echo $(git diff --cached)
40+
exit 1
41+
fi

CONTRIBUTING.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,67 @@ You can perform all checks locally using this command:
2727
make all
2828
```
2929

30+
## Description generation
31+
32+
The [./examples](./examples) directory contains a variety of examples, which
33+
include important comments describing the semantics of the configuration
34+
properties. In order to keep these comments consistent across examples, we have
35+
tooling which automatically generates comments for each property.
36+
37+
How it works:
38+
39+
* The [./schema/type_descriptions.yaml](./schema/type_descriptions.yaml) file
40+
defines descriptions for each of the properties of each type defines in
41+
the [JSON schema](./schema) data model.
42+
* The [./scripts/generate-descriptions.js](./scripts/generate-comments.js) is a
43+
script which for a given input configuration file will:
44+
* Parse the YAML.
45+
* Walk through each key / value pair, and for each:
46+
* Compute the JSON dot notation location of the current key / value pair.
47+
* Find the first matching rule
48+
in [type_description.yaml](./schema/type_descriptions.yaml). Iterate
49+
through the rules and evaluate the key / value pair dot notation location
50+
against each of the rule's `path_patterns`.
51+
* Inject / overwrite comments for its properties according
52+
to `type_descriptions.yaml`.
53+
* Write the resulting content to specified output file or to the console.
54+
55+
The `make generate-descriptions` command runs this process against each file
56+
in `./examples` and overwrites each file in the process.
57+
58+
**NOTE:** The [build](./.github/workflows/build-check.yaml) will fail
59+
if `make generate-descriptions` produces any changes which are not checked into
60+
version control.
61+
62+
To run against a single file:
63+
64+
- Install the latest LTS release of **[Node](https://nodejs.org/)**.
65+
For example, using **[nvm][]** under Linux run:
66+
67+
```bash
68+
nvm install --lts
69+
```
70+
71+
- Install tooling packages:
72+
73+
```bash
74+
npm install
75+
```
76+
77+
- Run the script:
78+
79+
```shell
80+
npm run-script generate-descriptions -- /absolute/path/to/input/file.yaml /absolute/path/to/output/file.yaml
81+
```
82+
83+
Optionally, include the `--debug` parameter. This prints out information about
84+
each key value pair, including the computed dot notation location, the matched
85+
rule, the previous description, the new description, etc.
86+
87+
```shell
88+
npm run-script generate-comments -- /absolute/path/to/input/file.yaml /absolute/path/to/output/file.yaml --debug
89+
```
90+
3091
## Pull requests
3192

3293
A PR is ready to merge when:

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ EXAMPLE_FILES := $(shell find . -path './examples/*.yaml' -exec basename {} \; |
33
$(shell mkdir -p out)
44

55
.PHONY: all
6-
all: install-tools compile-schema validate-examples
6+
all: install-tools compile-schema generate-descriptions validate-examples
77

88
include validator/Makefile
99

1010
.PHONY: compile-schema
1111
compile-schema:
1212
@if ! npm ls ajv-cli; then npm install; fi
1313
@for f in $(SCHEMA_FILES); do \
14-
npx --no ajv-cli compile --spec=draft2020 --allow-matching-properties -s ./schema/$$f -r "./schema/!($$f)" \
14+
npx --no ajv-cli compile --spec=draft2020 --allow-matching-properties -s ./schema/$$f -r "./schema/!($$f|*.yaml)" \
1515
|| exit 1; \
1616
done
1717

@@ -20,10 +20,17 @@ validate-examples:
2020
@if ! npm ls ajv-cli; then npm install; fi
2121
@for f in $(EXAMPLE_FILES); do \
2222
npx envsub ./examples/$$f ./out/$$f || exit 1; \
23-
npx --no ajv-cli validate --spec=draft2020 --allow-matching-properties --errors=text -s ./schema/opentelemetry_configuration.json -r "./schema/!(opentelemetry_configuration.json)" -d ./out/$$f \
23+
npx --no ajv-cli validate --spec=draft2020 --allow-matching-properties --errors=text -s ./schema/opentelemetry_configuration.json -r "./schema/!(opentelemetry_configuration.json|*.yaml)" -d ./out/$$f \
2424
|| exit 1; \
2525
done
2626

27+
.PHONY: generate-descriptions
28+
generate-descriptions:
29+
@if ! npm ls minimatch yaml; then npm install; fi
30+
@for f in $(EXAMPLE_FILES); do \
31+
npm run-script generate-descriptions -- $(shell pwd)/examples/$$f $(shell pwd)/examples/$$f || exit 1; \
32+
done
33+
2734
.PHONY: install-tools
2835
install-tools:
2936
npm install

examples/anchors.yaml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# anchors.yaml demonstrates anchor substitution to reuse OTLP exporter configuration across signals.
22

3+
# The file format version.
34
file_format: "0.1"
45
exporters:
56
otlp: &otlp-exporter
@@ -13,33 +14,52 @@ exporters:
1314
compression: gzip
1415
timeout: 10000
1516

17+
# Configure logger provider.
1618
logger_provider:
19+
# Configure log record processors.
1720
processors:
18-
- batch:
21+
- # Configure a batch log record processor.
22+
batch:
23+
# Configure exporter.
1924
exporter:
25+
# Configure exporter to be OTLP.
2026
otlp:
21-
# expand the otlp-exporter anchor
2227
<<: *otlp-exporter
28+
# Configure endpoint.
2329
endpoint: http://localhost:4318/v1/logs
2430

31+
# Configure meter provider.
2532
meter_provider:
33+
# Configure metric readers.
2634
readers:
27-
- periodic:
35+
- # Configure a periodic metric reader.
36+
periodic:
37+
# Configure delay interval (in milliseconds) between start of two consecutive exports.
2838
interval: 5000
39+
# Configure maximum allowed time (in milliseconds) to export data.
2940
timeout: 30000
41+
# Configure exporter.
3042
exporter:
43+
# Configure exporter to be OTLP.
3144
otlp:
32-
# expand the otlp-exporter anchor and add metric specific configuration
3345
<<: *otlp-exporter
46+
# Configure endpoint.
3447
endpoint: http://localhost:4318/v1/metrics
48+
# Configure temporality preference.
3549
temporality_preference: delta
50+
# Configure default histogram aggregation.
3651
default_histogram_aggregation: base2_exponential_bucket_histogram
3752

53+
# Configure tracer provider.
3854
tracer_provider:
55+
# Configure span processors.
3956
processors:
40-
- batch:
57+
- # Configure a batch span processor.
58+
batch:
59+
# Configure exporter.
4160
exporter:
61+
# Configure exporter to be OTLP.
4262
otlp:
43-
# expand the otlp-exporter anchor
4463
<<: *otlp-exporter
64+
# Configure endpoint.
4565
endpoint: http://localhost:4318/v1/traces

0 commit comments

Comments
 (0)