Wondering how to get commit notifications from Gitlab into Datadog?
There isn’t an official integration from Datadog - but with a small ruby app running on an Iron.io worker, you can create events in your Datadog Event stream when code is committed to your Gitlab repository.
You need a few things to make this happen:
- A free Iron.io account - signup here.
- A Ruby environment > 1.9 where you can install some gems.
- Access to your Gitlab repository Web Hooks page.
- An API key from your Datadog account - get it here.
Let’s install the gems you’ll need:
gem install iron_worker_ng
Now, create an Iron.io Project - I’ve called mine gitlab2datadog-demo
.
After it’s created, click on the “Worker” button:
Grab the iron.json credentials, so the gem knows how to upload your code:
Let’s grab some code to create our worker:
git clone https://github.com/darron/iron_worker_examples.git
cd iron_worker_examples/ruby_ng/gitlab_to_datadog_webhook_worker/
Put the iron.json
file into the iron_worker_examples/ruby_ng/gitlab_to_datadog_webhook_worker/
folder.
Now create a datadog.yml
file in the same folder:
datadog:
api_key: "not-my-real-key"
Using the gem we installed, upload your code to Iron.io:
iron_worker upload gitlab_to_datadog
Pay attention to the output from this command - it should look something like this:
------> Creating client
Project 'gitlab2datadog-demo' with id='54d2dbd42f5b4f6544245355'
------> Creating code package
Found workerfile with path='gitlab_to_datadog.worker'
Merging file with path='datadog.yml' and dest=''
Detected exec with path='gitlab_to_datadog.rb' and args='{}'
Adding ruby gem dependency with name='dogapi' and version='>= 0'
Code package name is 'gitlab_to_datadog'
------> Uploading and building code package 'gitlab_to_datadog'
Remote building worker
Code package uploaded with id='54d2dfc06485e3c433b04d431fd' and revision='1'
Check 'https://hud.iron.io/tq/projects/54d2dbd42f5b4f000937965555/code/58d2dfc1675e3c433b04975d' for more info
Follow the link that’s provided in the output - you should see the webhook URL:
Click the field to show the URL, copy that URL and then paste it into the Gitlab webhooks area:
Click “Add Web Hook” and if it works as planned - you’ll have a “Test Hook” button to try out:
This is what I see in my Datadog Events stream now:
This is a simple way to get commit notifications into Datadog, the other types of web hooks aren’t currently covered, but the code is simple enough to be adjusted.
Thanks to Iron.io for providing the original repository of examples.
I have a whole bunch of other projects in mind that could use Iron.io - glad I found this little project to try it out with!