Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate collector semconv codegen to weaver #11064

Closed
wants to merge 13 commits into from
33 changes: 26 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,34 @@ genpdata:
$(GOCMD) run pdata/internal/cmd/pdatagen/main.go
$(MAKE) fmt

# Definitions for semconvgen
DOCKER_USER=$(shell id -u):$(shell id -g)
# TODO - Pull docker image versions from rennovate-friendly source, e.g.
# $(shell cat dependencies.Dockerfile | awk '$$4=="weaver" {print $$2}')
WEAVER_CONTAINER=otel/weaver:v0.9.1


# Generate semantic convention constants. Requires a clone of the opentelemetry-specification repo
gensemconv: $(SEMCONVGEN) $(SEMCONVKIT)
@[ "${SPECPATH}" ] || ( echo ">> env var SPECPATH is not set"; exit 1 )
gensemconv: $(SEMCONVKIT)
@[ "${SPECTAG}" ] || ( echo ">> env var SPECTAG is not set"; exit 1 )
@echo "Generating semantic convention constants from specification version ${SPECTAG} at ${SPECPATH}"
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=resource -p conventionType=resource -f generated_resource.go
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=event -p conventionType=event -f generated_event.go
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=span -p conventionType=trace -f generated_trace.go
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=attribute_group -p conventionType=attribute_group -f generated_attribute_group.go
@echo "Generating semantic convention constants from specification version ${SPECTAG} at https://github.com/open-telemetry/semantic-conventions.git@${SPECTAG}"
# Ensure the target directory for source code is available.
mkdir -p $(PWD)/semconv/${SPECTAG}
# Note: We mount a home directory for downloading/storing the semconv repository.
# Weaver will automatically clean the cache when finished, but the directories will remain.
mkdir -p ~/.weaver
docker run --rm \
-u $(DOCKER_USER) \
--env HOME=/tmp/weaver \
--mount 'type=bind,source=$(PWD)/semconv/weaver,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=$(HOME)/.weaver,target=/tmp/weaver/.weaver' \
--mount 'type=bind,source=$(PWD)/semconv/${SPECTAG},target=/home/weaver/target' \
$(WEAVER_CONTAINER) registry generate \
--registry=https://github.com/open-telemetry/semantic-conventions.git@$(SPECTAG)#model \
--templates=/home/weaver/templates \
collector \
/home/weaver/target
# TODO: we should gofmt the result of running weaver.
$(SEMCONVKIT) -output "semconv/$(SPECTAG)" -tag "$(SPECTAG)"

# Checks that the HEAD of the contrib repo checked out in CONTRIB_PATH compiles
Expand Down
31 changes: 24 additions & 7 deletions semconv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,31 @@ from definitions in the specification.

## Generation

To generate the constants you can use the `gensemconv` make target. You must provide the path to the root of a clone of
the `semantic-conventions` repository in the `SPECPATH` variable and the version of the conventions to generate
To generate the constants you can use the `gensemconv` make target. You must provide the version of the conventions to generate
in the `SPECTAG` variable.

```console
$ make gensemconv SPECPATH=/tmp/semantic-conventions SPECTAG=v1.22.0
Generating semantic convention constants from specification version v1.22.0 at /tmp/semantic-conventions
.tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=resource -p conventionType=resource -f generated_resource.go
.tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=event -p conventionType=event -f generated_event.go
.tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=span -p conventionType=trace -f generated_trace.go
$ make gensemconv SPECTAG=v1.22.0
Generating semantic convention constants from specification version v1.27.0 at https://github.com/open-telemetry/[email protected]
mkdir -p /home/joshuasuereth/src/open-telemetry/opentelemetry-collector/semconv/v1.27.0
mkdir -p ~/.weaver
docker run --rm \
-u 110055:89939 \
--env HOME=/tmp/weaver \
--mount 'type=bind,source=/home/joshuasuereth/src/open-telemetry/opentelemetry-collector/semconv/weaver,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=/home/joshuasuereth/.weaver,target=/tmp/weaver/.weaver' \
--mount 'type=bind,source=/home/joshuasuereth/src/open-telemetry/opentelemetry-collector/semconv/v1.27.0,target=/home/weaver/target' \
otel/weaver:v0.9.1 registry generate \
--registry=https://github.com/open-telemetry/[email protected]#model \
--templates=/home/weaver/templates \
collector \
/home/weaver/target
✔ `main` semconv registry `https://github.com/open-telemetry/[email protected]#model[model]` loaded (160 files)
✔ No `before_resolution` policy violation
✔ `default` semconv registry resolved
✔ Generated file "/home/weaver/target/generated_resource.go"
✔ Generated file "/home/weaver/target/generated_event.go"
✔ Generated file "/home/weaver/target/generated_trace.go"
✔ Generated file "/home/weaver/target/generated_attribute_group.go"
✔ Artifacts generated successfully
```
2 changes: 1 addition & 1 deletion semconv/semconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAllSemConvFilesAreCrated(t *testing.T) {
assert.NoError(t, err)

for _, f := range files {
if !f.IsDir() {
if !f.IsDir() || f.Name() == "weaver" {
continue
}

Expand Down
81 changes: 0 additions & 81 deletions semconv/template.j2

This file was deleted.

Loading
Loading