README.md in fluent-plugin-simplearithmetic-0.0.1.pre vs README.md in fluent-plugin-simplearithmetic-0.0.1
- old
+ new
@@ -22,19 +22,19 @@
'time_start': '2001-02-03T04:05:06Z',
'time_finish': '2001-02-03T04:06:12Z',
}
```
-Now you can calculate with this `td-agent.conf`:
+Now you can calculate with this configuration:
```
<match arithmetic.test>
type simple_arithmetic
tag calculated.test
<formulas>
- total_price apple * 200 - orange * 100
+ total_price apple * 200 + orange * 100
# Calculation order is from up to down.
budget 2000 - total_price
# You can also use Time.iso8601
@@ -53,34 +53,92 @@
{
"apple": 7,
"orange": 3,
"time_start": "2001-02-03T04:05:06Z",
"time_finish": "2001-02-03T04:06:12Z",
- "total_price": 1100,
- "budget": 900,
+ "total_price": 1700,
+ "budget": 300,
"time_elapsed": 66.0
}
```
+If some fields are already defined before calculation, these fields will be overwritten.
+
## Configuration
+### tag
+The tag prefix for emitted event messages. Default is `simple_arithmetic`.
### undefined_variables
-1. `nil`
-2. `undefined` (default)
+A message such like `{'a': 20, 'x': 50}` with the formulas:
+```
+<formulas>
+ c a + b
+</formulas>
+```
+
+When undefined_variables is `undefined` (default) you get `{'a': 20, 'x': 50}`. Field `'c'` will not be defined.
+
+When `nil` you get `{'a': 20, 'c': nil, 'x': 50}`.
+
+
### how_to_process_error
-1. `nil`
-2. `undefined`
+A message such like `{'a': 20, 'b': "string"}` with the formulas:
-3. `error_string` (default)
+```
+<formulas>
+ c a + b
+</formulas>
+```
+In ruby, this calculation will be raise an error:
-### tag
-The tag prefix for emitted event messages. Default is `simple_arithmetic`.
+```
+irb(main):052:0* a = 20
+=> 20
+irb(main):053:0> b = "String"
+=> "String"
+irb(main):054:0> c = a + b
+TypeError: String can't be coerced into Fixnum
+ from (irb):54:in `+'
+ from (irb):54
+ from /opt/td-agent/embedded/bin/irb:11:in `<main>'
+```
+
+When how_to_process_error is `nil` you get `{'a': 20, 'b': "string", 'c': nil}`.
+
+When `undefined`, you get `{'a': 20, 'b': "string"}`. If an error is raised in the calculation, the field will not be defined.
+
+When `error_string` (default), you get: `{'a': 20, 'b': "String", 'c'=>"String can't be coerced into Fixnum"}`. An error message will be assigned to the field.
+
+### replace_hyphen, replace_dollar
+
+All formulas will be evaluated as ruby sentences. Some json fields will not be fitted as ruby variables. For example,
+
+```
+<formulas>
+ var-1 a + b
+ var$2 c * d
+</formulas>
+```
+
+will raise an syntax error in the initialize process of fluentd.
+
+To get rid of this case, you can set `replace_hyphen` and `replace_dollar` in the configuration and formulas.
+
+```
+replace_hyphen __H__
+replace_dollar __D__
+
+<formulas>
+ var__H__1 a + b
+ var__D__2 c * d
+</formulas>
+```
## Copyright
Copyright:: Copyright (c) 2014- Takahiro Kamatani