Skip to content

Commit

Permalink
(#56) Update traits usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler authored and squakez committed Jun 7, 2024
1 parent cbd329d commit 31de961
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 413 deletions.
26 changes: 16 additions & 10 deletions generic-examples/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Camel K Examples

This folder contains various examples of `Camel K` integrations. You can use them to learn more about the capabilities of Camel K or to inspire your integration development.
This folder contains various examples of `Camel K` integrations. You can use them to learn more about the capabilities
of Camel K or to inspire your integration development.

## Basic usage examples

In this section you will find the most basic examples. Useful to start learning about Camel K and how to run.
In this section you will find the most basic examples. Useful to start learning about Camel K and how to run.
You can use many supported languages and learn about the most basic features:

| Type | Description | Link |
Expand All @@ -22,7 +23,9 @@ You can use many supported languages and learn about the most basic features:

## Component usage examples

In this section you can find a few examples of certain [`Camel` components](https://camel.apache.org/components/latest/index.html). This is a limited number of the wide variety of components supported by Apache Camel.
In this section you can find a few examples of certain [
`Camel` components](https://camel.apache.org/components/latest/index.html). This is a limited number of the wide variety
of components supported by Apache Camel.
You can also find useful examples [in this repository](https://github.com/apache/camel-k-examples).

| Type | Description | Link |
Expand All @@ -37,7 +40,8 @@ You can also find useful examples [in this repository](https://github.com/apache

## Advanced usage examples

When you feel comfortable with basic stuff, you may want to try the more advanced features offered by Camel K. Here a few examples:
When you feel comfortable with basic stuff, you may want to try the more advanced features offered by Camel K. Here a
few examples:

| Type | Description | Link |
|----------|---------------------------------------------------------------------------------------|-----------------------------|
Expand All @@ -52,9 +56,11 @@ When you feel comfortable with basic stuff, you may want to try the more advance

Traits configuration will be very helpful to fine tune your `Integration`. Here a few examples:

| Type | Description | Link |
|-----------------------|-----------------------------------------|-------------------------------------|
| Container | How to customize with `container` trait | [see examples](./traits/container/) |
| Health | How to customize with `health` trait | [see examples](./traits/health/) |
| JVM | How to use `jvm` trait | [see examples](./traits/jvm/) |
| Tracing (opentracing) | How to use `tracing` trait | [see examples](./traits/tracing/) |
| Type | Description | Link |
|------------|-----------------------------------------|--------------------------------------|
| Container | How to customize with `container` trait | [see examples](./traits/container/) |
| Health | How to customize with `health` trait | [see examples](./traits/health/) |
| JVM | How to use `jvm` trait | [see examples](./traits/jvm/) |
| Prometheus | How to use `prometheus` trait | [see examples](./traits/prometheus/) |
| Service | How to use `service` trait | [see examples](./traits/service/) |
| Telemetry | How to use `telemetry` trait | [see examples](./traits/telemetry/) |
3 changes: 2 additions & 1 deletion generic-examples/languages/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
uri: "timer:tick"
parameters:
period: "5000"
includeMetadata: true
steps:
- set-body:
constant: "Hello Yaml !!!"
simple: "Hello Yaml #${header.CamelTimerCounter}"
- transform:
simple: "${body.toUpperCase()}"
- to: "log:info"
17 changes: 7 additions & 10 deletions generic-examples/traits/container/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Camel K Container Trait

In this section you will find examples about fine tuning your `Integration` using **Container** `trait` capability.
In this section you will find examples about fine-tuning your `Integration` using **Container** `trait` capability.

The Container trait is a platform trait, it is **enabled** by default.
The Container trait is a platform trait, it is **enabled** by default.

## Before you begin

Expand All @@ -25,9 +25,8 @@ kamel run \
--trait container.limit-memory=500Mi
```



When you check the values declared by the pod spec

```sh
kubectl get pods --selector="camel.apache.org/integration"="container" -o yaml
```
Expand All @@ -37,7 +36,6 @@ You should get a result with the values you defined
```yaml
...
"imagePullPolicy": "Always",

...
"resources": {
"limits": {
Expand All @@ -48,13 +46,13 @@ You should get a result with the values you defined
"cpu": "5m",
"memory": "100Mi"
}
},
}
...
```

## Advanced usages

The container and service port configuration needs needs the presence of a service, else it will be ignored.
The container and service port configuration needs the presence of a service, else it will be ignored.

For these example, we use an example route exposing some rest endpoint. This will enable the service and expose the container port by default.

Expand All @@ -76,7 +74,7 @@ kamel run --name restcontainer \
When you check the values declared by the service spec

```sh
kubectl get service restcontainer -o jsonpath='{.spec.ports}'
kubectl get service restcontainer -o jsonpath='{.spec.ports}'
```

You should get a result with the values you defined
Expand All @@ -101,8 +99,7 @@ kamel run \
```

```sh
kubectl get pods --selector="camel.apache.org/integration"="restcontainer" \
-o jsonpath= -o jsonpath='{.items[*].spec.containers[*].ports}'
kubectl get pods --selector="camel.apache.org/integration"="restcontainer" -o jsonpath='{.items[*].spec.containers[*].ports}'
```

You should get a result with the values you defined
Expand Down
8 changes: 4 additions & 4 deletions generic-examples/traits/health/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Camel K Health Trait

In this section you will find examples about fine tuning your `Integration` using **Health** `trait` capability.
In this section you will find examples about fine-tuning your `Integration` using **Health** `trait` capability.

The Health trait can be used to activate and configure the Health Probes on the integration container.

Expand All @@ -12,7 +12,7 @@ Make sure you've read the [installation instructions](https://camel.apache.org/c

## Basic usage

By default the trait is disabled so it needs to be activated.
By default, the trait is disabled so it needs to be activated.

To activate the trait and configure the liveness Probes, run the integration

Expand All @@ -29,13 +29,14 @@ kamel run \
--trait health.liveness-timeout=2
```


When you check the values declared by the pod spec

```sh
kubectl get pods --selector="camel.apache.org/integration"="health" -o jsonpath='{.items[*].spec.containers[*].livenessProbe}'
```

You should get a result with the values you defined

```json
{"failureThreshold":5,"httpGet":{"path":"/q/health/live","port":8080,"scheme":"HTTP"},"initialDelaySeconds":30,"periodSeconds":10,"successThreshold":1,"timeoutSeconds":2}
```
Expand Down Expand Up @@ -68,7 +69,6 @@ Run the integration
--trait health.readiness-scheme=HTTPS
```


When you check the values declared by the pod spec for the readinessProbe
```sh
kubectl get pods --selector="camel.apache.org/integration"="health" -o jsonpath='{.items[*].spec.containers[*].readinessProbe}'
Expand Down
5 changes: 0 additions & 5 deletions generic-examples/traits/jvm/Classpath.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
* limitations under the License.
*/

// Create a configmap holding a jar in order to simulate the presence of a dependency on the runtime image
// kubectl create configmap my-dep --from-file=sample-1.0.jar

//kamel run --resource configmap:my-dep -t jvm.classpath=/etc/camel/resources/my-dep/sample-1.0.jar Classpath.java --dev

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.example.MyClass;

Expand Down
17 changes: 16 additions & 1 deletion generic-examples/traits/jvm/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Camel K JVM Trait

In this section you will find examples about fine tuning your `Integration` using **JVM** `trait` capability.
In this section you will find examples about fine-tuning your `Integration` using **JVM** `trait` capability.

Create a configmap holding a jar in order to simulate the presence of a dependency on the runtime image

```shell
kubectl create configmap my-dep --from-file=sample-1.0.jar
```

Run the integration
```shell
kamel run --dev --resource configmap:my-dep --trait jvm.classpath=/etc/camel/resources/my-dep/sample-1.0.jar Classpath.java

[1] 2024-06-07 09:17:06,422 INFO [route1] (Camel (camel-1) thread #1 - timer://tick) Hello World!
[1] 2024-06-07 09:17:07,410 INFO [route1] (Camel (camel-1) thread #1 - timer://tick) Hello World!
[1] 2024-06-07 09:17:08,410 INFO [route1] (Camel (camel-1) thread #1 - timer://tick) Hello World!
```
13 changes: 2 additions & 11 deletions generic-examples/traits/prometheus/MyIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@
* limitations under the License.
*/

/*
To execute this example, run:
kamel run -t prometheus.enabled=true MyIntegration.java
*/

import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants;

public class MyIntegration extends RouteBuilder {

Expand All @@ -39,12 +32,10 @@ public void configure() {
.log(LoggingLevel.ERROR, "Failed processing ${body}")
.to("log:exception");

from("timer:foo?period=1000")
from("timer:foo?includeMetadata=true")
.routeId("unreliable-service")
.setBody(header(Exchange.TIMER_COUNTER).prepend("event #"))
.log("Processing ${body}...")
.bean("service", "process")
.log("Successfully processed ${body}")
.to("microprofile-metrics:meter:success");
.to("micrometer:counter:success");
}
}
31 changes: 19 additions & 12 deletions generic-examples/traits/prometheus/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
# Camel K Prometheus Trait

In this section you will find examples about fine tuning your `Integration` using **Prometheus** `trait` capability.
In this section you will find examples about fine-tuning your `Integration` using **Prometheus** `trait` capability.


A Prometheus-compatible endpoint is configured with the Prometheus trait. When utilising the Prometheus operator, it also generates a PodMonitor resource, which allows the endpoint to be scraped automatically.
A Prometheus-compatible endpoint is configured with the Prometheus trait.
When utilising the Prometheus operator, it also generates a PodMonitor resource, which allows the endpoint to be scraped automatically.

To get statistics about the number of events successfully handled by the `Integration`,execute the `MyIntegration.java` route via:

$ kamel run -t prometheus.enabled=true MyIntegration.java
In case the prometheus operator is not installed in your cluster, run:

```shell
kamel run --dev --trait prometheus.enabled=true --trait prometheus.pod-monitor=false MyIntegration.java
```

In case the prometheus operator is not installed in your cluster, run:

$ kamel run -t prometheus.enabled=true pod-monitor=false MyIntegration.java
Alternatively, you can quickly deploy the Prometheus operator and then run:

You should be able to see the new integration running after a while via:
```shell
kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/bundle.yaml

$ kamel get
kamel run --dev --trait prometheus.enabled=true MyIntegration.java
```

The metrics can be retrieved by port-forwarding this service, e.g.:

$ kubectl port-forward svc/metrics-prometheus 8080:8080
```shell
kubectl port-forward svc/prometheus-operator 8080:8080

$ curl http://localhost:8080/metrics
curl http://localhost:8080/metrics
```

Similarly other use cases can be to retrieve information on unprocessed events, number of retries made to process an event, etc. For more information on Integration monitoring refer to the [Camel K Integration Monitoring](https://camel.apache.org/camel-k/next/observability/monitoring/integration.html) documentation.
Similarly other use cases can be to retrieve information on unprocessed events, number of retries made to process an event, etc.
For more information on Integration monitoring refer to the [Camel K Integration Monitoring](https://camel.apache.org/camel-k/next/observability/monitoring/integration.html) documentation.

16 changes: 14 additions & 2 deletions generic-examples/traits/service/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# SERVICE EXAMPLE

This folder contains examples of how to use a `trait service`. You can use them to learn more about how to enable services for integrations deployed on the cluster.
This folder contains examples of how to use a trait `service`. You can use them to learn more about how to enable services for integrations deployed on the cluster.

To access integration outside the cluster you can enable a nodePort when you deploy integration. An example is `./RestDSL.java.`

You can also optionally decide to just go with the default clusterIP if you do not want your integration to be directly exposed to the outside world. An example of this use case is `./RestDSL2.java`
To run this integrations use:
```shell
kamel run --dev --trait service.enabled=true --trait service.node-port=true RestDSL.java

kubectl port-forward svc/rest-dsl 8080:80
curl http://localhost:8080/hello
```

You can also optionally decide to just go with the default clusterIP if you do not want your integration to be directly exposed to the outside world.

```shell
kamel run --dev --trait service.enabled=true rest-dsl.yaml
```
5 changes: 0 additions & 5 deletions generic-examples/traits/service/RestDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
* limitations under the License.
*/

//
// To run this integrations use:
// kamel run RestDSL.java --trait service.enabled=true\
// --trait service.node-port=true
//
import org.apache.camel.Exchange;

public class RestDSL extends org.apache.camel.builder.RouteBuilder {
Expand Down
35 changes: 0 additions & 35 deletions generic-examples/traits/service/RestDSL2.java

This file was deleted.

24 changes: 24 additions & 0 deletions generic-examples/traits/service/rest-dsl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# camel-k: language=yaml

# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------

- from:
uri: "rest:get:/hello"
steps:
- setBody:
simple: "Hello World"
3 changes: 1 addition & 2 deletions generic-examples/traits/telemetry/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Camel K Telemetry Trait

In this section you will find examples about fine tuning your `Integration` using **Telemetry** `trait` capability.
In this section you will find examples about fine-tuning your `Integration` using **Telemetry** `trait` capability.

The Telemetry trait can be used to automatically publish tracing information of interactions to an OTLP compatible collector.

## Configure and Setup OTLP collector

You can choose which distributed tracing tool you want to use as long as it offers a OTLP compatible collector.


### Configure and Setup Jaeger

Telemetry is compatible with Jaeger version 1.35+.
Expand Down
Loading

0 comments on commit 31de961

Please sign in to comment.