# Developing the plugin ## Set up As of September 2019, some supported versions of Fluentd uses Ruby 2.1.10p492, so you'll want to use that to develop and test with. * Install rbenv * Install an old version of Ruby: `rbenv install 2.1.0` * Use that older version: `rbenv local 2.1.0` ## Developing * Install Bundler gem: `gem install bundler` * Install dependencies: `bundle install` * Write tests and production code! * Bump version: edit version file `version.rb` * Run tests: `bundle exec rspec` * Build the gem: `gem build newrelic-fluentd-output.gemspec` **NOTE**: Be mindful that using `log.info` in the plugin causes an unintended Sorcerer's Apprentice Syndrome style bug where exponentially larger copies of log messages are sent until the td-agent is unloaded. Super weird, but now you know. ## Testing on MacOS ### Install Fluentd * `brew cask install td-agent` ### Configure Fluentd * `sudo vi /etc/td-agent/td-agent.conf` * Add the following: ``` @type newrelic api_key (your-api-key) @type tail format none path /usr/local/var/log/test.log tag test ``` ### Testing plugin * Stop Fluentd: `sudo launchctl unload /Library/LaunchDaemons/td-agent.plist` * Remove previous version: `sudo /opt/td-agent/usr/sbin/td-agent-gem uninstall fluent-plugin-newrelic` * Add new version: `sudo /opt/td-agent/usr/sbin/td-agent-gem install fluent-plugin-newrelic-.gem` * Start Fluentd: `sudo launchctl load /Library/LaunchDaemons/td-agent.plist` * Make sure things start up OK: `tail -f /var/log/td-agent/td-agent.log` * Cause a change that you've configured Fluentd to pick up: (`echo "FluentdTest" >> /usr/local/var/log/test.log` * Look in `https://one.newrelic.com/launcher/logger.log-launcher` for your log message ("FluentdTest") ## Pushing changes to the public repo After updating the New Relic repo with changes, changes will need to be pushed to the public GitHub repo at: https://github.com/newrelic/newrelic-fluentd-output Make sure you have the public set up as a remote called `public`: ``` git remote add public git@github.com:newrelic/newrelic-fluentd-output.git ``` Sync: ``` git checkout --orphan single-commit-for-public-sync && \ # Remove things we don't want sent to the public-sync repo \ rm grandcentral.yml DEVELOPER.md && \ # Create a single commit and force push it, overwriting the remote master \ git commit -am "Mirrored commit" && \ git push --force public single-commit-for-public-sync:master && \ # Clean up \ git checkout master && \ git branch -D single-commit-for-public-sync ``` # Push changes to RubyGems After updating the source code and gem version in `version.rb`, push the changes to RubyGems. Note, you must be a gem owner to publish changes on [RubyGems.org](https://rubygems.org/profiles/NR-LOGGING) * Build the gem: `gem build newrelic-fluentd-output.gemspec` * Publish the gem: `gem push fluent-plugin-newrelic-.gem` with the updated version (example: `gem push fluent-plugin-newrelic-0.2.2.gem`)