Skip to content

Commit

Permalink
add genjsonschema makefile target & remove collector dep
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
Alex Boten committed Sep 27, 2023
1 parent fd1a2ae commit ecc8594
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 306 deletions.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
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/cmd/gojsonschema

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

# Generate
Expand Down Expand Up @@ -283,3 +286,31 @@ 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=main

# 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) \
--package config \
--tags mapstructure \
--output ${GENERATED_CONFIG} \
--schema-package=https://opentelemetry.io/otelconfig/opentelemetry_configuration.json=github.com/open-telemetry/opentelemetry-collector/schema \
${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
72 changes: 26 additions & 46 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,137 +5,117 @@ package config // import "go.opentelemetry.io/contrib/config"

import (
"fmt"

"go.opentelemetry.io/collector/confmap"
)

func (sp *SpanProcessor) Unmarshal(conf *confmap.Conf) error {
if conf == nil {
return nil
}

if err := conf.Unmarshal(sp); err != nil {
return fmt.Errorf("invalid span processor configuration: %w", err)
}

// Validate checks for a valid batch processor for the SpanProcessor.
func (sp *SpanProcessor) Validate() error {
if sp.Batch != nil {
return sp.Batch.Exporter.Validate()
}
return fmt.Errorf("unsupported span processor type %s", conf.AllKeys())
return fmt.Errorf("unsupported span processor type")
}

// Validate checks for valid exporters to be configured for the SpanExporter
// Validate checks for valid exporters to be configured for the SpanExporter.
func (se *SpanExporter) Validate() error {
if se.Console == nil && se.Otlp == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
}

func (mr *MetricReader) Unmarshal(conf *confmap.Conf) error {
if conf == nil {
return nil
}

if err := conf.Unmarshal(mr); err != nil {
return fmt.Errorf("invalid metric reader configuration: %w", err)
}

// Validate checks for either a valid pull or periodic exporter for the MetricReader.
func (mr *MetricReader) Validate() error {
if mr.Pull != nil {
return mr.Pull.Validate()
}
if mr.Periodic != nil {
return mr.Periodic.Validate()
}

return fmt.Errorf("unsupported metric reader type %s", conf.AllKeys())
return fmt.Errorf("unsupported metric reader type")
}

// Validate checks for valid exporters to be configured for the PullMetricReader
// Validate checks for valid exporters to be configured for the PullMetricReader.
func (pmr *PullMetricReader) Validate() error {
if pmr.Exporter.Prometheus == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
}

// Validate checks for valid exporters to be configured for the PeriodicMetricReader
// Validate checks for valid exporters to be configured for the PeriodicMetricReader.
func (pmr *PeriodicMetricReader) Validate() error {
if pmr.Exporter.Otlp == nil && pmr.Exporter.Console == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
}

func (v *View) Unmarshal(conf *confmap.Conf) error {
if conf == nil {
return nil
}

if err := conf.Unmarshal(v); err != nil {
return fmt.Errorf("invalid view configuration: %w", err)
}

return v.Validate()
}

// Validate checks for a valid Selector or Stream to be configured for the View.
func (v *View) Validate() error {
if v.Selector == nil || v.Stream == nil {
return fmt.Errorf("invalid view configuration")
}
return nil
}

func (s *ViewSelector) InstrumentNameStr() string {
func (s *ViewSelector) instrumentNameStr() string {
if s.InstrumentName == nil {
return ""
}
return *s.InstrumentName
}

func (s *ViewSelector) InstrumentTypeStr() string {
func (s *ViewSelector) instrumentTypeStr() string {
if s.InstrumentType == nil {
return ""
}
return *s.InstrumentType
return string(*s.InstrumentType)
}

func (s *ViewSelector) MeterNameStr() string {
func (s *ViewSelector) meterNameStr() string {
if s.MeterName == nil {
return ""
}
return *s.MeterName
}

func (s *ViewSelector) MeterVersionStr() string {
func (s *ViewSelector) meterVersionStr() string {
if s.MeterVersion == nil {
return ""
}
return *s.MeterVersion
}

func (s *ViewSelector) MeterSchemaUrlStr() string {
func (s *ViewSelector) meterSchemaURLStr() string {
if s.MeterSchemaUrl == nil {
return ""
}
return *s.MeterSchemaUrl
}

func (s *ViewStream) NameStr() string {
func (s *ViewSelector) unitStr() string {
if s.Unit == nil {
return ""
}
return *s.Unit
}

func (s *ViewStream) nameStr() string {
if s.Name == nil {
return ""
}
return *s.Name
}

func (s *ViewStream) DescriptionStr() string {
func (s *ViewStream) descriptionStr() string {
if s.Description == nil {
return ""
}
return *s.Description
}

func (e *ViewStreamAggregationExplicitBucketHistogram) RecordMinMaxBool() bool {
func (e *ViewStreamAggregationExplicitBucketHistogram) recordMinMaxBool() bool {
if e.RecordMinMax == nil {
return false
}
Expand Down

0 comments on commit ecc8594

Please sign in to comment.