Skip to content

Commit

Permalink
Externalized the otelcol version
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling committed Sep 16, 2020
1 parent 4109388 commit 239d559
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ dist:
module: github.com/observatorium/opentelemetry-collector-builder # the module name for the new distribution, following Go mod conventions. Optional, but recommended.
name: otelcol-custom # the binary name. Optional.
description: "Custom OpenTelemetry Collector distribution" # a long name for the application. Optional.
otelcol_version: "0.10.0" # the OpenTelemetry Collector version to use as base for the distribution. Optional.
output_path: /tmp/otelcol-distributionNNN # the path to write the output (sources and binary). Optional.
version: "1.0.0" # the version for your custom OpenTelemetry Collector. Optional.
go: "/usr/bin/go" # which Go binary to use to compile the generated sources. Optional.
exporters:
- gomod: "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter v0.9.0" # the Go module for the component. Required.
import: "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter" # the import path for the component. Optional.
name: "alibabacloudlogserviceexporter" # package name to use in the generated sources. Optional.
path: "./alibabacloudlogserviceexporter" # in case a local version should be used for the module, the path relative to the current dir, or a full path can be specified. Optional.
```
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Execute() {
cobra.OnInitialize(initConfig)

cmd := &cobra.Command{
Use: "otelcol-builder",
Use: "opentelemetry-collector-builder",
Long: "OpenTelemetry Collector distribution builder",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cfg.Validate(); err != nil {
Expand All @@ -55,6 +55,7 @@ func Execute() {
cmd.Flags().StringVar(&cfg.Distribution.ExeName, "name", "otelcol-custom", "The executable name for the OpenTelemetry Collector distribution")
cmd.Flags().StringVar(&cfg.Distribution.LongName, "description", "Custom OpenTelemetry Collector distribution", "A descriptive name for the OpenTelemetry Collector distribution")
cmd.Flags().StringVar(&cfg.Distribution.Version, "version", "1.0.0", "The version for the OpenTelemetry Collector distribution")
cmd.Flags().StringVar(&cfg.Distribution.OtelColVersion, "otelcol-version", cfg.Distribution.OtelColVersion, "Which version of OpenTelemetry Collector to use as base")
cmd.Flags().StringVar(&cfg.Distribution.OutputPath, "output-path", cfg.Distribution.OutputPath, "Where to write the resulting files")
cmd.Flags().StringVar(&cfg.Distribution.Go, "go", "/usr/bin/go", "The Go binary to use during the compilation phase")
cmd.Flags().StringVar(&cfg.Distribution.Module, "module", "github.com/jpkroehling/opentelemetry-collector-builder", "The Go module for the new distribution")
Expand Down
20 changes: 12 additions & 8 deletions internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"go.uber.org/zap"
)

const defaultOtelColVersion = "0.10.0"

// ErrInvalidGoMod indicates an invalid gomod
var ErrInvalidGoMod = errors.New("invalid gomod specification for module")

Expand All @@ -41,12 +43,13 @@ type Config struct {

// Distribution holds the parameters for the final binary
type Distribution struct {
Module string `mapstructure:"module"`
ExeName string `mapstructure:"name"`
Go string `mapstructure:"go"`
LongName string `mapstructure:"description"`
OutputPath string `mapstructure:"output_path"`
Version string `mapstructure:"version"`
Module string `mapstructure:"module"`
ExeName string `mapstructure:"name"`
Go string `mapstructure:"go"`
LongName string `mapstructure:"description"`
OtelColVersion string `mapstructure:"otelcol_version"`
OutputPath string `mapstructure:"output_path"`
Version string `mapstructure:"version"`
}

// Module represents a receiver, exporter, processor or extension for the distribution
Expand All @@ -61,7 +64,7 @@ type Module struct {
func DefaultConfig() Config {
zapLog, err := zap.NewDevelopment()
if err != nil {
panic(fmt.Sprintf("failed to obtain a logger instance (%v)?", err))
panic(fmt.Sprintf("failed to obtain a logger instance: %v", err))
}
log := zapr.NewLogger(zapLog)

Expand All @@ -73,7 +76,8 @@ func DefaultConfig() Config {
return Config{
Logger: log,
Distribution: Distribution{
OutputPath: outputDir,
OutputPath: outputDir,
OtelColVersion: defaultOtelColVersion,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
{{- range .Processors}}
{{.GoMod}}
{{- end}}
go.opentelemetry.io/collector v0.9.0
go.opentelemetry.io/collector v{{.Distribution.OtelColVersion}}
)
{{- range .Extensions}}
Expand Down

0 comments on commit 239d559

Please sign in to comment.