-
Notifications
You must be signed in to change notification settings - Fork 13
Mapping the dimensions #92
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
base: master
Are you sure you want to change the base?
Changes from all commits
2ad542a
04cb0c4
d53e491
d1a75f3
a4a0d37
0828bd6
05954a4
9f3caed
0e49ef7
3c0f5ae
92454bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,6 +285,80 @@ interval="10s" | |
[[inputs.kernel]] | ||
``` | ||
|
||
#### TransformSource | ||
Sometimes you'll want to transform the incoming data before aggregating. | ||
As shown in the example collectd source, it is possible to wrap a source with | ||
another source that will transform the data. The TransformingSource specifies | ||
sets of transformations to apply to the input records, allowing you to add dimensions | ||
to all metrics, remove dimensions from all metrics, and modify metrics based on their | ||
name. | ||
|
||
ex: | ||
```hocon | ||
{ | ||
type="com.arpnetworking.metrics.mad.sources.TransformingSource" | ||
name="transforming_source" | ||
transformations = [ | ||
{ | ||
injectDimensions = { | ||
foo { | ||
value = bar | ||
overwrite = false | ||
} | ||
} | ||
removeDimensions = [ | ||
baz | ||
] | ||
transformMetrics = { | ||
"this" = ["that"] | ||
"extract/([^/]*)/thing" = ["extract/thing/${other_dimension};my_dimension=${1}"] | ||
} | ||
} | ||
] | ||
source { | ||
// your wrapped source goes here | ||
} | ||
} | ||
``` | ||
|
||
tranformations is a list of TransformationSet objects. Each TransformationSet has an inject (Map\<String, DimensionInjection\>), | ||
remove (List\<String\>) and a findAndReplace (Map\<String, List\<String\>\>). | ||
|
||
A DimensionInjection is just a value and a boolean of whether or not to overwrite existing values. Of omitted, overwrite defaults to true. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type-o: |
||
|
||
The keys in findAndReplace are regular expressions used to match metrics. If matched, the list of replacements is | ||
executed, allowing for a single input metric to be recorded multiple times with different names or dimensions. | ||
The format for the values in the list are similar to a standard java regex replacement. Variables are enclosed in ${}, | ||
for example: | ||
```bash | ||
${my_variable} | ||
``` | ||
Variables will be matched in the following order (first match wins): | ||
1. capture group | ||
2. dimension | ||
3. environment variable | ||
|
||
|
||
Variable names may also have a prefix that specifies where the value should originate. For example: | ||
```bash | ||
${capture:my_var} | ||
``` | ||
```bash | ||
${env:MYVAR} | ||
``` | ||
```bash | ||
${dimension:some_dimension} | ||
``` | ||
|
||
This namespacing prevents the built-in precendence search for a matching variable. | ||
|
||
__Note: Any dimensions matched as part of a replacement will be removed from the resulting metric.__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems somewhat surprising. Shouldn't it be kept, and then you can add it to remove if you want to drop it? I understand that's common behavior, but it's going to be harder to express using it and restoring it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removal of dimensions is not on a per-metric basis. The removal applies to all metrics. As for preserving it, it's as simple as "metric/${consumed};consumed=${consumed}". Basically, add it as a dimension with the same value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, that's a weird scoping; why would the removal apply to all metrics but when the extraction only applies to some? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unclear and somewhat surprising since the rule only applies to a particular set of metrics based on the regex match. |
||
|
||
Dimensions can also be injected into a metric. To do this, add a ';' after the replacement name of the metric | ||
and proceed to specify key=value pairs (where both the key and value can use variables). Basically, the | ||
replacement is processed, the string split on ';' with the first part being the metric name and anything | ||
after the ';' being parsed as key=value pairs to be added to the metric's dimensions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do they replace? What if I don't want them to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you didn't want them to replace, why would you put them there? |
||
|
||
Development | ||
----------- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,27 @@ safe_command() { | |
fi | ||
} | ||
|
||
checksum() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. |
||
l_file="$1" | ||
checksum_exec="" | ||
if command -v md5 > /dev/null; then | ||
checksum_exec="md5" | ||
elif command -v sha1sum > /dev/null; then | ||
checksum_exec="sha1sum" | ||
elif command -v shasum > /dev/null; then | ||
checksum_exec="shasum" | ||
fi | ||
if [ -z "${checksum_exec}" ]; then | ||
log_err "ERROR: No supported checksum command found!" | ||
exit 1 | ||
fi | ||
cat "${l_file}" | ${checksum_exec} | ||
} | ||
|
||
rand() { | ||
awk 'BEGIN {srand();printf "%d\n", (rand() * 10^8);}' | ||
} | ||
|
||
download() { | ||
file="$1" | ||
if [ ! -f "${JDKW_PATH}/${file}" ]; then | ||
|
@@ -93,7 +114,10 @@ fi | |
|
||
# Resolve latest version | ||
if [ "${JDKW_RELEASE}" = "latest" ]; then | ||
JDKW_RELEASE=$(curl ${CURL_OPTIONS} -f -k -L -H 'Accept: application/json' "${JDKW_BASE_URI}/releases/latest" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') | ||
latest_version_json="${TMPDIR:-/tmp}/jdkw-latest-version-$$.$(rand)" | ||
safe_command "curl ${CURL_OPTIONS} -f -k -L -o \"${latest_version_json}\" -H 'Accept: application/json' \"${JDKW_BASE_URI}/releases/latest\"" | ||
JDKW_RELEASE=$(cat "${latest_version_json}" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') | ||
rm -f "${latest_version_json}" | ||
log_out "Resolved latest version to ${JDKW_RELEASE}" | ||
fi | ||
|
||
|
@@ -114,7 +138,7 @@ download "${JDKW_WRAPPER}" | |
# Check whether this wrapper is the one specified for this version | ||
jdkw_download="${JDKW_PATH}/${JDKW_WRAPPER}" | ||
jdkw_current="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)/$(basename "$0")" | ||
if [ "$(cat "${jdkw_download}" | sha1sum )" != "$(cat "${jdkw_current}" | sha1sum)" ]; then | ||
if [ "$(checksum "${jdkw_download}")" != "$(checksum "${jdkw_current}")" ]; then | ||
printf "\e[0;31m[WARNING]\e[0m Your jdk-wrapper.sh file does not match the one in your JDKW_RELEASE.\n" | ||
printf "\e[0;32mUpdate your jdk-wrapper.sh to match by running:\e[0m\n" | ||
printf "cp \"%s\" \"%s\"\n" "${jdkw_download}" "${jdkw_current}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t => T
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of escaping, why not put it in ticks for inline code?