Skip to content

Commit 1db1b04

Browse files
committed
finalize the developer environment experience
1 parent cc00c4e commit 1db1b04

10 files changed

Lines changed: 195 additions & 186 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,12 @@
1-
# Use a Ruby image >= 3.1, as required by some dependencies like recent nokogiri
2-
FROM ruby:3.2-slim-bookworm
1+
FROM fluent/fluentd:latest
32

4-
# Prevent interactive prompts from apt
53
ENV DEBIAN_FRONTEND=noninteractive
4+
USER root
65

7-
# Install system dependencies required for building gems with native extensions
8-
# and for general development.
9-
# - build-essential: For compiling native extensions
10-
# - git: For cloning repos if needed, although VS Code handles the main clone
11-
# - curl, wget: Useful general tools
12-
# - libxml2-dev, libxslt1-dev: Needed by nokogiri gem
13-
# - zlib1g-dev: Needed by many gems
14-
# - sqlite3, libsqlite3-dev: Needed by some gems that might be transitively included
15-
# - libssl-dev: Needed for secure connections, potentially by some gems
16-
# - pkg-config: Build helper
17-
# - make: Used by the Makefile in the repo
18-
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
RUN apt-get update && apt-get install -y \
197
build-essential \
208
git \
21-
curl \
22-
wget \
23-
libxml2-dev \
24-
libxslt1-dev \
25-
zlib1g-dev \
26-
sqlite3 \
27-
libsqlite3-dev \
28-
libssl-dev \
29-
pkg-config \
30-
make \
31-
zsh \
32-
&& apt-get clean \
33-
&& rm -rf /var/lib/apt/lists/*
9+
curl
3410

35-
36-
# (Optional but Recommended) Create a non-root user for development
37-
# This matches the default user setup by Dev Containers 'automatic' creation
38-
ARG USERNAME=vscode
39-
ARG USER_UID=1000
40-
ARG USER_GID=$USER_UID
41-
42-
RUN groupadd --gid $USER_GID $USERNAME \
43-
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
44-
# Add the new user to the sudo group to allow them to run commands with sudo
45-
&& apt-get update \
46-
&& apt-get install -y sudo \
47-
&& echo $USERNAME ALL=\(ALL\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
48-
&& chmod 0440 /etc/sudoers.d/$USERNAME \
49-
&& rm -rf /var/lib/apt/lists/*
50-
51-
# Set Zsh as the default shell for the non-root user
52-
# Needs to be run as root, after the user is created and zsh is installed
53-
RUN chsh -s $(which zsh) ${USERNAME}
54-
55-
# Set the default working directory for subsequent commands and where the project code will be mounted
5611
WORKDIR /workspaces
5712

58-
# Switch to the non-root user
59-
USER $USERNAME
60-
61-
# The project code will be mounted into /workspaces by Dev Containers.
62-
# Dependencies will be installed via postCreateCommand in devcontainer.json

.devcontainer/devcontainer.json

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,21 @@
11
// .devcontainer/devcontainer.json
22
{
3-
"name": "Fluent Plugin Datadog Dev", // A friendly name
4-
// Specify the path to the custom Dockerfile
3+
"name": "Fluent Plugin Datadog Dev",
54
"build": {
65
"dockerfile": "Dockerfile"
76
},
8-
// Use the non-root user created in the Dockerfile
9-
"remoteUser": "vscode",
10-
// Set the workspace folder inside the container
117
"workspaceFolder": "/workspaces/fluent-plugin-datadog",
12-
// Command to run after the container is created and the workspace is mounted.
13-
// This installs the gem dependencies using Bundler.
14-
"postCreateCommand": "bundle install && sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\"",
15-
// Forward ports that might be useful (e.g., for testing Fluentd)
16-
// Fluentd's default forward port is 24224. The repo's docker-compose also uses this.
17-
"forwardPorts": [
18-
24224
19-
],
20-
// Configuration specific to VS Code
8+
"postCreateCommand": "bundle install --jobs 4 --retry 3",
219
"customizations": {
2210
"vscode": {
23-
"settings": {
24-
// Optional: Configure Ruby environment settings if needed
25-
"ruby.useBundler": true,
26-
"ruby.lint": {
27-
"rubocop": true
28-
},
29-
"ruby.format": "rubocop",
30-
// Add other Ruby or general settings here
31-
// Configure VS Code's integrated terminal to use Zsh
32-
"terminal.integrated.defaultProfile.linux": "zsh (2)",
33-
"terminal.integrated.profiles.linux": {
34-
"zsh (2)": {
35-
"path": "zsh"
36-
}
37-
}
38-
},
39-
// Specify VS Code extensions to install automatically
4011
"extensions": [
41-
"rebornix.ruby", // Official Ruby extension
42-
"bungcip.better-toml", // For TOML config files
43-
"kaiinui.vscode-ruby-test-explorer", // If you want a test explorer UI
44-
"dbaeumer.vscode-eslint", // If there are JS parts or linting
45-
"redhat.vscode-yaml", // For YAML files (like the docker-compose)
46-
"ms-azuretools.vscode-docker" // Useful for working with Docker inside VS Code
47-
// Add any other extensions relevant to your workflow
48-
]
12+
"shopify.ruby-lsp",
13+
"ms-azuretools.vscode-docker"
14+
],
15+
"settings": {
16+
"rubyLsp.bundleExec": true,
17+
"rubyLsp.useBundler": true
18+
}
4919
}
5020
}
51-
// Uncomment to connect as root instead of the remoteUser.
52-
// "remoteUser": "root"
5321
}

.github/workflows/test.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v3
17-
1817
- name: Set up Ruby
1918
uses: ruby/setup-ruby@v1
2019
with:
21-
ruby-version: ${{ matrix.ruby-version }}
22-
23-
- name: Configure Bundler to exclude development gems
24-
run: bundle config set --local without development
25-
26-
- name: Install dependencies
27-
run: bundle install --jobs 4 --retry 3
20+
ruby-version: 3.0
21+
bundler-cache: true
2822

2923
- name: Run tests
3024
run: bundle exec rake

.vscode/launch.json

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,10 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Debug Fluentd with Plugin",
6-
"type": "Ruby",
5+
"type": "ruby_lsp",
76
"request": "launch",
8-
"program": "/usr/local/bin/bundle",
9-
"args": [
10-
"exec",
11-
"fluentd",
12-
"-c",
13-
"${workspaceFolder}/test/fluentd-test.conf",
14-
"-p",
15-
"${workspaceFolder}/lib/fluent/plugin"
16-
],
17-
"cwd": "${workspaceFolder}",
18-
"showDebuggerOutput": true,
19-
"useBundler": true
20-
},
21-
{
22-
"name": "Debug Rake Tests",
23-
"type": "Ruby",
24-
"request": "launch",
25-
"program": "/usr/local/bin/bundle",
26-
"args": [
27-
"exec",
28-
"rake",
29-
"test"
30-
],
31-
"cwd": "${workspaceFolder}",
32-
"showDebuggerOutput": true,
33-
"useBundler": true
7+
"name": "Run Tests",
8+
"program": "bundle exec ruby -Itest test/plugin/test_out_datadog.rb",
349
}
3510
]
3611
}

.vscode/tasks.json

Lines changed: 0 additions & 54 deletions
This file was deleted.

fluent-plugin-datadog.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
2525

2626
spec.add_runtime_dependency "fluentd", [">= 1", "< 2"]
2727
spec.add_runtime_dependency "net-http-persistent", '~> 4.0.1'
28-
28+
2929
spec.add_development_dependency "bundler", "~> 2.1"
3030
spec.add_development_dependency "test-unit", '~> 3.1'
3131
spec.add_development_dependency 'webmock', "~> 3.6.0"

test/TestApp/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# TestApp - Typical Fluentd Usage Example
2+
3+
This directory demonstrates an example of fluentd usage with the Datadog plugin - using configuration files and running Fluentd as a service.
4+
5+
## Files
6+
7+
- **`fluent.conf`** - Fluentd configuration file
8+
- **`start_fluentd.sh`** - Script to start Fluentd with the configuration
9+
- **`send_test_logs.sh`** - Script to send test logs via HTTP (bash)
10+
11+
## Quick Start
12+
13+
### 1. Set your Datadog API Key
14+
15+
```bash
16+
export DD_API_KEY=your_api_key_here
17+
```
18+
19+
### 2. Start Fluentd
20+
21+
```bash
22+
./start_fluentd.sh
23+
```
24+
25+
This starts Fluentd as a service with the configuration file. Fluentd will:
26+
- Listen on HTTP port 8888 for log ingestion
27+
- Listen on Forward port 24224 for Fluentd protocol
28+
- Route logs matching `test.**` to Datadog
29+
30+
### 3. Send Test Logs
31+
32+
In another terminal:
33+
34+
```bash
35+
# Using bash script
36+
./send_test_logs.sh
37+
38+
# Or manually with curl
39+
curl -X POST -d 'json={"message":"Hello from Fluentd"}' \
40+
http://localhost:8888/test.app
41+
```
42+
43+
### 4. Verify Logs
44+
45+
Check your Datadog dashboard to see the logs appear. They should include:
46+
- Original log fields
47+
- Datadog metadata: `ddsource`, `ddtags`, `service`, `hostname`, `tag`, `@timestamp`

test/TestApp/fluent.conf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Typical Fluentd configuration file for Datadog plugin
2+
# This is how Fluentd is typically configured in production
3+
4+
# HTTP input - allows sending logs via HTTP POST
5+
<source>
6+
@type http
7+
port 8888
8+
bind 0.0.0.0
9+
</source>
10+
11+
# Forward input - allows sending logs via Fluentd forward protocol
12+
<source>
13+
@type forward
14+
port 24224
15+
bind 0.0.0.0
16+
</source>
17+
18+
# Match events and send them to Datadog
19+
<match test.**>
20+
@type datadog
21+
@id datadog_output
22+
api_key YOUR_API_KEY_HERE
23+
24+
# Optional configuration
25+
include_tag_key true
26+
tag_key 'tag'
27+
service 'fluentd-test-app'
28+
dd_source 'ruby'
29+
dd_tags 'env:test,app:testapp'
30+
31+
<buffer>
32+
@type memory
33+
flush_interval 3s
34+
chunk_limit_size 5m
35+
chunk_limit_records 500
36+
</buffer>
37+
</match>
38+

test/TestApp/send_test_logs.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# Unless explicitly stated otherwise all files in this repository are licensed
3+
# under the Apache License Version 2.0.
4+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
5+
# Copyright 2018 Datadog, Inc.
6+
7+
# Script to send test logs to Fluentd via HTTP
8+
# This demonstrates typical usage - sending logs to Fluentd's HTTP endpoint
9+
10+
FLUENTD_URL="${FLUENTD_URL:-http://localhost:8888}"
11+
TAG="${TAG:-test.app}"
12+
13+
echo "Sending test logs to Fluentd at ${FLUENTD_URL}"
14+
echo "Tag: ${TAG}"
15+
echo ""
16+
17+
# Send test log 1
18+
echo "Sending log 1: Test message"
19+
curl -X POST -d 'json={"message":"Test log message from TestApp","level":"info","user":"test_user","action":"test_action"}' \
20+
"${FLUENTD_URL}/${TAG}"
21+
22+
echo ""
23+
echo ""
24+
25+
# Send test log 2
26+
echo "Sending log 2: Debug message"
27+
curl -X POST -d 'json={"message":"Another test message","level":"debug","component":"test_component","status":"success"}' \
28+
"${FLUENTD_URL}/${TAG}"
29+
30+
echo ""
31+
echo ""
32+
33+
# Send test log 3
34+
echo "Sending log 3: Error simulation"
35+
curl -X POST -d 'json={"message":"Error simulation","level":"error","error_code":"TEST_ERROR","stack_trace":"test_stack_trace"}' \
36+
"${FLUENTD_URL}/${TAG}"
37+
38+
echo ""
39+
echo ""
40+
echo "Check Fluentd output or Datadog dashboard to verify logs were received."
41+

0 commit comments

Comments
 (0)