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

Add kafka to logs example #355

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions kafka/connect-plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
confluentinc*
*.zip
Empty file added kafka/connect-plugins/.gitkeep
Empty file.
134 changes: 134 additions & 0 deletions kafka/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Copyright 2023 The original authors
#
# Licensed 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.
#
version: '3.8'
services:
kafka:
image: "confluentinc/cp-kafka:7.5.0"
ports:
- "9092:9092"
container_name: kafka
environment:
KAFKA_NODE_ID: 101
# random cluster ID used for formatting LOG_DIR for KRaft
CLUSTER_ID: 'xtzWWN4bTjitpL3kfd9s5g'
KAFKA_CONTROLLER_QUORUM_VOTERS: '101@kafka:29093'
KAFKA_PROCESS_ROLES: 'broker,controller'
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092'
KAFKA_LISTENERS: 'PLAINTEXT://kafka:29092,PLAINTEXT_HOST://0.0.0.0:9092,CONTROLLER://kafka:29093'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT'
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT'
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: kafka:29092
CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
CONFLUENT_METRICS_ENABLE: 'false'
KAFKA_AUTHORIZER_CLASS_NAME: org.apache.kafka.metadata.authorizer.StandardAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: 'true'
KAFKA_SUPER_USERS: 'User:anonymous'
networks:
- kafka-platform

schema-registry:
image: confluentinc/cp-schema-registry:7.5.0
hostname: schema-registry
container_name: schema-registry
ports:
- "8081:8081"
environment:
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: PLAINTEXT://kafka:29092
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081
depends_on:
- kafka
networks:
- kafka-platform

akhq:
image: tchiotludo/akhq
hostname: akhq
container_name: akhq
depends_on:
- kafka
ports:
- "8087:8080"
environment:
AKHQ_CONFIGURATION: |
akhq:
connections:
docker-kafka-server:
properties:
bootstrap.servers: "kafka:29092"
schema-registry:
url: "http://schema-registry:8081"
connect:
- name: "connect"
url: "http://connect:8083"
networks:
- kafka-platform

otel-collector:
image: otel/opentelemetry-collector-contrib:latest
restart: always
command: ["--config=/etc/otel-collector-config.yaml"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
depends_on:
- kafka
environment:
- LIGHTSTEP_ACCESS_TOKEN=${LIGHTSTEP_ACCESS_TOKEN}
ports:
- "1888:1888" # pprof extension
- "8888:8888" # Prometheus metrics exposed by the collector
- "8889:8889" # Prometheus exporter metrics
- "13133:13133" # health_check extension
- "4317:4317" # OTLP gRPC receiver
- "55679:55679" # zpages extension
networks:
- kafka-platform

connect:
image: confluentinc/cp-kafka-connect:7.5.0
container_name: connect
depends_on:
- kafka
volumes:
- ./connect-plugins:/connect-plugins
ports:
- "8083:8083"
- "8000:8000"
environment:
CONNECT_BOOTSTRAP_SERVERS: 'kafka:29092'
CONNECT_REST_ADVERTISED_HOST_NAME: connect
CONNECT_REST_PORT: 8083
CONNECT_GROUP_ID: kafka-connect
CONNECT_CONFIG_STORAGE_TOPIC: _connect-configs
CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
CONNECT_OFFSET_FLUSH_INTERVAL_MS: 10000
CONNECT_OFFSET_STORAGE_TOPIC: _connect-offsets
CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
CONNECT_STATUS_STORAGE_TOPIC: _connect-status
CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter
CONNECT_VALUE_CONVERTER: org.apache.kafka.connect.storage.StringConverter
CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
CONNECT_PLUGIN_PATH: "/usr/local/share/kafka/plugins,/usr/share/filestream-connectors,/connect-plugins"
networks:
- kafka-platform

networks:
kafka-platform:
driver: bridge
22 changes: 22 additions & 0 deletions kafka/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
receivers:
kafka:
brokers: kafka:29092
topic: example-topic
encoding: json

exporters:
logging:
otlp/ls:
endpoint: ingest.lightstep.com:443
headers:
"lightstep-access-token": "${LIGHTSTEP_ACCESS_TOKEN}"

processors:
batch:

service:
pipelines:
logs:
receivers: [kafka]
processors: [batch]
exporters: [logging, otlp/ls]
17 changes: 17 additions & 0 deletions kafka/plugin-config-elastic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "elasticsearch-sink",
"config": {
"connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
"tasks.max": "1",
"topics": "example-topic",
"key.ignore": "true",
"schema.ignore": "true",
"connection.url": "https://logingest.lightstep.com:443",
"connection.username": "lightstep",
"connection.password": "your-access-token",
"type.name": "_doc",
"name": "elasticsearch-sink",
"value.converter": "org.apache.kafka.connect.json.JsonConverter",
"value.converter.schemas.enable": "false"
}
}
28 changes: 28 additions & 0 deletions kafka/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### Stream logs from Kafka

Streams Kafka topics to ServiceNow Cloud Observability logs

#### Run

1) Download and unzip https://www.confluent.io/hub/confluentinc/kafka-connect-elasticsearch into `connect-plugins/`

2) Run Kafka

```
export LIGHTSTEP_ACCESS_TOKEN=your-token
docker-compose up

# wait a few minutes...
```

3) Configure connector

```
curl -X POST http://localhost:8083/connectors -H 'Content-Type: application/json' -d @plugin-config-elastic.json
```

4) Send some data

```
docker exec -i kafka bash -c "echo '{\"userId\": \"1\", \"action\": \"login\"}' | /usr/bin/kafka-console-producer --broker-list kafka:9092 --topic example-topic"
```
Loading