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

[config] introduce config package #4376

Merged
merged 7 commits into from Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Expand Up @@ -109,6 +109,15 @@ updates:
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /config
labels:
- dependencies
- go
- Skip Changelog
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /detectors/aws/ec2
labels:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108)
- Add `"go.opentelemetry.io/contrib/samplers/jaegerremote".WithSamplingStrategyFetcher` which sets custom fetcher implementation. (#4045)
- Add `"go.opentelemetry.io/contrib/config"` package that includes configuration models generated via go-jsonschema (#4376)

### Changed

Expand Down
33 changes: 33 additions & 0 deletions Makefile
Expand Up @@ -74,6 +74,9 @@ $(GOTMPL): PACKAGE=go.opentelemetry.io/build-tools/gotmpl
GORELEASE = $(TOOLS)/gorelease
$(GORELEASE): PACKAGE=golang.org/x/exp/cmd/gorelease

GOJSONSCHEMA = $(TOOLS)/go-jsonschema
$(GOJSONSCHEMA): PACKAGE=github.com/atombender/go-jsonschema

tools: $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(PORTO) $(MULTIMOD) $(DBOTCONF) $(CROSSLINK) $(GOTMPL) $(GORELEASE)

# Generate
Expand Down Expand Up @@ -283,3 +286,33 @@ COMMIT ?= "HEAD"
add-tags: | $(MULTIMOD)
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
$(MULTIMOD) verify && $(MULTIMOD) tag -m ${MODSET} -c ${COMMIT}

# The source directory for opentelemetry-configuration schema.
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR=tmp/opentelememetry-configuration

# The SHA matching the current version of the opentelemetry-configuration schema to use
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION=v0.1.0

# Cleanup temporary directory
genjsonschema-cleanup:
rm -Rf ${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR}

GENERATED_CONFIG=./config/generated_config.go

# Generate structs for configuration from opentelemetry-configuration schema
genjsonschema: genjsonschema-cleanup $(GOJSONSCHEMA)
mkdir -p ${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR}
curl -sSL https://api.github.com/repos/open-telemetry/opentelemetry-configuration/tarball/${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION} | tar xz --strip 1 -C ${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR}
$(GOJSONSCHEMA) \
--capitalization ID \
--capitalization OTLP \
--struct-name-from-title \
--package config \
pellared marked this conversation as resolved.
Show resolved Hide resolved
--tags mapstructure \
--output ${GENERATED_CONFIG} \
${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR}/schema/opentelemetry_configuration.json
@echo Modify jsonschema generated files.
sed -f ./config/jsonschema_patch.sed ${GENERATED_CONFIG} > ${GENERATED_CONFIG}.tmp
mv ${GENERATED_CONFIG}.tmp ${GENERATED_CONFIG}
$(MAKE) lint
$(MAKE) genjsonschema-cleanup
31 changes: 31 additions & 0 deletions config/README.md
@@ -0,0 +1,31 @@
# Configuration Library

This package can be used to parse a configuration file that follows the JSON
Schema defined by the [OpenTelemetry Configuration] schema.

The package contains:

- models generated via the JSON schema using the [go-jsonschema] library
- a `Create` function that interprets [configuration model] and return SDK components (TODO)
- a `Parse` function that parses and validates a [configuration file] (TODO)
pellared marked this conversation as resolved.
Show resolved Hide resolved

## Using the generate model code

The `generated_config.go` code in versioned submodule can be used directly as-is to programmatically
produce a configuration model that can be then used as a parameter to the `Create` function. Note
pellared marked this conversation as resolved.
Show resolved Hide resolved
that the package is versioned to match the release versioning of the opentelemetry-configuration
repository.

## Using the `Create` function (TODO)

## Using the `Parse` function (TODO)

The original code from the package comes from the [OpenTelemetry Collector's service] telemetry
configuration code. The intent being to share this code across implementations and reduce
duplication where possible.

[OpenTelemetry Configuration]: https://github.com/open-telemetry/opentelemetry-configuration/
[go-jsonschema]: https://github.com/omissis/go-jsonschema
[configuration model]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/file-configuration.md#configuration-model
[configuration file]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/file-configuration.md#configuration-file
[OpenTelemetry Collector's service]: https://github.com/open-telemetry/opentelemetry-collector/blob/7c5ecef11dff4ce5501c9683b277a25a61ea0f1a/service/telemetry/generated_config.go