This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 2c6189ff05cb54c733e1150cd59fad7f81652220 Author: Gaelle Fournier <[email protected]> AuthorDate: Thu Jan 5 16:09:54 2023 +0100 feat(trait): Add telemetry trait * Define telemetry addon * Jaeger discovery for OTLP API * Basic configuration for tracing OTLP sampler * update existing e2e using tracing to telemetry Resolves: #3519 --- addons/addons_test.go | 18 +-- .../defaults.go => addons/register_telemetry.go | 38 +---- addons/telemetry/discovery/jaeger.go | 73 ++++++++++ .../telemetry/discovery/locator.go | 43 ++---- addons/telemetry/telemetry.go | 158 +++++++++++++++++++++ addons/telemetry/telemetry_test.go | 100 +++++++++++++ .../telemetry/test_support.go | 36 +---- addons/telemetry/zz_desc_generated.go | 1 + addons/telemetry/zz_generated_doc.go | 1 + addons/tracing/tracing.go | 8 +- docs/modules/ROOT/nav.adoc | 3 +- docs/modules/traits/pages/telemetry.adoc | 82 +++++++++++ docs/modules/traits/pages/tracing.adoc | 7 +- .../install/cli/duplicate_parameters_test.go | 6 +- .../install/cli/files/JavaDuplicateParams.java | 2 +- pkg/apis/camel/v1/common_types.go | 2 + pkg/apis/camel/v1/common_types_support_test.go | 6 +- pkg/resources/resources.go | 4 +- pkg/trait/util_test.go | 4 +- pkg/util/defaults/defaults.go | 2 +- resources/traits.yaml | 49 ++++++- script/gen_doc.sh | 1 + 22 files changed, 520 insertions(+), 124 deletions(-) diff --git a/addons/addons_test.go b/addons/addons_test.go index 786172ee8..b33e880f9 100644 --- a/addons/addons_test.go +++ b/addons/addons_test.go @@ -23,7 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/apache/camel-k/addons/master" - "github.com/apache/camel-k/addons/tracing" + "github.com/apache/camel-k/addons/telemetry" v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/trait" @@ -44,7 +44,7 @@ func TestTraitConfiguration(t *testing.T) { "labelKey": "test-label", "labelValue": "test-value", }), - "tracing": trait.ToAddonTrait(t, map[string]interface{}{ + "telemetry": trait.ToAddonTrait(t, map[string]interface{}{ "enabled": true, }), }, @@ -63,10 +63,10 @@ func TestTraitConfiguration(t *testing.T) { assert.Equal(t, "test-label", *master.LabelKey) assert.Equal(t, "test-value", *master.LabelValue) - require.NotNil(t, c.GetTrait("tracing")) - tracing, ok := c.GetTrait("tracing").(*tracing.TestTracingTrait) + require.NotNil(t, c.GetTrait("telemetry")) + telemetry, ok := c.GetTrait("telemetry").(*telemetry.TestTelemetryTrait) require.True(t, ok) - assert.True(t, *tracing.Enabled) + assert.True(t, *telemetry.Enabled) } func TestTraitConfigurationFromAnnotations(t *testing.T) { @@ -78,7 +78,7 @@ func TestTraitConfigurationFromAnnotations(t *testing.T) { "trait.camel.apache.org/master.resource-name": "test-lock", "trait.camel.apache.org/master.label-key": "test-label", "trait.camel.apache.org/master.label-value": "test-value", - "trait.camel.apache.org/tracing.enabled": "true", + "trait.camel.apache.org/telemetry.enabled": "true", }, }, Spec: v1.IntegrationSpec{ @@ -97,8 +97,8 @@ func TestTraitConfigurationFromAnnotations(t *testing.T) { assert.Equal(t, "test-label", *master.LabelKey) assert.Equal(t, "test-value", *master.LabelValue) - require.NotNil(t, c.GetTrait("tracing")) - tracing, ok := c.GetTrait("tracing").(*tracing.TestTracingTrait) + require.NotNil(t, c.GetTrait("telemetry")) + telemetry, ok := c.GetTrait("telemetry").(*telemetry.TestTelemetryTrait) require.True(t, ok) - assert.True(t, *tracing.Enabled) + assert.True(t, *telemetry.Enabled) } diff --git a/pkg/util/defaults/defaults.go b/addons/register_telemetry.go similarity index 54% copy from pkg/util/defaults/defaults.go copy to addons/register_telemetry.go index f2a39043d..9e2961522 100644 --- a/pkg/util/defaults/defaults.go +++ b/addons/register_telemetry.go @@ -15,37 +15,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package defaults +package addons -// *********************** -// DO NOT EDIT THIS FILE -// *********************** - -const ( - // Version -- - Version = "1.12.0-SNAPSHOT" - - // DefaultRuntimeVersion -- - DefaultRuntimeVersion = "1.17.0-SNAPSHOT" - - // BuildahVersion -- - BuildahVersion = "1.23.3" - - // KanikoVersion -- - KanikoVersion = "0.17.1" - - // baseImage -- - baseImage = "docker.io/adoptopenjdk/openjdk11:slim" - - // LocalRepository -- - LocalRepository = "/tmp/artifacts/m2" - - // ImageName -- - ImageName = "docker.io/apache/camel-k" - - // installDefaultKamelets -- - installDefaultKamelets = true +import ( + "github.com/apache/camel-k/addons/telemetry" + "github.com/apache/camel-k/pkg/trait" ) -// GitCommit must be provided during application build -var GitCommit string +func init() { + trait.AddToTraits(telemetry.NewTelemetryTrait) +} diff --git a/addons/telemetry/discovery/jaeger.go b/addons/telemetry/discovery/jaeger.go new file mode 100644 index 000000000..2eebd14b3 --- /dev/null +++ b/addons/telemetry/discovery/jaeger.go @@ -0,0 +1,73 @@ +/* +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 discovery + +import ( + "context" + "fmt" + "sort" + "strings" + + "github.com/apache/camel-k/pkg/client" + "github.com/apache/camel-k/pkg/trait" + "github.com/apache/camel-k/pkg/util/log" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type JaegerTelemetryLocator struct { + allowHeadless bool +} + +const ( + jaegerPortName = "grpc-otlp" +) + +func (loc *JaegerTelemetryLocator) FindEndpoint(ctx context.Context, c client.Client, l log.Logger, e *trait.Environment) (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) + if err != nil { + return "", err + } + var candidates []string + for _, svc := range lst.Items { + if !loc.allowHeadless && strings.HasSuffix(svc.Name, "-headless") { + continue + } + + for _, port := range svc.Spec.Ports { + if port.Name == jaegerPortName && port.Port > 0 { + candidates = append(candidates, fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", svc.Name, svc.Namespace, port.Port)) + } + } + } + sort.Strings(candidates) + if len(candidates) > 0 { + for _, endpoint := range candidates { + l.Infof("Detected Jaeger endpoint at: %s", endpoint) + } + return candidates[0], nil + } + return "", nil +} + +// registering the locator. +func init() { + TelemetryLocators = append(TelemetryLocators, &JaegerTelemetryLocator{}, &JaegerTelemetryLocator{allowHeadless: true}) +} diff --git a/pkg/util/defaults/defaults.go b/addons/telemetry/discovery/locator.go similarity index 54% copy from pkg/util/defaults/defaults.go copy to addons/telemetry/discovery/locator.go index f2a39043d..42563791e 100644 --- a/pkg/util/defaults/defaults.go +++ b/addons/telemetry/discovery/locator.go @@ -15,37 +15,20 @@ See the License for the specific language governing permissions and limitations under the License. */ -package defaults +package discovery -// *********************** -// DO NOT EDIT THIS FILE -// *********************** +import ( + "context" -const ( - // Version -- - Version = "1.12.0-SNAPSHOT" - - // DefaultRuntimeVersion -- - DefaultRuntimeVersion = "1.17.0-SNAPSHOT" - - // BuildahVersion -- - BuildahVersion = "1.23.3" - - // KanikoVersion -- - KanikoVersion = "0.17.1" - - // baseImage -- - baseImage = "docker.io/adoptopenjdk/openjdk11:slim" - - // LocalRepository -- - LocalRepository = "/tmp/artifacts/m2" - - // ImageName -- - ImageName = "docker.io/apache/camel-k" - - // installDefaultKamelets -- - installDefaultKamelets = true + "github.com/apache/camel-k/pkg/client" + "github.com/apache/camel-k/pkg/trait" + "github.com/apache/camel-k/pkg/util/log" ) -// GitCommit must be provided during application build -var GitCommit string +// TelemetryLocators contains available telemetry OTLP locators. +var TelemetryLocators []TelemetryLocator + +// TelemetryLocator is able to find the address of an available telemetry OTLP endpoint. +type TelemetryLocator interface { + FindEndpoint(context.Context, client.Client, log.Logger, *trait.Environment) (string, error) +} diff --git a/addons/telemetry/telemetry.go b/addons/telemetry/telemetry.go new file mode 100644 index 000000000..b3687296c --- /dev/null +++ b/addons/telemetry/telemetry.go @@ -0,0 +1,158 @@ +/* +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 + +import ( + "k8s.io/utils/pointer" + + "github.com/apache/camel-k/addons/telemetry/discovery" + v1 "github.com/apache/camel-k/pkg/apis/camel/v1" + traitv1 "github.com/apache/camel-k/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/pkg/trait" + "github.com/apache/camel-k/pkg/util" +) + +// 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"` +} + +const ( + propEnabled = "propEnabled" + propEndpoint = "propEndpoint" + propServiceName = "propServiceName" + propSampler = "propSampler" + propSamplerRatio = "propSamplerRatio" + propSamplerParentBased = "propSamplerParentBased" +) + +var ( + telemetryProperties = map[v1.RuntimeProvider]map[string]string{ + v1.RuntimeProviderQuarkus: { + propEndpoint: "quarkus.opentelemetry.tracer.exporter.otlp.endpoint", + propServiceName: "quarkus.opentelemetry.tracer.resource-attributes", + propSampler: "quarkus.opentelemetry.tracer.sampler", + propSamplerRatio: "quarkus.opentelemetry.tracer.sampler.ratio", + propSamplerParentBased: "quarkus.opentelemetry.tracer.sampler.parent-based", + }, + } +) + +// NewTelemetryTrait instance the telemetry trait as a BaseTrait capable to inject quarkus properties. +func NewTelemetryTrait() trait.Trait { + return &telemetryTrait{ + BaseTrait: trait.NewBaseTrait("telemetry", trait.TraitOrderBeforeControllerCreation), + } +} + +func (t *telemetryTrait) Configure(e *trait.Environment) (bool, error) { + if e.Integration == nil || !pointer.BoolDeref(t.Enabled, false) { + return false, nil + } + + if pointer.BoolDeref(t.Auto, true) { + if t.Endpoint == "" { + for _, locator := range discovery.TelemetryLocators { + endpoint, err := locator.FindEndpoint(e.Ctx, t.Client, t.L, e) + if err != nil { + return false, err + } + if endpoint != "" { + t.L.Infof("Using tracing endpoint: %s", endpoint) + t.Endpoint = endpoint + break + } + } + } + + if t.ServiceName == "" { + t.ServiceName = e.Integration.Name + } + + if t.Sampler == "" { + t.Sampler = "on" + } + } + + return true, nil +} + +func (t *telemetryTrait) Apply(e *trait.Environment) error { + util.StringSliceUniqueAdd(&e.Integration.Status.Capabilities, v1.CapabilityTelemetry) + + if e.CamelCatalog != nil { + provider := e.CamelCatalog.CamelCatalogSpec.Runtime.Provider + properties := telemetryProperties[provider] + + if appPropEnabled := properties[propEnabled]; appPropEnabled != "" { + e.ApplicationProperties[appPropEnabled] = "true" + } + + if appPropEndpoint := properties[propEndpoint]; appPropEndpoint != "" && t.Endpoint != "" { + e.ApplicationProperties[appPropEndpoint] = t.Endpoint + } + + if appPropServiceName := properties[propServiceName]; appPropServiceName != "" && t.ServiceName != "" { + e.ApplicationProperties[appPropServiceName] = "service.name=" + t.ServiceName + } + + if appPropSampler := properties[propSampler]; appPropSampler != "" && t.Sampler != "" { + e.ApplicationProperties[appPropSampler] = t.Sampler + } + + if appPropSamplerRatio := properties[propSamplerRatio]; appPropSamplerRatio != "" && t.SamplerRatio != "" { + e.ApplicationProperties[appPropSamplerRatio] = t.SamplerRatio + } + + if appPropSamplerParentBased := properties[propSamplerParentBased]; appPropSamplerParentBased != "" { + if pointer.BoolDeref(t.SamplerParentBased, true) { + e.ApplicationProperties[appPropSamplerParentBased] = "true" + } else { + e.ApplicationProperties[appPropSamplerParentBased] = "false" + } + } + + } + + return nil +} diff --git a/addons/telemetry/telemetry_test.go b/addons/telemetry/telemetry_test.go new file mode 100644 index 000000000..02070f8b2 --- /dev/null +++ b/addons/telemetry/telemetry_test.go @@ -0,0 +1,100 @@ +/* +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 + +import ( + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" + + v1 "github.com/apache/camel-k/pkg/apis/camel/v1" + "github.com/apache/camel-k/pkg/trait" + "github.com/apache/camel-k/pkg/util/camel" + + "github.com/stretchr/testify/assert" +) + +func TestTelemetryTraitOnDefaultQuarkus(t *testing.T) { + e := createEnvironment(t, camel.QuarkusCatalog) + telemetry := NewTelemetryTrait() + tt, _ := telemetry.(*telemetryTrait) + tt.Enabled = pointer.Bool(true) + tt.Endpoint = "http://endpoint3" + ok, err := telemetry.Configure(e) + assert.Nil(t, err) + assert.True(t, ok) + + err = telemetry.Apply(e) + assert.Nil(t, err) + + assert.Empty(t, e.ApplicationProperties["quarkus.opentelemetry.enabled"]) + assert.Equal(t, "http://endpoint3", e.ApplicationProperties["quarkus.opentelemetry.tracer.exporter.otlp.endpoint"]) + assert.Equal(t, "service.name=test", e.ApplicationProperties["quarkus.opentelemetry.tracer.resource-attributes"]) + assert.Equal(t, "on", e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler"]) + assert.Empty(t, e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler.ratio"]) + assert.Equal(t, "true", e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler.parent-based"]) +} + +func TestTelemetryTraitWithValues(t *testing.T) { + e := createEnvironment(t, camel.QuarkusCatalog) + telemetry := NewTelemetryTrait() + tt, _ := telemetry.(*telemetryTrait) + tt.Enabled = pointer.Bool(true) + tt.Endpoint = "http://endpoint3" + tt.ServiceName = "Test" + tt.Sampler = "ratio" + tt.SamplerRatio = "0.001" + tt.SamplerParentBased = pointer.Bool(false) + ok, err := telemetry.Configure(e) + assert.Nil(t, err) + assert.True(t, ok) + + err = telemetry.Apply(e) + assert.Nil(t, err) + + assert.Empty(t, e.ApplicationProperties["quarkus.opentelemetry.enabled"]) + assert.Equal(t, "http://endpoint3", e.ApplicationProperties["quarkus.opentelemetry.tracer.exporter.otlp.endpoint"]) + assert.Equal(t, "service.name=Test", e.ApplicationProperties["quarkus.opentelemetry.tracer.resource-attributes"]) + assert.Equal(t, "ratio", e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler"]) + assert.Equal(t, "0.001", e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler.ratio"]) + assert.Equal(t, "false", e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler.parent-based"]) +} + +func createEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error)) *trait.Environment { + t.Helper() + + catalog, err := catalogGen() + assert.Nil(t, err) + + e := trait.Environment{ + CamelCatalog: catalog, + ApplicationProperties: make(map[string]string), + } + + it := v1.Integration{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + }, + Status: v1.IntegrationStatus{ + Phase: v1.IntegrationPhaseDeploying, + }, + } + e.Integration = &it + return &e +} diff --git a/pkg/util/defaults/defaults.go b/addons/telemetry/test_support.go similarity index 53% copy from pkg/util/defaults/defaults.go copy to addons/telemetry/test_support.go index f2a39043d..10ecf724c 100644 --- a/pkg/util/defaults/defaults.go +++ b/addons/telemetry/test_support.go @@ -15,37 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package defaults +package telemetry -// *********************** -// DO NOT EDIT THIS FILE -// *********************** - -const ( - // Version -- - Version = "1.12.0-SNAPSHOT" - - // DefaultRuntimeVersion -- - DefaultRuntimeVersion = "1.17.0-SNAPSHOT" - - // BuildahVersion -- - BuildahVersion = "1.23.3" - - // KanikoVersion -- - KanikoVersion = "0.17.1" - - // baseImage -- - baseImage = "docker.io/adoptopenjdk/openjdk11:slim" - - // LocalRepository -- - LocalRepository = "/tmp/artifacts/m2" - - // ImageName -- - ImageName = "docker.io/apache/camel-k" - - // installDefaultKamelets -- - installDefaultKamelets = true -) - -// GitCommit must be provided during application build -var GitCommit string +// Expose telemetryTrait type for testing. +type TestTelemetryTrait = telemetryTrait diff --git a/addons/telemetry/zz_desc_generated.go b/addons/telemetry/zz_desc_generated.go new file mode 100644 index 000000000..073f40d23 --- /dev/null +++ b/addons/telemetry/zz_desc_generated.go @@ -0,0 +1 @@ +package telemetry diff --git a/addons/telemetry/zz_generated_doc.go b/addons/telemetry/zz_generated_doc.go new file mode 100644 index 000000000..073f40d23 --- /dev/null +++ b/addons/telemetry/zz_generated_doc.go @@ -0,0 +1 @@ +package telemetry diff --git a/addons/tracing/tracing.go b/addons/tracing/tracing.go index 7423eb9fb..667240fe2 100644 --- a/addons/tracing/tracing.go +++ b/addons/tracing/tracing.go @@ -27,13 +27,17 @@ import ( "github.com/apache/camel-k/pkg/util" ) -// The Tracing trait can be used to automatically publish tracing information to an -// OpenTracing compatible collector. +// +// WARNING: The Tracing trait has been **deprecated** in favor of the xref:traits:telemetry.adoc[Telemetry] trait. +// +// The Tracing trait can be used to automatically publish tracing information to an OpenTracing compatible collector. // // The trait is able to automatically discover the tracing endpoint available in the namespace (supports **Jaeger**). // // The Tracing trait is disabled by default. // +// WARNING: The Tracing trait can't be enabled at the same time as the Telemetry trait. +// // +camel-k:trait=tracing. type Trait struct { traitv1.Trait `property:",squash" json:",inline"` diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index 61a1a98a4..a9919e50a 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -52,7 +52,7 @@ ** xref:scaling/binding.adoc[Binding] * xref:traits:traits.adoc[Traits] // Start of autogenerated code - DO NOT EDIT! (trait-nav) -** xref:traits:3scale.adoc[3scale] +** xref:traits:3scale.adoc[3Scale] ** xref:traits:affinity.adoc[Affinity] ** xref:traits:aws-secrets-manager.adoc[Aws Secrets Manager] ** xref:traits:azure-key-vault.adoc[Azure Key Vault] @@ -92,6 +92,7 @@ ** xref:traits:route.adoc[Route] ** xref:traits:service-binding.adoc[Service Binding] ** xref:traits:service.adoc[Service] +** xref:traits:telemetry.adoc[Telemetry] ** xref:traits:toleration.adoc[Toleration] ** xref:traits:tracing.adoc[Tracing] // End of autogenerated code - DO NOT EDIT! (trait-nav) diff --git a/docs/modules/traits/pages/telemetry.adoc b/docs/modules/traits/pages/telemetry.adoc new file mode 100644 index 000000000..6adacbaa8 --- /dev/null +++ b/docs/modules/traits/pages/telemetry.adoc @@ -0,0 +1,82 @@ += Telemetry Trait + +// Start of autogenerated code - DO NOT EDIT! (description) +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. + + +This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**. + +// End of autogenerated code - DO NOT EDIT! (description) +// Start of autogenerated code - DO NOT EDIT! (configuration) +== Configuration + +Trait properties can be specified when running any integration with the CLI: +[source,console] +---- +$ kamel run --trait telemetry.[key]=[value] --trait telemetry.[key2]=[value2] integration.groovy +---- +The following configuration options are available: + +[cols="2m,1m,5a"] +|=== +|Property | Type | Description + +| telemetry.enabled +| bool +| Can be used to enable or disable a trait. All traits share this common property. + +| telemetry.auto +| bool +| Enables automatic configuration of the trait, including automatic discovery of the telemetry endpoint. + +| telemetry.service-name +| string +| The name of the service that publishes telemetry data (defaults to the integration name) + +| telemetry.endpoint +| string +| The target endpoint of the Telemetry service (automatically discovered by default) + +| telemetry.sampler +| string +| The sampler of the telemetry used for tracing (default "on") + +| telemetry.sampler-ratio +| string +| The sampler ratio of the telemetry used for tracing + +| telemetry.sampler-parent-based +| bool +| The sampler of the telemetry used for tracing is parent based (default "true") + +|=== + +// End of autogenerated code - DO NOT EDIT! (configuration) + +== Examples + +* To activate tracing to a deployed OTLP API Jaeger through discovery: ++ +[source,console] +$ kamel run -t telemetry.enable=true ... + +* To define a specific deployed OTLP gRPC reciever: ++ +[source,console] +$ kamel run -t telemetry.enable=true -t telemetry.endpoint=http://instance-collector:4317 ... + +* To define another sampler service name: ++ +[source,console] +$ kamel run -t telemetry.enable=true -t telemetry.service-name=tracer_myintegration ... + +* To use a ratio sampler with a sampling ratio of 1 to every 1,000 : ++ +[source,console] +$ kamel run -t telemetry.enable=true -t telemetry.sampler=ratio -t telemetry.sampler-ratio=0.001 ... diff --git a/docs/modules/traits/pages/tracing.adoc b/docs/modules/traits/pages/tracing.adoc index 735f624d4..549910fed 100755 --- a/docs/modules/traits/pages/tracing.adoc +++ b/docs/modules/traits/pages/tracing.adoc @@ -1,13 +1,16 @@ = Tracing Trait // Start of autogenerated code - DO NOT EDIT! (description) -The Tracing trait can be used to automatically publish tracing information to an -OpenTracing compatible collector. +WARNING: The Tracing trait has been **deprecated** in favor of the xref:traits:telemetry.adoc[Telemetry] trait. + +The Tracing trait can be used to automatically publish tracing information to an OpenTracing compatible collector. The trait is able to automatically discover the tracing endpoint available in the namespace (supports **Jaeger**). The Tracing trait is disabled by default. +WARNING: The Tracing trait can't be enabled at the same time as the Telemetry trait. + This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**. diff --git a/e2e/namespace/install/cli/duplicate_parameters_test.go b/e2e/namespace/install/cli/duplicate_parameters_test.go index b3a114e1b..7e03e1d48 100644 --- a/e2e/namespace/install/cli/duplicate_parameters_test.go +++ b/e2e/namespace/install/cli/duplicate_parameters_test.go @@ -39,10 +39,10 @@ func TestDuplicateParameters(t *testing.T) { defer cancel() // run kamel to output the traits/configuration structure in json format to check the processed values - // the tracing.enabled is false inside JavaDuplicateParams.java, so we can check the output of this trait as true. + // the telemetry.enabled is false inside JavaDuplicateParams.java, so we can check the output of this trait as true. cmdParams := []string{"kamel", "run", "files/JavaDuplicateParams.java", "-o", "json", - "-t", "tracing.enabled=true", "--trait", "pull-secret.enabled=true", + "-t", "telemetry.enabled=true", "--trait", "pull-secret.enabled=true", "--property", "prop1=true", "-p", "prop2=true", "--force"} comm, _, _ := cmd.NewKamelWithModelineCommand(ctx, cmdParams) @@ -51,6 +51,6 @@ func TestDuplicateParameters(t *testing.T) { commOutput := GetOutputString(comm) outParams := - `"traits":{"affinity":{"enabled":true},"camel":{"properties":["prop1 = true","prop2 = true","foo = bar"]},"pull-secret":{"enabled":true},"addons":{"tracing":{"enabled":true}}}` + `"traits":{"affinity":{"enabled":true},"camel":{"properties":["prop1 = true","prop2 = true","foo = bar"]},"pull-secret":{"enabled":true},"addons":{"telemetry":{"enabled":true}}}` Expect(commOutput).To(ContainSubstring(outParams)) } diff --git a/e2e/namespace/install/cli/files/JavaDuplicateParams.java b/e2e/namespace/install/cli/files/JavaDuplicateParams.java index 95b73b1ac..ef267c31a 100644 --- a/e2e/namespace/install/cli/files/JavaDuplicateParams.java +++ b/e2e/namespace/install/cli/files/JavaDuplicateParams.java @@ -1,4 +1,4 @@ -// camel-k: language=java trait=tracing.enabled=false trait=affinity.enabled=true property=prop1=false property=foo=bar +// camel-k: language=java trait=telemetry.enabled=false trait=affinity.enabled=true property=prop1=false property=foo=bar /* * Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go index c30be28de..33eec9f89 100644 --- a/pkg/apis/camel/v1/common_types.go +++ b/pkg/apis/camel/v1/common_types.go @@ -294,6 +294,8 @@ const ( CapabilityCircuitBreaker = "circuit-breaker" // CapabilityTracing defines the tracing (opentracing) capability CapabilityTracing = "tracing" + // CapabilityTelemetry defines the telemetry (opentelemetry) capability + CapabilityTelemetry = "telemetry" // CapabilityMaster defines the master capability CapabilityMaster = "master" // CapabilityResumeKafka defines the resume capability diff --git a/pkg/apis/camel/v1/common_types_support_test.go b/pkg/apis/camel/v1/common_types_support_test.go index e46455493..dd424a33d 100644 --- a/pkg/apis/camel/v1/common_types_support_test.go +++ b/pkg/apis/camel/v1/common_types_support_test.go @@ -47,7 +47,7 @@ func TestTraitsMerge(t *testing.T) { "master": toAddonTrait(t, map[string]interface{}{ "resourceName": "test-lock", }), - "tracing": toAddonTrait(t, map[string]interface{}{ + "telemetry": toAddonTrait(t, map[string]interface{}{ "enabled": true, }), }, @@ -66,7 +66,7 @@ func TestTraitsMerge(t *testing.T) { Level: "DEBUG", }, Addons: map[string]AddonTrait{ - "tracing": toAddonTrait(t, map[string]interface{}{ + "telemetry": toAddonTrait(t, map[string]interface{}{ "serviceName": "test-integration", }), }, @@ -103,7 +103,7 @@ func TestTraitsMerge(t *testing.T) { "enabled": true, "serviceName": "test-integration", }), - t1.Addons["tracing"]) + t1.Addons["telemetry"]) } func configurationFromMap(t *testing.T, configMap map[string]interface{}) *trait.Configuration { diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go index 61fa2f5b9..121603906 100644 --- a/pkg/resources/resources.go +++ b/pkg/resources/resources.go @@ -611,9 +611,9 @@ var assets = func() http.FileSystem { "/traits.yaml": &vfsgen۰CompressedFileInfo{ name: "traits.yaml", modTime: time.Time{}, - uncompressedSize: 56648, + uncompressedSize: 58334, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\x39\x92\x20\xfe\x7f\x7f\x0a\x84\xf6\xb7\x21\xc9\x41\x52\xee\x9e\x9d\xd9\x5e\xfd\xce\x3b\xa7\xb6\xdd\x33\xea\xf6\x43\x67\xa9\x7b\x76\xc2\xe7\x18\x82\x55\x20\x09\xb3\x0a\xa8\x06\x50\x92\xd8\x37\xf7\xdd\x2f\x90\x99\x78\x54\xb1\x28\x52\xb6\xd5\x31\xba\xb9\xe9\x88\xb1\x48\x56\x25\x12\x89\x44\x22\x91\x4f\x67\xb8\x74\xf6\xf4\xab\x31\x53\xbc\x16\xa7\xec\x77\xb6\xe0\x95\xf8\x8a\xb1\xa6\xe2\x6e\xae\x4d\x7d\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\xfd\x73\x1c\x37\x92\x20\xfa\xbb\xfe\x0a\x04\xf7\x6d\x90\xd4\xeb\x6e\xca\x9e\xf5\xac\x97\xef\x69\xe7\x68\x59\x9e\xa1\xad\x0f\x9e\x48\x7b\x76\x42\xa7\x98\x46\x57\xa1\xbb\xa1\xae\x02\x6a\x00\x14\xc9\xf6\xed\xfd\xef\x17\xc8\x4c\x7c\x54\x75\x35\xbb\x29\x89\xbe\xe1\xcd\xee\x44\xac\x45\xb2\x90\x48\x24\x12\x89\x44\x7e\x3a\xc3\xa5\xb3\xa7\x4f\xc6\x4c\xf1\x5a\x9c\xb2\xdf\xd9\x82\x57\xe2\x09\x63\x4d\xc5\xdd\x5c\x9b\xfa\x [...] }, } fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ diff --git a/pkg/trait/util_test.go b/pkg/trait/util_test.go index 7c19d9332..63b973a1d 100644 --- a/pkg/trait/util_test.go +++ b/pkg/trait/util_test.go @@ -53,7 +53,7 @@ func TestToTraitMap(t *testing.T) { }, }, Addons: map[string]v1.AddonTrait{ - "tracing": ToAddonTrait(t, map[string]interface{}{ + "telemetry": ToAddonTrait(t, map[string]interface{}{ "enabled": true, }), }, @@ -76,7 +76,7 @@ func TestToTraitMap(t *testing.T) { "enabled": true, }, "addons": { - "tracing": map[string]interface{}{ + "telemetry": map[string]interface{}{ "enabled": true, }, }, diff --git a/pkg/util/defaults/defaults.go b/pkg/util/defaults/defaults.go index f2a39043d..3297388a4 100644 --- a/pkg/util/defaults/defaults.go +++ b/pkg/util/defaults/defaults.go @@ -47,5 +47,5 @@ const ( installDefaultKamelets = true ) -// GitCommit must be provided during application build +//GitCommit must be provided during application build var GitCommit string diff --git a/resources/traits.yaml b/resources/traits.yaml index 156bf380a..a5fef3a9f 100755 --- a/resources/traits.yaml +++ b/resources/traits.yaml @@ -1289,6 +1289,44 @@ traits: - name: services type: '[]string' description: List of Services in the form [[apigroup/]version:]kind:[namespace/]name +- name: telemetry + platform: false + profiles: + - Kubernetes + - Knative + - OpenShift + description: '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.' + properties: + - name: enabled + type: bool + description: Can be used to enable or disable a trait. All traits share this common + property. + - name: auto + type: bool + description: Enables automatic configuration of the trait, including automatic + discovery of the telemetry endpoint. + - name: service-name + type: string + description: The name of the service that publishes telemetry data (defaults to + the integration name) + - name: endpoint + type: string + description: The target endpoint of the Telemetry service (automatically discovered + by default) + - name: sampler + type: string + description: The sampler of the telemetry used for tracing (default "on") + - name: sampler-ratio + type: string + description: The sampler ratio of the telemetry used for tracing + - name: sampler-parent-based + type: bool + description: The sampler of the telemetry used for tracing is parent based (default + "true") - name: toleration platform: false profiles: @@ -1316,10 +1354,13 @@ traits: - Kubernetes - Knative - OpenShift - description: The Tracing trait can be used to automatically publish tracing information - to an OpenTracing compatible collector. The trait is able to automatically discover - the tracing endpoint available in the namespace (supports **Jaeger**). The Tracing - trait is disabled by default. + description: 'WARNING: The Tracing trait has been **deprecated** in favor of the + xref:traits:telemetry.adoc[Telemetry] trait. The Tracing trait can be used to + automatically publish tracing information to an OpenTracing compatible collector. + The trait is able to automatically discover the tracing endpoint available in + the namespace (supports **Jaeger**). The Tracing trait is disabled by default. + WARNING: The Tracing trait can''t be enabled at the same time as the Telemetry + trait.' properties: - name: enabled type: bool diff --git a/script/gen_doc.sh b/script/gen_doc.sh index 523d0cdc7..76982a18b 100755 --- a/script/gen_doc.sh +++ b/script/gen_doc.sh @@ -31,6 +31,7 @@ go run ./cmd/util/doc-gen \ --input-dirs github.com/apache/camel-k/addons/resume \ --input-dirs github.com/apache/camel-k/addons/threescale \ --input-dirs github.com/apache/camel-k/addons/tracing \ + --input-dirs github.com/apache/camel-k/addons/telemetry \ --input-dirs github.com/apache/camel-k/addons/vault/aws \ --input-dirs github.com/apache/camel-k/addons/vault/gcp \ --input-dirs github.com/apache/camel-k/addons/vault/azure
