Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add capability to also remove prefixes #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ A plugin to connect etsy's statsD to Datadog
datadogApiKey: "your_api_key" // You can get it from this page: https://app.datadoghq.com/account/settings#api
datadogPrefix: "your_prefix" // Your metrics will be prefixed by this prefix
datadogTags: ["your:tag", "another:tag"] // Your metrics will include these tags
datadogRemovePrefix: 2 // Number of period delimited prefixes to remove. If you use this option with *datadogPrefix* remove will happen prior to addition.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a bit of a misleading name, maybe datadogMetricKeyTrim - so that the purpose of the variable is a little bit more clear in that it acts over the key, and that it's a trim operation?

```
### Example:

If the metric name is called **"hosts.foo.bar.count"**, it will be rewritten to **"application.bar.count"**:
```
datadogRemovePrefix: 2
datadogPrefix: "application"
```

## How to enable
Expand Down
11 changes: 8 additions & 3 deletions lib/datadog.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var datadogApiHost;
var datadogApiKey;
var datadogStats = {};
var datadogPrefix;
var datadogRemovePrefix;
var datadogTags;

var Datadog = function(api_key, options) {
Expand Down Expand Up @@ -192,11 +193,14 @@ var flush_stats = function datadog_post_stats(ts, metrics) {
};

var get_prefix = function datadog_get_prefix(key) {
var new_key = key;
if (datadogRemovePrefix !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (datadogRemovePrefix !== undefined) {
if (datadogRemovePrefix !== undefined) && (typeof datadogRemovePrefix == "number") {

new_key = key.split(".").slice(datadogRemovePrefix).join('.');
}
if (datadogPrefix !== undefined) {
return [datadogPrefix, key].join('.');
} else {
return key;
new_key = [datadogPrefix, new_key].join('.');
}
return new_key;
}

var backend_status = function datadog_status(writeCb) {
Expand All @@ -215,6 +219,7 @@ exports.init = function datadog_init(startup_time, config, events, log) {
datadogApiKey = config.datadogApiKey;
datadogApiHost = config.datadogApiHost;
datadogPrefix = config.datadogPrefix;
datadogRemovePrefix = config.datadogRemovePrefix;
datadogTags = config.datadogTags;

if (datadogTags === undefined || datadogTags.constructor !== Array || datadogTags.length < 1) {
Expand Down