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

feat(trait): Move addon Telemetry to traits #5814

Merged
merged 3 commits into from
Sep 4, 2024
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
5 changes: 0 additions & 5 deletions addons/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
27 changes: 0 additions & 27 deletions addons/register_telemetry.go

This file was deleted.

21 changes: 0 additions & 21 deletions addons/telemetry/test_support.go

This file was deleted.

1 change: 0 additions & 1 deletion addons/telemetry/zz_desc_generated.go

This file was deleted.

1 change: 0 additions & 1 deletion addons/telemetry/zz_generated_doc.go

This file was deleted.

81 changes: 81 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]*
|
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
39 changes: 39 additions & 0 deletions e2e/telemetry/files/int-rest-consumer-addon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------

kind: Integration
apiVersion: camel.apache.org/v1
metadata:
name: rest-consumer-addon
spec:
flows:
- rest:
get:
- path: /customers/{name}
to: direct:start
- from:
steps:
- log:
message: get ${header.name}
- setBody:
simple: ${header.name} Doe
uri: direct:start
traits:
addons:
telemetry:
enabled: true
endpoint: http://opentelemetrycollector.otlp:4317
32 changes: 32 additions & 0 deletions e2e/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,35 @@ func TestTelemetryTrait(t *testing.T) {
g.Eventually(TailedLogs(t, ctx, pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.url: Str(http://%s/customers/%s)", serviceName, name)))
})
}

func TestTelemetryAddon(t *testing.T) {
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
// Check service is available
g.Eventually(ServicesByType(t, ctx, "otlp", corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty())

// Create integration and activate traces by telemetry trait
ExpectExecSucceed(t, g, Kubectl("apply", "-f", "files/int-rest-consumer-addon.yaml", "-n", ns))
g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-consumer-addon"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationCondition(t, ctx, ns, "rest-consumer-addon", "TelemetryTraitInfo"), TestTimeoutShort).Should(
WithTransform(IntegrationConditionMessage, ContainSubstring("Telemetry addon configuration is deprecated")))

name := "Alice"
serviceName := fmt.Sprintf("rest-consumer-addon.%s", ns)
g.Expect(KamelRun(t, ctx, ns, "files/rest-producer.yaml",
"-p", fmt.Sprintf("serviceName=%s", serviceName),
"-p", "name="+name,
"--name", "rest-producer-addon").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-producer-addon"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationLogs(t, ctx, ns, "rest-consumer-addon"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("get %s", name)))
g.Eventually(IntegrationLogs(t, ctx, ns, "rest-producer-addon"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("%s Doe", name)))

// Find opentelemetry collector pod : the exporter is configured to log traces with detailed verbosity.
pod, err := Pod(t, ctx, "otlp", "opentelemetrycollector")()
g.Expect(err).To(BeNil())
g.Expect(pod).NotTo(BeNil())

// Ensured logs in opentelemetry collector pod are present
g.Eventually(TailedLogs(t, ctx, pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.target: Str(/customers/%s)", name)))
g.Eventually(TailedLogs(t, ctx, pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.url: Str(http://%s/customers/%s)", serviceName, name)))
})
}
Loading