From 1fd750bea6cb5d09e7ee7ed83c4bba34d55f0b02 Mon Sep 17 00:00:00 2001 From: Gaelle Fournier Date: Tue, 3 Sep 2024 16:43:03 +0200 Subject: [PATCH] feat(trait): Move addon Telemetry to traits --- addons/addons_test.go | 5 - addons/register_telemetry.go | 27 -- addons/telemetry/test_support.go | 21 -- addons/telemetry/zz_desc_generated.go | 1 - addons/telemetry/zz_generated_doc.go | 1 - .../ROOT/partials/apis/camel-k-crds.adoc | 81 ++++++ helm/camel-k/crds/camel-k-crds.yaml | 261 ++++++++++++++++++ pkg/apis/camel/v1/common_types.go | 2 + pkg/apis/camel/v1/trait/telemetry.go | 43 +++ .../camel/v1/trait/zz_generated.deepcopy.go | 26 ++ pkg/apis/camel/v1/zz_generated.deepcopy.go | 5 + .../applyconfiguration/camel/v1/traits.go | 9 + pkg/cmd/run_test.go | 4 +- ...camel.apache.org_integrationplatforms.yaml | 74 +++++ .../camel.apache.org_integrationprofiles.yaml | 74 +++++ .../bases/camel.apache.org_integrations.yaml | 37 +++ .../camel.apache.org_kameletbindings.yaml | 38 +++ .../crd/bases/camel.apache.org_pipes.yaml | 38 +++ .../trait}/discovery/jaeger.go | 5 +- .../trait}/discovery/locator.go | 3 +- {addons/telemetry => pkg/trait}/telemetry.go | 66 ++--- .../telemetry => pkg/trait}/telemetry_test.go | 22 +- pkg/trait/trait_register.go | 1 + 23 files changed, 723 insertions(+), 121 deletions(-) delete mode 100644 addons/register_telemetry.go delete mode 100644 addons/telemetry/test_support.go delete mode 100644 addons/telemetry/zz_desc_generated.go delete mode 100644 addons/telemetry/zz_generated_doc.go create mode 100644 pkg/apis/camel/v1/trait/telemetry.go rename {addons/telemetry => pkg/trait}/discovery/jaeger.go (91%) rename {addons/telemetry => pkg/trait}/discovery/locator.go (93%) rename {addons/telemetry => pkg/trait}/telemetry.go (68%) rename {addons/telemetry => pkg/trait}/telemetry_test.go (94%) diff --git a/addons/addons_test.go b/addons/addons_test.go index 3adda05d21..dc5fa92efc 100644 --- a/addons/addons_test.go +++ b/addons/addons_test.go @@ -21,7 +21,6 @@ import ( "testing" "github.com/apache/camel-k/v2/addons/master" - "github.com/apache/camel-k/v2/addons/telemetry" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/trait" @@ -61,8 +60,4 @@ func TestTraitConfiguration(t *testing.T) { assert.Equal(t, "test-label", *master.LabelKey) assert.Equal(t, "test-value", *master.LabelValue) - require.NotNil(t, c.GetTrait("telemetry")) - telemetry, ok := c.GetTrait("telemetry").(*telemetry.TestTelemetryTrait) - require.True(t, ok) - assert.True(t, *telemetry.Enabled) } diff --git a/addons/register_telemetry.go b/addons/register_telemetry.go deleted file mode 100644 index fd451a8262..0000000000 --- a/addons/register_telemetry.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package addons - -import ( - "github.com/apache/camel-k/v2/addons/telemetry" - "github.com/apache/camel-k/v2/pkg/trait" -) - -func init() { - trait.AddToTraits(telemetry.NewTelemetryTrait) -} diff --git a/addons/telemetry/test_support.go b/addons/telemetry/test_support.go deleted file mode 100644 index 10ecf724c2..0000000000 --- a/addons/telemetry/test_support.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package telemetry - -// Expose telemetryTrait type for testing. -type TestTelemetryTrait = telemetryTrait diff --git a/addons/telemetry/zz_desc_generated.go b/addons/telemetry/zz_desc_generated.go deleted file mode 100644 index 073f40d23f..0000000000 --- a/addons/telemetry/zz_desc_generated.go +++ /dev/null @@ -1 +0,0 @@ -package telemetry diff --git a/addons/telemetry/zz_generated_doc.go b/addons/telemetry/zz_generated_doc.go deleted file mode 100644 index 073f40d23f..0000000000 --- a/addons/telemetry/zz_generated_doc.go +++ /dev/null @@ -1 +0,0 @@ -package telemetry diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index 4761b27477..c7bfdb9642 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -6057,6 +6057,13 @@ The configuration of Service trait The configuration of Service Binding trait +|`telemetry` + +*xref:#_camel_apache_org_v1_trait_TelemetryTrait[TelemetryTrait]* +| + + +The configuration of Telemetry trait + |`toleration` + *xref:#_camel_apache_org_v1_trait_TolerationTrait[TolerationTrait]* | @@ -8774,6 +8781,79 @@ The type of service to be used, either 'ClusterIP', 'NodePort' or 'LoadBalancer' +[#_camel_apache_org_v1_trait_TelemetryTrait] +=== TelemetryTrait + +*Appears on:* + +* <<#_camel_apache_org_v1_Traits, Traits>> + +The Telemetry trait can be used to automatically publish tracing information to an OTLP compatible collector. + +The trait is able to automatically discover the telemetry OTLP endpoint available in the namespace (supports **Jaerger** in version 1.35+). + +The Telemetry trait is disabled by default. + +WARNING: The Telemetry trait can't be enabled at the same time as the Tracing trait. + + +[cols="2,2a",options="header"] +|=== +|Field +|Description + +|`Trait` + +*xref:#_camel_apache_org_v1_trait_Trait[Trait]* +|(Members of `Trait` are embedded into this type.) + + + + +|`auto` + +bool +| + + +Enables automatic configuration of the trait, including automatic discovery of the telemetry endpoint. + +|`serviceName` + +string +| + + +The name of the service that publishes telemetry data (defaults to the integration name) + +|`endpoint` + +string +| + + +The target endpoint of the Telemetry service (automatically discovered by default) + +|`sampler` + +string +| + + +The sampler of the telemetry used for tracing (default "on") + +|`sampler-ratio` + +string +| + + +The sampler ratio of the telemetry used for tracing + +|`sampler-parent-based` + +bool +| + + +The sampler of the telemetry used for tracing is parent based (default "true") + + +|=== + [#_camel_apache_org_v1_trait_TolerationTrait] === TolerationTrait @@ -8843,6 +8923,7 @@ The list of taints to tolerate, in the form `Key[=Value]:Effect[:Seconds]` * <<#_camel_apache_org_v1_trait_RouteTrait, RouteTrait>> * <<#_camel_apache_org_v1_trait_ServiceBindingTrait, ServiceBindingTrait>> * <<#_camel_apache_org_v1_trait_ServiceTrait, ServiceTrait>> +* <<#_camel_apache_org_v1_trait_TelemetryTrait, TelemetryTrait>> * <<#_camel_apache_org_v1_trait_TolerationTrait, TolerationTrait>> Trait is the base type for all traits. It could be disabled by the user. diff --git a/helm/camel-k/crds/camel-k-crds.yaml b/helm/camel-k/crds/camel-k-crds.yaml index 632193ad51..06a215afcc 100644 --- a/helm/camel-k/crds/camel-k-crds.yaml +++ b/helm/camel-k/crds/camel-k-crds.yaml @@ -5260,6 +5260,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -7361,6 +7398,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -9367,6 +9441,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -11350,6 +11461,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -19373,6 +19521,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -27761,6 +27946,44 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. + All traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for + tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -38646,6 +38869,44 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. + All traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for + tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go index 80466ab4c3..561c896701 100644 --- a/pkg/apis/camel/v1/common_types.go +++ b/pkg/apis/camel/v1/common_types.go @@ -250,6 +250,8 @@ type Traits struct { Service *trait.ServiceTrait `property:"service" json:"service,omitempty"` // The configuration of Service Binding trait ServiceBinding *trait.ServiceBindingTrait `property:"service-binding" json:"service-binding,omitempty"` + // The configuration of Telemetry trait + Telemetry *trait.TelemetryTrait `property:"telemetry" json:"telemetry,omitempty"` // The configuration of Toleration trait Toleration *trait.TolerationTrait `property:"toleration" json:"toleration,omitempty"` diff --git a/pkg/apis/camel/v1/trait/telemetry.go b/pkg/apis/camel/v1/trait/telemetry.go new file mode 100644 index 0000000000..a9b6139ee4 --- /dev/null +++ b/pkg/apis/camel/v1/trait/telemetry.go @@ -0,0 +1,43 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package trait + +// The Telemetry trait can be used to automatically publish tracing information to an OTLP compatible collector. +// +// The trait is able to automatically discover the telemetry OTLP endpoint available in the namespace (supports **Jaerger** in version 1.35+). +// +// The Telemetry trait is disabled by default. +// +// WARNING: The Telemetry trait can't be enabled at the same time as the Tracing trait. +// +// +camel-k:trait=telemetry. +type TelemetryTrait struct { + Trait `property:",squash" json:",inline"` + // Enables automatic configuration of the trait, including automatic discovery of the telemetry endpoint. + Auto *bool `property:"auto" json:"auto,omitempty"` + // The name of the service that publishes telemetry data (defaults to the integration name) + ServiceName string `property:"service-name" json:"serviceName,omitempty"` + // The target endpoint of the Telemetry service (automatically discovered by default) + Endpoint string `property:"endpoint" json:"endpoint,omitempty"` + // The sampler of the telemetry used for tracing (default "on") + Sampler string `property:"sampler" json:"sampler,omitempty"` + // The sampler ratio of the telemetry used for tracing + SamplerRatio string `property:"sampler-ratio" json:"sampler-ratio,omitempty"` + // The sampler of the telemetry used for tracing is parent based (default "true") + SamplerParentBased *bool `property:"sampler-parent-based" json:"sampler-parent-based,omitempty"` +} diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go index 734f102969..42b190f709 100644 --- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go @@ -1168,6 +1168,32 @@ func (in *ServiceTrait) DeepCopy() *ServiceTrait { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TelemetryTrait) DeepCopyInto(out *TelemetryTrait) { + *out = *in + in.Trait.DeepCopyInto(&out.Trait) + if in.Auto != nil { + in, out := &in.Auto, &out.Auto + *out = new(bool) + **out = **in + } + if in.SamplerParentBased != nil { + in, out := &in.SamplerParentBased, &out.SamplerParentBased + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TelemetryTrait. +func (in *TelemetryTrait) DeepCopy() *TelemetryTrait { + if in == nil { + return nil + } + out := new(TelemetryTrait) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TolerationTrait) DeepCopyInto(out *TolerationTrait) { *out = *in diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go index 275a98449f..64fa10e2bd 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -3303,6 +3303,11 @@ func (in *Traits) DeepCopyInto(out *Traits) { *out = new(trait.ServiceBindingTrait) (*in).DeepCopyInto(*out) } + if in.Telemetry != nil { + in, out := &in.Telemetry, &out.Telemetry + *out = new(trait.TelemetryTrait) + (*in).DeepCopyInto(*out) + } if in.Toleration != nil { in, out := &in.Toleration, &out.Toleration *out = new(trait.TolerationTrait) diff --git a/pkg/client/camel/applyconfiguration/camel/v1/traits.go b/pkg/client/camel/applyconfiguration/camel/v1/traits.go index 4cb380e71c..f6dea6970e 100644 --- a/pkg/client/camel/applyconfiguration/camel/v1/traits.go +++ b/pkg/client/camel/applyconfiguration/camel/v1/traits.go @@ -60,6 +60,7 @@ type TraitsApplyConfiguration struct { SecurityContext *trait.SecurityContextTrait `json:"security-context,omitempty"` Service *trait.ServiceTrait `json:"service,omitempty"` ServiceBinding *trait.ServiceBindingTrait `json:"service-binding,omitempty"` + Telemetry *trait.TelemetryTrait `json:"telemetry,omitempty"` Toleration *trait.TolerationTrait `json:"toleration,omitempty"` Addons map[string]AddonTraitApplyConfiguration `json:"addons,omitempty"` Keda *TraitSpecApplyConfiguration `json:"keda,omitempty"` @@ -347,6 +348,14 @@ func (b *TraitsApplyConfiguration) WithServiceBinding(value trait.ServiceBinding return b } +// WithTelemetry sets the Telemetry field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Telemetry field is set to the value of the last call. +func (b *TraitsApplyConfiguration) WithTelemetry(value trait.TelemetryTrait) *TraitsApplyConfiguration { + b.Telemetry = &value + return b +} + // WithToleration sets the Toleration field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Toleration field is set to the value of the last call. diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go index 0cfa30a925..37df7d6d49 100644 --- a/pkg/cmd/run_test.go +++ b/pkg/cmd/run_test.go @@ -438,6 +438,7 @@ func TestConfigureTraits(t *testing.T) { "--trait", "affinity.pod-affinity=false", "--trait", "environment.container-meta=false", "--trait", "prometheus.pod-monitor=false", + "--trait", "telemetry.auto=true", "example.js") if err != nil { t.Error(err) @@ -454,10 +455,11 @@ func TestConfigureTraits(t *testing.T) { require.NoError(t, err) traitMap, err := trait.ToTraitMap(traits) require.NoError(t, err) - assert.Len(t, traitMap, 3) + assert.Len(t, traitMap, 4) assertTraitConfiguration(t, traits.Affinity, &traitv1.AffinityTrait{PodAffinity: ptr.To(false)}) assertTraitConfiguration(t, traits.Environment, &traitv1.EnvironmentTrait{ContainerMeta: ptr.To(false)}) assertTraitConfiguration(t, traits.Prometheus, &traitv1.PrometheusTrait{PodMonitor: ptr.To(false)}) + assertTraitConfiguration(t, traits.Telemetry, &traitv1.TelemetryTrait{Auto: ptr.To(true)}) } func assertTraitConfiguration(t *testing.T, trait interface{}, expected interface{}) { diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml index 0a1614617f..319b0e242d 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -2105,6 +2105,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -4206,6 +4243,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml index fe7a5df999..5987791c85 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml @@ -1980,6 +1980,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: @@ -3963,6 +4000,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml index b4da071b58..e6fa68441a 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml @@ -8000,6 +8000,43 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. All + traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml index f4045c4749..2660bd748b 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml @@ -8069,6 +8069,44 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. + All traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for + tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml index 3e13afdbcc..83d2f95d67 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml @@ -8067,6 +8067,44 @@ spec: required: - configuration type: object + telemetry: + description: The configuration of Telemetry trait + properties: + auto: + description: Enables automatic configuration of the trait, + including automatic discovery of the telemetry endpoint. + type: boolean + configuration: + description: |- + Legacy trait configuration parameters. + Deprecated: for backward compatibility. + type: object + x-kubernetes-preserve-unknown-fields: true + enabled: + description: Can be used to enable or disable a trait. + All traits share this common property. + type: boolean + endpoint: + description: The target endpoint of the Telemetry service + (automatically discovered by default) + type: string + sampler: + description: The sampler of the telemetry used for tracing + (default "on") + type: string + sampler-parent-based: + description: The sampler of the telemetry used for tracing + is parent based (default "true") + type: boolean + sampler-ratio: + description: The sampler ratio of the telemetry used for + tracing + type: string + serviceName: + description: The name of the service that publishes telemetry + data (defaults to the integration name) + type: string + type: object toleration: description: The configuration of Toleration trait properties: diff --git a/addons/telemetry/discovery/jaeger.go b/pkg/trait/discovery/jaeger.go similarity index 91% rename from addons/telemetry/discovery/jaeger.go rename to pkg/trait/discovery/jaeger.go index 04d508725a..20946ea04f 100644 --- a/addons/telemetry/discovery/jaeger.go +++ b/pkg/trait/discovery/jaeger.go @@ -24,7 +24,6 @@ import ( "strings" "github.com/apache/camel-k/v2/pkg/client" - "github.com/apache/camel-k/v2/pkg/trait" "github.com/apache/camel-k/v2/pkg/util/log" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -37,11 +36,11 @@ const ( jaegerPortName = "grpc-otlp" ) -func (loc *JaegerTelemetryLocator) FindEndpoint(ctx context.Context, c client.Client, l log.Logger, e *trait.Environment) (string, error) { +func (loc *JaegerTelemetryLocator) FindEndpoint(ctx context.Context, c client.Client, l log.Logger, namespace string) (string, error) { opts := metav1.ListOptions{ LabelSelector: "app.kubernetes.io/part-of=jaeger,app.kubernetes.io/component=service-collector", } - lst, err := c.CoreV1().Services(e.Integration.Namespace).List(ctx, opts) + lst, err := c.CoreV1().Services(namespace).List(ctx, opts) if err != nil { return "", err } diff --git a/addons/telemetry/discovery/locator.go b/pkg/trait/discovery/locator.go similarity index 93% rename from addons/telemetry/discovery/locator.go rename to pkg/trait/discovery/locator.go index 94cf94f3de..c0633e4ae3 100644 --- a/addons/telemetry/discovery/locator.go +++ b/pkg/trait/discovery/locator.go @@ -21,7 +21,6 @@ import ( "context" "github.com/apache/camel-k/v2/pkg/client" - "github.com/apache/camel-k/v2/pkg/trait" "github.com/apache/camel-k/v2/pkg/util/log" ) @@ -30,5 +29,5 @@ var TelemetryLocators []TelemetryLocator // TelemetryLocator is able to find the address of an available telemetry OTLP endpoint. type TelemetryLocator interface { - FindEndpoint(ctx context.Context, c client.Client, logger log.Logger, env *trait.Environment) (string, error) + FindEndpoint(ctx context.Context, c client.Client, logger log.Logger, namespace string) (string, error) } diff --git a/addons/telemetry/telemetry.go b/pkg/trait/telemetry.go similarity index 68% rename from addons/telemetry/telemetry.go rename to pkg/trait/telemetry.go index 5fae672324..963cdbe6bd 100644 --- a/addons/telemetry/telemetry.go +++ b/pkg/trait/telemetry.go @@ -15,51 +15,23 @@ See the License for the specific language governing permissions and limitations under the License. */ -package telemetry +package trait import ( "fmt" - "github.com/apache/camel-k/v2/pkg/util/boolean" - - corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" - - "github.com/apache/camel-k/v2/addons/telemetry/discovery" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" - "github.com/apache/camel-k/v2/pkg/trait" + "github.com/apache/camel-k/v2/pkg/trait/discovery" "github.com/apache/camel-k/v2/pkg/util" + "github.com/apache/camel-k/v2/pkg/util/boolean" + corev1 "k8s.io/api/core/v1" + "k8s.io/utils/ptr" ) -// The Telemetry trait can be used to automatically publish tracing information to an OTLP compatible collector. -// -// The trait is able to automatically discover the telemetry OTLP endpoint available in the namespace (supports **Jaerger** in version 1.35+). -// -// The Telemetry trait is disabled by default. -// -// WARNING: The Telemetry trait can't be enabled at the same time as the Tracing trait. -// -// +camel-k:trait=telemetry. -type Trait struct { - traitv1.Trait `property:",squash" json:",inline"` - // Enables automatic configuration of the trait, including automatic discovery of the telemetry endpoint. - Auto *bool `property:"auto" json:"auto,omitempty"` - // The name of the service that publishes telemetry data (defaults to the integration name) - ServiceName string `property:"service-name" json:"serviceName,omitempty"` - // The target endpoint of the Telemetry service (automatically discovered by default) - Endpoint string `property:"endpoint" json:"endpoint,omitempty"` - // The sampler of the telemetry used for tracing (default "on") - Sampler string `property:"sampler" json:"sampler,omitempty"` - // The sampler ratio of the telemetry used for tracing - SamplerRatio string `property:"sampler-ratio" json:"sampler-ratio,omitempty"` - // The sampler of the telemetry used for tracing is parent based (default "true") - SamplerParentBased *bool `property:"sampler-parent-based" json:"sampler-parent-based,omitempty"` -} - type telemetryTrait struct { - trait.BaseTrait - Trait `property:",squash"` + BaseTrait + traitv1.TelemetryTrait `property:",squash"` } const ( @@ -84,13 +56,13 @@ var ( ) // NewTelemetryTrait instance the telemetry trait as a BaseTrait capable to inject quarkus properties. -func NewTelemetryTrait() trait.Trait { +func NewTelemetryTrait() Trait { return &telemetryTrait{ - BaseTrait: trait.NewBaseTrait("telemetry", trait.TraitOrderBeforeControllerCreation), + BaseTrait: NewBaseTrait("telemetry", TraitOrderBeforeControllerCreation), } } -func (t *telemetryTrait) Configure(e *trait.Environment) (bool, *trait.TraitCondition, error) { +func (t *telemetryTrait) Configure(e *Environment) (bool, *TraitCondition, error) { if e.Integration == nil || !ptr.Deref(t.Enabled, false) { return false, nil, nil } @@ -99,17 +71,17 @@ func (t *telemetryTrait) Configure(e *trait.Environment) (bool, *trait.TraitCond return true, nil, nil } - var condition *trait.TraitCondition + var condition *TraitCondition if t.Endpoint == "" { for _, locator := range discovery.TelemetryLocators { - endpoint, err := locator.FindEndpoint(e.Ctx, t.Client, t.L, e) + endpoint, err := locator.FindEndpoint(e.Ctx, t.Client, t.L, e.Integration.Namespace) if err != nil { return false, nil, err } if endpoint != "" { t.L.Infof("Using tracing endpoint: %s", endpoint) - condition = trait.NewIntegrationCondition( + condition = NewIntegrationCondition( "Telemetry", v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, @@ -133,7 +105,7 @@ func (t *telemetryTrait) Configure(e *trait.Environment) (bool, *trait.TraitCond return true, condition, nil } -func (t *telemetryTrait) Apply(e *trait.Environment) error { +func (t *telemetryTrait) Apply(e *Environment) error { util.StringSliceUniqueAdd(&e.Integration.Status.Capabilities, v1.CapabilityTelemetry) if e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties != nil { @@ -145,7 +117,7 @@ func (t *telemetryTrait) Apply(e *trait.Environment) error { return nil } -func (t *telemetryTrait) setCatalogConfiguration(e *trait.Environment) { +func (t *telemetryTrait) setCatalogConfiguration(e *Environment) { if e.ApplicationProperties == nil { e.ApplicationProperties = make(map[string]string) } @@ -170,17 +142,17 @@ func (t *telemetryTrait) setCatalogConfiguration(e *trait.Environment) { if e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties != nil { for _, cp := range e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties { - e.ApplicationProperties[trait.CapabilityPropertyKey(cp.Key, e.ApplicationProperties)] = cp.Value + e.ApplicationProperties[CapabilityPropertyKey(cp.Key, e.ApplicationProperties)] = cp.Value } } } // Deprecated: to be removed in future release in favor of func setCatalogConfiguration(). -func (t *telemetryTrait) setRuntimeProviderProperties(e *trait.Environment) { +func (t *telemetryTrait) setRuntimeProviderProperties(e *Environment) { provider := e.CamelCatalog.CamelCatalogSpec.Runtime.Provider properties := telemetryProperties[provider] if appPropEnabled := properties[propEnabled]; appPropEnabled != "" { - e.ApplicationProperties[appPropEnabled] = "true" + e.ApplicationProperties[appPropEnabled] = boolean.TrueString } if appPropEndpoint := properties[propEndpoint]; appPropEndpoint != "" && t.Endpoint != "" { e.ApplicationProperties[appPropEndpoint] = t.Endpoint @@ -196,7 +168,7 @@ func (t *telemetryTrait) setRuntimeProviderProperties(e *trait.Environment) { } if appPropSamplerParentBased := properties[propSamplerParentBased]; appPropSamplerParentBased != "" { if ptr.Deref(t.SamplerParentBased, true) { - e.ApplicationProperties[appPropSamplerParentBased] = "true" + e.ApplicationProperties[appPropSamplerParentBased] = boolean.TrueString } else { e.ApplicationProperties[appPropSamplerParentBased] = boolean.FalseString } diff --git a/addons/telemetry/telemetry_test.go b/pkg/trait/telemetry_test.go similarity index 94% rename from addons/telemetry/telemetry_test.go rename to pkg/trait/telemetry_test.go index ad57ba96c7..c6bd50f0fc 100644 --- a/addons/telemetry/telemetry_test.go +++ b/pkg/trait/telemetry_test.go @@ -15,26 +15,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -package telemetry +package trait import ( "testing" - "github.com/apache/camel-k/v2/pkg/util/boolean" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" - "github.com/apache/camel-k/v2/pkg/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" ) func TestTelemetryTraitOnDefaultQuarkus(t *testing.T) { - e := createEnvironment(t, camel.QuarkusCatalog) + e := createTelemetryEnvironment(t, camel.QuarkusCatalog) telemetry := NewTelemetryTrait() tt, _ := telemetry.(*telemetryTrait) tt.Enabled = ptr.To(true) @@ -61,7 +57,7 @@ func TestTelemetryTraitOnDefaultQuarkus(t *testing.T) { } func TestTelemetryTraitWithValues(t *testing.T) { - e := createEnvironment(t, camel.QuarkusCatalog) + e := createTelemetryEnvironment(t, camel.QuarkusCatalog) telemetry := NewTelemetryTrait() tt, _ := telemetry.(*telemetryTrait) tt.Enabled = ptr.To(true) @@ -92,7 +88,7 @@ func TestTelemetryTraitWithValues(t *testing.T) { } func TestTelemetryForSourceless(t *testing.T) { - e := createEnvironment(t, camel.QuarkusCatalog) + e := createTelemetryEnvironment(t, camel.QuarkusCatalog) telemetry := NewTelemetryTrait() tt, _ := telemetry.(*telemetryTrait) tt.Enabled = ptr.To(true) @@ -119,13 +115,13 @@ func TestTelemetryForSourceless(t *testing.T) { assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.k.telemetry.samplerParentBased"]) } -func createEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error)) *trait.Environment { +func createTelemetryEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error)) *Environment { t.Helper() catalog, err := catalogGen() require.NoError(t, err) - e := trait.Environment{ + e := Environment{ CamelCatalog: catalog, ApplicationProperties: make(map[string]string), } diff --git a/pkg/trait/trait_register.go b/pkg/trait/trait_register.go index bac29dab51..032470f349 100644 --- a/pkg/trait/trait_register.go +++ b/pkg/trait/trait_register.go @@ -54,6 +54,7 @@ func init() { AddToTraits(newSecurityContextTrait) AddToTraits(newServiceTrait) AddToTraits(newServiceBindingTrait) + AddToTraits(NewTelemetryTrait) AddToTraits(newTolerationTrait) // ^^ Declaration order is not important, but let's keep them sorted for debugging. }