From 06e7228041f139bae47e4fd0c97ed27bff2e3619 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Thu, 5 Dec 2024 14:43:39 +0000 Subject: [PATCH] Add HTTP input to Fluent Bit configuration and expose port 8889 for telemetry ingestion --- Common/Server/Middleware/TelemetryIngest.ts | 2 ++ FluentBit/Dockerfile.tpl | 1 + FluentBit/README.md | 28 +++++++++++++++++++++ FluentBit/etc/fluent-bit.yaml | 18 +++++++++---- OpenTelemetryIngest/API/OTelIngest.ts | 1 + docker-compose.dev.yml | 1 + 6 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 FluentBit/README.md diff --git a/Common/Server/Middleware/TelemetryIngest.ts b/Common/Server/Middleware/TelemetryIngest.ts index f4fe00bf07..9e91b6f3e5 100644 --- a/Common/Server/Middleware/TelemetryIngest.ts +++ b/Common/Server/Middleware/TelemetryIngest.ts @@ -23,6 +23,8 @@ export default class TelemetryIngest { try { // check header. + debugger; + let oneuptimeToken: string | undefined = req.headers[ "x-oneuptime-token" ] as string | undefined; diff --git a/FluentBit/Dockerfile.tpl b/FluentBit/Dockerfile.tpl index d80c522cc5..1be172c48b 100644 --- a/FluentBit/Dockerfile.tpl +++ b/FluentBit/Dockerfile.tpl @@ -6,5 +6,6 @@ USER root EXPOSE 24224 EXPOSE 24284 EXPOSE 2020 +EXPOSE 8889 CMD ["/fluent-bit/bin/fluent-bit", "-c", "/fluent-bit/etc/fluent-bit.yaml"] \ No newline at end of file diff --git a/FluentBit/README.md b/FluentBit/README.md new file mode 100644 index 0000000000..872a7f0f37 --- /dev/null +++ b/FluentBit/README.md @@ -0,0 +1,28 @@ +# Fluentd + +This guide will help you test fluent-bit logs with OneUptime. + +## Prerequisites + +- Filuentd docker container running on your system (essentially this folder should be running). + You can run the container using the command `npm run dev fluent-bit` +- OneUptime account +- OneUptime project +- Telemetry Ingestion Key (Create one from the OneUptime dashboard, Click on More -> Project Settings -> Telemetry Ingestion Key) + + +## Configuration and Testing + +- Please make sure the correct token and url is in the configuration file located at `FluentBut/etc/fluent-bit.yaml`. +- Build the docker image using the command `npm run force-build fluent-bit` +- Run the docker image using the command `npm run dev fluent-bit` +- Send logs to the Fluentd container using the curl command + +```bash +curl -X POST -H "Content-Type: application/json" -d '{"log": "This is a test log message"}' http://localhost:8889 +``` + +You should be able to see the logs in the OneUptime dashboard. + + + diff --git a/FluentBit/etc/fluent-bit.yaml b/FluentBit/etc/fluent-bit.yaml index 273765a1be..cadcd76894 100644 --- a/FluentBit/etc/fluent-bit.yaml +++ b/FluentBit/etc/fluent-bit.yaml @@ -1,14 +1,22 @@ service: flush: 1 log_level: info - http_server: true - http_listen: 0.0.0.0 - http_port: 2020 pipeline: inputs: - - name: random + - name: http + listen: 0.0.0.0 + port: 8889 outputs: - name: stdout - match: '*' \ No newline at end of file + match: '*' + - name: opentelemetry + match: '*' + host: 'otel-collector' + port: 4318 + header: + - x-oneuptime-token aaa670e0-ac15-11ef-9e8b-0bf23dab1c65 + - x-oneuptime-service-name fluent-bit + + diff --git a/OpenTelemetryIngest/API/OTelIngest.ts b/OpenTelemetryIngest/API/OTelIngest.ts index 207962e899..77cab27743 100644 --- a/OpenTelemetryIngest/API/OTelIngest.ts +++ b/OpenTelemetryIngest/API/OTelIngest.ts @@ -88,6 +88,7 @@ class OpenTelemetryRequestMiddleware { } productType = ProductType.Traces; } else if (req.url.includes("/otlp/v1/logs")) { + debugger; if (isProtobuf) { req.body = LogsData.decode(req.body); } diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 0d4aea99ba..52598c15f4 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -430,6 +430,7 @@ services: - 24225:24224 - 24285:24284 - 2020:2020 + - 8889:8889 extends: file: ./docker-compose.base.yml service: fluent-bit