From b347f1deda9b8e0d1b55306aba02730246049e43 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 25 Apr 2025 16:33:11 -0400 Subject: [PATCH 01/10] Add devcontainer configuration --- .devcontainer/Dockerfile | 62 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 53 ++++++++++++++++++++++++++++ .vscode/launch.json | 27 ++++++++++++++ .vscode/tasks.json | 54 ++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..b6a250e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,62 @@ +# Use a Ruby image >= 3.1, as required by some dependencies like recent nokogiri +FROM ruby:3.2-slim-bookworm + +# Prevent interactive prompts from apt +ENV DEBIAN_FRONTEND=noninteractive + +# Install system dependencies required for building gems with native extensions +# and for general development. +# - build-essential: For compiling native extensions +# - git: For cloning repos if needed, although VS Code handles the main clone +# - curl, wget: Useful general tools +# - libxml2-dev, libxslt1-dev: Needed by nokogiri gem +# - zlib1g-dev: Needed by many gems +# - sqlite3, libsqlite3-dev: Needed by some gems that might be transitively included +# - libssl-dev: Needed for secure connections, potentially by some gems +# - pkg-config: Build helper +# - make: Used by the Makefile in the repo +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + git \ + curl \ + wget \ + libxml2-dev \ + libxslt1-dev \ + zlib1g-dev \ + sqlite3 \ + libsqlite3-dev \ + libssl-dev \ + pkg-config \ + make \ + zsh \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + + +# (Optional but Recommended) Create a non-root user for development +# This matches the default user setup by Dev Containers 'automatic' creation +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # Add the new user to the sudo group to allow them to run commands with sudo + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(ALL\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + && rm -rf /var/lib/apt/lists/* + +# Set Zsh as the default shell for the non-root user +# Needs to be run as root, after the user is created and zsh is installed +RUN chsh -s $(which zsh) ${USERNAME} + +# Set the default working directory for subsequent commands and where the project code will be mounted +WORKDIR /workspaces + +# Switch to the non-root user +USER $USERNAME + +# The project code will be mounted into /workspaces by Dev Containers. +# Dependencies will be installed via postCreateCommand in devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..be25f55 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,53 @@ +// .devcontainer/devcontainer.json +{ + "name": "Fluent Plugin Datadog Dev", // A friendly name + // Specify the path to the custom Dockerfile + "build": { + "dockerfile": "Dockerfile" + }, + // Use the non-root user created in the Dockerfile + "remoteUser": "vscode", + // Set the workspace folder inside the container + "workspaceFolder": "/workspaces/fluent-plugin-datadog", + // Command to run after the container is created and the workspace is mounted. + // This installs the gem dependencies using Bundler. + "postCreateCommand": "bundle install && sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\"", + // Forward ports that might be useful (e.g., for testing Fluentd) + // Fluentd's default forward port is 24224. The repo's docker-compose also uses this. + "forwardPorts": [ + 24224 + ], + // Configuration specific to VS Code + "customizations": { + "vscode": { + "settings": { + // Optional: Configure Ruby environment settings if needed + "ruby.useBundler": true, + "ruby.lint": { + "rubocop": true + }, + "ruby.format": "rubocop", + // Add other Ruby or general settings here + // Configure VS Code's integrated terminal to use Zsh + "terminal.integrated.defaultProfile.linux": "zsh (2)", + "terminal.integrated.profiles.linux": { + "zsh (2)": { + "path": "zsh" + } + } + }, + // Specify VS Code extensions to install automatically + "extensions": [ + "rebornix.ruby", // Official Ruby extension + "bungcip.better-toml", // For TOML config files + "kaiinui.vscode-ruby-test-explorer", // If you want a test explorer UI + "dbaeumer.vscode-eslint", // If there are JS parts or linting + "redhat.vscode-yaml", // For YAML files (like the docker-compose) + "ms-azuretools.vscode-docker" // Useful for working with Docker inside VS Code + // Add any other extensions relevant to your workflow + ] + } + } + // Uncomment to connect as root instead of the remoteUser. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1a3d11d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Run Fluentd with Datadog Plugin", + "type": "node", + "request": "launch", + "program": "${workspaceFolder}/bin/fluentd", + "args": [ + "-c", + "${workspaceFolder}/test/fluentd.conf", + "-p", + "${workspaceFolder}/lib/fluent/plugin" + ], + "env": { + "FLUENTD_DISABLE_BUNDLER_INJECTION": "1" + } + }, + { + "name": "Run Tests", + "type": "node", + "request": "launch", + "program": "${workspaceFolder}/bin/rake", + "args": ["test"] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..440595e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,54 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Install Dependencies", + "type": "shell", + "command": "bundle install", + "group": "build", + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [] + }, + { + "label": "Build Gem", + "type": "shell", + "command": "gem build fluent-plugin-datadog.gemspec", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [], + "dependsOn": ["Install Dependencies"] + }, + { + "label": "Run Tests", + "type": "shell", + "command": "bundle exec rake test", + "group": "test", + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [] + }, + { + "label": "Build and Test", + "dependsOn": [ + "Install Dependencies", + "Build Gem", + "Run Tests" + ], + "group": { + "kind": "build", + "isDefault": false + } + } + ] +} \ No newline at end of file From e9d925a34cb89d7bdd4c9486d9cd81ab00b1f1be Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 12 May 2025 17:05:59 -0400 Subject: [PATCH 02/10] Fix launch.json and update readme --- .vscode/launch.json | 31 ++++++++++++++++++++----------- README.md | 8 ++++++++ fluent-plugin-datadog.gemspec | 2 ++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1a3d11d..b08c771 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,26 +2,35 @@ "version": "0.2.0", "configurations": [ { - "name": "Run Fluentd with Datadog Plugin", - "type": "node", + "name": "Debug Fluentd with Plugin", + "type": "Ruby", "request": "launch", - "program": "${workspaceFolder}/bin/fluentd", + "program": "/usr/local/bin/bundle", "args": [ + "exec", + "fluentd", "-c", - "${workspaceFolder}/test/fluentd.conf", + "${workspaceFolder}/test/fluentd-test.conf", "-p", "${workspaceFolder}/lib/fluent/plugin" ], - "env": { - "FLUENTD_DISABLE_BUNDLER_INJECTION": "1" - } + "cwd": "${workspaceFolder}", + "showDebuggerOutput": true, + "useBundler": true }, { - "name": "Run Tests", - "type": "node", + "name": "Debug Rake Tests", + "type": "Ruby", "request": "launch", - "program": "${workspaceFolder}/bin/rake", - "args": ["test"] + "program": "/usr/local/bin/bundle", + "args": [ + "exec", + "rake", + "test" + ], + "cwd": "${workspaceFolder}", + "showDebuggerOutput": true, + "useBundler": true } ] } \ No newline at end of file diff --git a/README.md b/README.md index 55c1fba..b05ba5c 100644 --- a/README.md +++ b/README.md @@ -156,3 +156,11 @@ To build a new version of this plugin and push it to RubyGems: `curl -u https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials`, it will ask for your password. +## Development Environment + +This repository includes the files to run it in a devcontainer in VS Code. To use it: + +1. Install VS Code and Docker +2. Open the project in VS Code with the Dev Containers extension. + +VS Code will build and start the container automatically. diff --git a/fluent-plugin-datadog.gemspec b/fluent-plugin-datadog.gemspec index 9acb04d..8214fff 100644 --- a/fluent-plugin-datadog.gemspec +++ b/fluent-plugin-datadog.gemspec @@ -31,6 +31,8 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "yajl-ruby", "~> 1.2" spec.add_development_dependency 'webmock', "~> 3.6.0" + spec.add_development_dependency "ruby-debug-ide" + spec.add_development_dependency "debase" spec.metadata = { 'bug_tracker_uri' => 'https://github.com/DataDog/fluent-plugin-datadog/issues', From 27a71b0f717b34f072dd7f516c226243d55a0f97 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 12 May 2025 17:23:23 -0400 Subject: [PATCH 03/10] CI fix --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 93071b4..15d10d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,10 +14,12 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Configure Bundler to exclude development gems + run: bundle config set --local without development - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0 + ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run tests run: bundle exec rake From ae696faf10654cadf36a6a8e25c0701509ea4273 Mon Sep 17 00:00:00 2001 From: Lucas Liseth <36653792+soberpeach@users.noreply.github.com> Date: Mon, 12 May 2025 17:23:45 -0400 Subject: [PATCH 04/10] Update README.md Co-authored-by: Jen Gilbert --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b05ba5c..66759f3 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ To build a new version of this plugin and push it to RubyGems: ## Development Environment -This repository includes the files to run it in a devcontainer in VS Code. To use it: +This repository includes the files to run it in a dev container in VS Code. To use it: 1. Install VS Code and Docker 2. Open the project in VS Code with the Dev Containers extension. From 3b397f023b449453a1dcfd8161f324c92751015a Mon Sep 17 00:00:00 2001 From: Lucas Liseth <36653792+soberpeach@users.noreply.github.com> Date: Mon, 12 May 2025 17:23:52 -0400 Subject: [PATCH 05/10] Update README.md Co-authored-by: Jen Gilbert --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66759f3..d46bc2a 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ To build a new version of this plugin and push it to RubyGems: This repository includes the files to run it in a dev container in VS Code. To use it: -1. Install VS Code and Docker +1. Install VS Code and Docker. 2. Open the project in VS Code with the Dev Containers extension. VS Code will build and start the container automatically. From faa603b3a1c1bfeb55d39b764cc9f2821ff0ee79 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 12 May 2025 17:25:38 -0400 Subject: [PATCH 06/10] CI fix --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15d10d3..0565d6c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,12 +14,12 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Configure Bundler to exclude development gems - run: bundle config set --local without development - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true + - name: Configure Bundler to exclude development gems + run: bundle config set --local without development - name: Run tests run: bundle exec rake From 56cc3dffa2eda63e015f01dce8bef7819b8b6a2d Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 12 May 2025 17:28:50 -0400 Subject: [PATCH 07/10] More CI fixes --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0565d6c..5c07e37 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,12 +14,17 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true + - name: Configure Bundler to exclude development gems run: bundle config set --local without development + + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run tests run: bundle exec rake From 187c1104c438c00bdd40cb70deddc3c21b40c78e Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 12 May 2025 17:30:54 -0400 Subject: [PATCH 08/10] Add rake as runtime dependency --- fluent-plugin-datadog.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-plugin-datadog.gemspec b/fluent-plugin-datadog.gemspec index 8214fff..a0f88b2 100644 --- a/fluent-plugin-datadog.gemspec +++ b/fluent-plugin-datadog.gemspec @@ -25,10 +25,10 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "fluentd", [">= 1", "< 2"] spec.add_runtime_dependency "net-http-persistent", '~> 4.0.1' + spec.add_runtime_dependency "rake", "~> 12.0" spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "test-unit", '~> 3.1' - spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "yajl-ruby", "~> 1.2" spec.add_development_dependency 'webmock', "~> 3.6.0" spec.add_development_dependency "ruby-debug-ide" From 555ad05a2ea85e787a52213fb50e5d1dda34f53b Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 12 May 2025 17:32:30 -0400 Subject: [PATCH 09/10] Make test-unit runtime dependency --- fluent-plugin-datadog.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-plugin-datadog.gemspec b/fluent-plugin-datadog.gemspec index a0f88b2..6c426b4 100644 --- a/fluent-plugin-datadog.gemspec +++ b/fluent-plugin-datadog.gemspec @@ -26,9 +26,9 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "fluentd", [">= 1", "< 2"] spec.add_runtime_dependency "net-http-persistent", '~> 4.0.1' spec.add_runtime_dependency "rake", "~> 12.0" + spec.add_runtime_dependency "test-unit", "~> 3.1" spec.add_development_dependency "bundler", "~> 2.1" - spec.add_development_dependency "test-unit", '~> 3.1' spec.add_development_dependency "yajl-ruby", "~> 1.2" spec.add_development_dependency 'webmock', "~> 3.6.0" spec.add_development_dependency "ruby-debug-ide" From 23339ce74efb48570a32de092a9b87cf06e4cb17 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 12 May 2025 17:34:04 -0400 Subject: [PATCH 10/10] Add runtime dependency --- fluent-plugin-datadog.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-plugin-datadog.gemspec b/fluent-plugin-datadog.gemspec index 6c426b4..8840cc4 100644 --- a/fluent-plugin-datadog.gemspec +++ b/fluent-plugin-datadog.gemspec @@ -27,10 +27,10 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "net-http-persistent", '~> 4.0.1' spec.add_runtime_dependency "rake", "~> 12.0" spec.add_runtime_dependency "test-unit", "~> 3.1" + spec.add_runtime_dependency "webmock", "~> 3.6.0" spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "yajl-ruby", "~> 1.2" - spec.add_development_dependency 'webmock', "~> 3.6.0" spec.add_development_dependency "ruby-debug-ide" spec.add_development_dependency "debase"