Skip to content

Commit 3592a15

Browse files
authored
Export logs to in-cluster logging (open-telemetry#3217)
1 parent 9272b88 commit 3592a15

13 files changed

+837
-1
lines changed

tests/e2e-openshift/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN mkdir -p /tmp/go/bin $GOCACHE \
1818
&& chmod -R 777 /tmp/go/bin $GOPATH $GOCACHE
1919

2020
# Install dependencies required by test cases and debugging
21-
RUN apt-get update && apt-get install -y jq vim libreadline-dev
21+
RUN apt-get update && apt-get install -y jq vim libreadline-dev unzip
2222

2323
# Install kuttl e2e
2424
RUN curl -LO https://github.com/kudobuilder/kuttl/releases/download/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64 \
@@ -34,5 +34,11 @@ RUN curl -LO https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/la
3434
&& chmod +x oc kubectl \
3535
&& mv oc kubectl /usr/local/bin/
3636

37+
# Install the latest version of logcli
38+
RUN curl -LO https://github.com/grafana/loki/releases/latest/download/logcli-linux-amd64.zip \
39+
&& unzip logcli-linux-amd64.zip \
40+
&& chmod +x logcli-linux-amd64 \
41+
&& mv logcli-linux-amd64 /usr/local/bin/logcli
42+
3743
# Set the working directory
3844
WORKDIR /tmp/opentelemetry-operator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: export-to-cluster-logging-lokistack
5+
spec:
6+
namespace: chainsaw-incllogs
7+
description: Tests shipping of logs to OpenShift in-cluster Logging LokiStack instance using OpenTelemetry collector. The tests requires the Loki, OpenTelemetry and Cluster Observability Operator to be installed along with logcli
8+
steps:
9+
- name: Create the OTEL collector instance
10+
try:
11+
- apply:
12+
file: otel-collector.yaml
13+
- assert:
14+
file: otel-collector-assert.yaml
15+
- name: Install Minio instance
16+
try:
17+
- apply:
18+
file: install-minio.yaml
19+
- assert:
20+
file: install-minio-assert.yaml
21+
- name: Create the LokiStack instance
22+
try:
23+
- apply:
24+
file: install-loki.yaml
25+
- assert:
26+
file: install-loki-assert.yaml
27+
- name: Check the status of LokiStack instance
28+
try:
29+
- script:
30+
timeout: 5m
31+
content: kubectl get --namespace openshift-logging lokistacks logging-loki -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
32+
- name: Enable Logging UI. Not needed by test but can be used for debugging
33+
try:
34+
- apply:
35+
file: logging-uiplugin.yaml
36+
- assert:
37+
file: logging-uiplugin-assert.yaml
38+
- name: Generate logs
39+
try:
40+
- apply:
41+
file: generate-logs.yaml
42+
- assert:
43+
file: generate-logs-assert.yaml
44+
- name: Check logs in LokiStack instance
45+
try:
46+
- script:
47+
timeout: 5m
48+
content: ./check_logs.sh
49+
cleanup:
50+
- delete:
51+
ref:
52+
apiVersion: loki.grafana.com/v1
53+
kind: LokiStack
54+
name: logging-loki
55+
namespace: openshift-logging
56+
- delete:
57+
ref:
58+
apiVersion: v1
59+
kind: PersistentVolumeClaim
60+
labels:
61+
app.kubernetes.io/instance: "logging-loki"
62+
namespace: openshift-logging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
TOKEN=$(oc -n openshift-logging create token otel-collector-deployment)
4+
LOKI_URL=$(oc -n openshift-logging get route logging-loki -o json | jq '.spec.host' -r)
5+
6+
while true; do
7+
LOG_OUTPUT=$(logcli -o raw --tls-skip-verify \
8+
--bearer-token="${TOKEN}" \
9+
--addr "https://${LOKI_URL}/api/logs/v1/application" query '{log_type="application"}')
10+
11+
if echo "$LOG_OUTPUT" | jq -e '
12+
. as $root |
13+
select(
14+
.body == "the message" and
15+
.severity == "Info" and
16+
.attributes.app == "server" and
17+
.resources."k8s.container.name" == "telemetrygen" and
18+
.resources."k8s.namespace.name" == "chainsaw-incllogs"
19+
)
20+
' > /dev/null; then
21+
echo "Logs found:"
22+
break
23+
else
24+
echo "Logs not found. Continuing to check..."
25+
sleep 5
26+
fi
27+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: telemetrygen
5+
namespace: chainsaw-incllogs
6+
status:
7+
active: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: telemetrygen
5+
namespace: chainsaw-incllogs
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: telemetrygen
11+
image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:v0.106.1
12+
args:
13+
- logs
14+
- --otlp-endpoint=otel-collector.openshift-logging.svc.cluster.local:4317
15+
- --otlp-insecure
16+
- --workers=1
17+
- --duration=120s
18+
- --otlp-attributes=k8s.container.name="telemetrygen"
19+
restartPolicy: Never
20+
backoffLimit: 4

0 commit comments

Comments
 (0)