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

Add support for nodejs and python image defaulting and upgrade #607

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ ARG VERSION_DATE
ARG OTELCOL_VERSION
ARG TARGETALLOCATOR_VERSION
ARG AUTO_INSTRUMENTATION_JAVA_VERSION
ARG AUTO_INSTRUMENTATION_NODEJS_VERSION
ARG AUTO_INSTRUMENTATION_PYTHON_VERSION

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION}" -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION}" -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ OTELCOL_VERSION ?= "$(shell grep -v '\#' versions.txt | grep opentelemetry-colle
OPERATOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep operator | awk -F= '{print $$2}')"
TARGETALLOCATOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep targetallocator | awk -F= '{print $$2}')"
AUTO_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-java | awk -F= '{print $$2}')"
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION}"
AUTO_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-nodejs | awk -F= '{print $$2}')"
AUTO_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-python | awk -F= '{print $$2}')"
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION}"

# Image URL to use all building/pushing image targets
IMG_PREFIX ?= ghcr.io/${USER}/opentelemetry-operator
Expand Down Expand Up @@ -134,7 +136,7 @@ set-test-image-vars:

# Build the container image, used only for local dev purposes
container:
docker build -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} .
docker build -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} .

# Push the container image, used only for local dev purposes
container-push:
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ spec:
sampler:
type: parentbased_traceidratio
argument: "0.25"
java:
image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:latest
nodejs:
image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:latest
python:
image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:latest
EOF
```

Expand Down
14 changes: 13 additions & 1 deletion apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
)

const (
AnnotationDefaultAutoInstrumentationJava = "instrumentation.opentelemetry.io/default-auto-instrumentation-java-image"
AnnotationDefaultAutoInstrumentationJava = "instrumentation.opentelemetry.io/default-auto-instrumentation-java-image"
AnnotationDefaultAutoInstrumentationNodeJS = "instrumentation.opentelemetry.io/default-auto-instrumentation-nodejs-image"
AnnotationDefaultAutoInstrumentationPython = "instrumentation.opentelemetry.io/default-auto-instrumentation-python-image"
)

// log is for logging in this package.
Expand Down Expand Up @@ -56,6 +58,16 @@ func (r *Instrumentation) Default() {
r.Spec.Java.Image = val
}
}
if r.Spec.NodeJS.Image == "" {
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationNodeJS]; ok {
r.Spec.NodeJS.Image = val
}
}
if r.Spec.Python.Image == "" {
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationPython]; ok {
r.Spec.Python.Image = val
}
}
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1alpha1-instrumentation,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=instrumentations,versions=v1alpha1,name=vinstrumentationcreateupdate.kb.io,sideEffects=none,admissionReviewVersions={v1,v1beta1}
Expand Down
10 changes: 8 additions & 2 deletions apis/v1alpha1/instrumentation_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ import (
func TestInstrumentationDefaultingWebhook(t *testing.T) {
inst := &Instrumentation{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{AnnotationDefaultAutoInstrumentationJava: "img:1"},
Annotations: map[string]string{
AnnotationDefaultAutoInstrumentationJava: "java-img:1",
AnnotationDefaultAutoInstrumentationNodeJS: "nodejs-img:1",
AnnotationDefaultAutoInstrumentationPython: "python-img:1",
},
},
}
inst.Default()
assert.Equal(t, "img:1", inst.Spec.Java.Image)
assert.Equal(t, "java-img:1", inst.Spec.Java.Image)
assert.Equal(t, "nodejs-img:1", inst.Spec.NodeJS.Image)
assert.Equal(t, "python-img:1", inst.Spec.Python.Image)
}

func TestInstrumentationValidatingWebhook(t *testing.T) {
Expand Down
48 changes: 31 additions & 17 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ type Config struct {
onChange []func() error

// config state
collectorImage string
collectorConfigMapEntry string
targetAllocatorImage string
targetAllocatorConfigMapEntry string
platform platform.Platform
autoInstrumentationJavaImage string
collectorImage string
collectorConfigMapEntry string
targetAllocatorImage string
targetAllocatorConfigMapEntry string
platform platform.Platform
autoInstrumentationJavaImage string
autoInstrumentationNodeJSImage string
autoInstrumentationPythonImage string
}

// New constructs a new configuration based on the given options.
Expand All @@ -68,16 +70,18 @@ func New(opts ...Option) Config {
}

return Config{
autoDetect: o.autoDetect,
autoDetectFrequency: o.autoDetectFrequency,
collectorImage: o.collectorImage,
collectorConfigMapEntry: o.collectorConfigMapEntry,
targetAllocatorImage: o.targetAllocatorImage,
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
logger: o.logger,
onChange: o.onChange,
platform: o.platform,
autoInstrumentationJavaImage: o.autoInstrumentationjavaImage,
autoDetect: o.autoDetect,
autoDetectFrequency: o.autoDetectFrequency,
collectorImage: o.collectorImage,
collectorConfigMapEntry: o.collectorConfigMapEntry,
targetAllocatorImage: o.targetAllocatorImage,
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
logger: o.logger,
onChange: o.onChange,
platform: o.platform,
autoInstrumentationJavaImage: o.autoInstrumentationJavaImage,
autoInstrumentationNodeJSImage: o.autoInstrumentationNodeJSImage,
autoInstrumentationPythonImage: o.autoInstrumentationPythonImage,
}
}

Expand Down Expand Up @@ -169,7 +173,17 @@ func (c *Config) Platform() platform.Platform {
return c.platform
}

// AutoInstrumentationJavaImage returns OpenTelemetry auto-instrumentation container image.
// AutoInstrumentationJavaImage returns OpenTelemetry Java auto-instrumentation container image.
func (c *Config) AutoInstrumentationJavaImage() string {
return c.autoInstrumentationJavaImage
}

// AutoInstrumentationNodeJSImage returns OpenTelemetry NodeJS auto-instrumentation container image.
func (c *Config) AutoInstrumentationNodeJSImage() string {
return c.autoInstrumentationNodeJSImage
}

// AutoInstrumentationPythonImage returns OpenTelemetry Python auto-instrumentation container image.
func (c *Config) AutoInstrumentationPythonImage() string {
return c.autoInstrumentationPythonImage
}
38 changes: 26 additions & 12 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ import (
type Option func(c *options)

type options struct {
autoDetect autodetect.AutoDetect
autoDetectFrequency time.Duration
targetAllocatorImage string
collectorImage string
autoInstrumentationjavaImage string
collectorConfigMapEntry string
targetAllocatorConfigMapEntry string
logger logr.Logger
onChange []func() error
platform platform.Platform
version version.Version
autoDetect autodetect.AutoDetect
autoDetectFrequency time.Duration
targetAllocatorImage string
collectorImage string
autoInstrumentationJavaImage string
autoInstrumentationNodeJSImage string
autoInstrumentationPythonImage string
collectorConfigMapEntry string
targetAllocatorConfigMapEntry string
logger logr.Logger
onChange []func() error
platform platform.Platform
version version.Version
}

func WithAutoDetect(a autodetect.AutoDetect) Option {
Expand Down Expand Up @@ -98,6 +100,18 @@ func WithVersion(v version.Version) Option {

func WithAutoInstrumentationJavaImage(s string) Option {
return func(o *options) {
o.autoInstrumentationjavaImage = s
o.autoInstrumentationJavaImage = s
}
}

func WithAutoInstrumentationNodeJSImage(s string) Option {
return func(o *options) {
o.autoInstrumentationNodeJSImage = s
}
}

func WithAutoInstrumentationPythonImage(s string) Option {
return func(o *options) {
o.autoInstrumentationPythonImage = s
}
}
61 changes: 42 additions & 19 deletions internal/version/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,52 @@ import (
)

var (
version string
buildDate string
otelCol string
targetAllocator string
autoInstrumentationJava string
version string
buildDate string
otelCol string
targetAllocator string
autoInstrumentationJava string
autoInstrumentationNodeJS string
autoInstrumentationPython string
)

// Version holds this Operator's version as well as the version of some of the components it uses.
type Version struct {
Operator string `json:"opentelemetry-operator"`
BuildDate string `json:"build-date"`
OpenTelemetryCollector string `json:"opentelemetry-collector-version"`
Go string `json:"go-version"`
TargetAllocator string `json:"target-allocator-version"`
JavaAutoInstrumentation string `json:"auto-instrumentation-java"`
Operator string `json:"opentelemetry-operator"`
BuildDate string `json:"build-date"`
OpenTelemetryCollector string `json:"opentelemetry-collector-version"`
Go string `json:"go-version"`
TargetAllocator string `json:"target-allocator-version"`
AutoInstrumentationJava string `json:"auto-instrumentation-java"`
AutoInstrumentationNodeJS string `json:"auto-instrumentation-nodejs"`
AutoInstrumentationPython string `json:"auto-instrumentation-python"`
}

// Get returns the Version object with the relevant information.
func Get() Version {
return Version{
Operator: version,
BuildDate: buildDate,
OpenTelemetryCollector: OpenTelemetryCollector(),
Go: runtime.Version(),
TargetAllocator: TargetAllocator(),
JavaAutoInstrumentation: javaAutoInstrumentation(),
Operator: version,
BuildDate: buildDate,
OpenTelemetryCollector: OpenTelemetryCollector(),
Go: runtime.Version(),
TargetAllocator: TargetAllocator(),
AutoInstrumentationJava: AutoInstrumentationJava(),
AutoInstrumentationNodeJS: AutoInstrumentationNodeJS(),
AutoInstrumentationPython: AutoInstrumentationPython(),
}
}

func (v Version) String() string {
return fmt.Sprintf(
"Version(Operator='%v', BuildDate='%v', OpenTelemetryCollector='%v', Go='%v', TargetAllocator='%v')",
"Version(Operator='%v', BuildDate='%v', OpenTelemetryCollector='%v', Go='%v', TargetAllocator='%v', AutoInstrumentationJava='%v', AutoInstrumentationNodeJS='%v', AutoInstrumentationPython='%v')",
v.Operator,
v.BuildDate,
v.OpenTelemetryCollector,
v.Go,
v.TargetAllocator,
v.AutoInstrumentationJava,
v.AutoInstrumentationNodeJS,
v.AutoInstrumentationPython,
)
}

Expand All @@ -83,9 +92,23 @@ func TargetAllocator() string {
return "0.0.0"
}

func javaAutoInstrumentation() string {
func AutoInstrumentationJava() string {
if len(autoInstrumentationJava) > 0 {
return autoInstrumentationJava
}
return "0.0.0"
}

func AutoInstrumentationNodeJS() string {
if len(autoInstrumentationNodeJS) > 0 {
return autoInstrumentationNodeJS
}
return "0.0.0"
}

func AutoInstrumentationPython() string {
if len(autoInstrumentationPython) > 0 {
return autoInstrumentationPython
}
return "0.0.0"
}
10 changes: 9 additions & 1 deletion internal/version/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@ func TestTargetAllocatorVersionFromBuild(t *testing.T) {
}

func TestAutoInstrumentationJavaFallbackVersion(t *testing.T) {
assert.Equal(t, "0.0.0", javaAutoInstrumentation())
assert.Equal(t, "0.0.0", AutoInstrumentationJava())
}

func TestAutoInstrumentationNodeJSFallbackVersion(t *testing.T) {
assert.Equal(t, "0.0.0", AutoInstrumentationNodeJS())
}

func TestAutoInstrumentationPythonFallbackVersion(t *testing.T) {
assert.Equal(t, "0.0.0", AutoInstrumentationPython())
}
Loading