Skip to content

Commit ad4514b

Browse files
authored
Updated the docs (#71)
Updated the docs
1 parent b1cad28 commit ad4514b

File tree

6 files changed

+70
-37
lines changed

6 files changed

+70
-37
lines changed

README.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ Build and run
1414
`go get -u github.com/bookingcom/nanotube`
1515
2. Navigate to it and run
1616
`make`
17+
to build
1718
3. Run it with
1819

19-
`./nanotube -config config/config.toml
20+
```
21+
./nanotube -config config/config.toml
22+
```
23+
24+
Command line options:
25+
26+
```
27+
-config string
28+
Path to config file.
29+
-validate
30+
Validate configuration files.
31+
-version
32+
Print version info.
33+
```
2034

2135
Running with docker-compose
2236
-----------------------------------
@@ -32,7 +46,6 @@ You can feed in sample data with:
3246
```
3347
echo "test1.test 5 $(date +%s)" | nc -c localhost 2003
3448
```
35-
As many netcat implementations exist, a parameter may be needed to instruct it to close the socket once data is sent. Such param will usually be -q0, -c or -N. Refer to your implementation man page.
3649

3750
Get it back with:
3851

@@ -45,15 +58,37 @@ To test the second store (alone or in conjunction) change the metric path to `te
4558
Record structure
4659
----------------
4760

48-
The only supported protocol is [line](https://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol). The records should follow the structure:
61+
The only supported protocol is [line](https://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol). The records have the structure:
4962
```
5063
path.path.path value datetime
5164
```
5265

5366
Config
5467
------
5568

56-
Please refer to the sample configs in the _config_ folder for examples and documentation.
69+
Please refer to the [sample config](config/config.toml) for examples and documentation.
70+
71+
Routing
72+
-------
73+
74+
Is defined in the [rules config](config/rules.toml) that is in turn referred to in the [main config](config/config.toml). This is how it works:
75+
- routing rules are applied to each incoming record in order;
76+
- if regex in a rule matches, the record is sent to the clusters in the `clusters` list;
77+
- if `continue` is `true` continue matching next rules, stop otherwise. `false` is the default;
78+
- if regex does not match, continue down the list of rules;
79+
- multiple rules can be matched to each record;
80+
- each record can be sent to a single cluster at most once. If two rules send it to same cluster, only one instance will be sent;
81+
- cluster names must be from the set defined in the [clusters config](clonfig/clusters.toml);
82+
83+
#### Rewrites
84+
85+
Optionally, it is possible to apply the [rewrite rules](config/rewrite.toml). This is how they work:
86+
87+
- rewrites are applied before the routing;
88+
- all rules are applied to each record one-by-one in order. The record may be modified along the way;
89+
- rule matches if `from` matches;
90+
- then metric path is rewriten to `to` in place;
91+
- if `copy` is `true` the original metric is copied and sent directly to be routed skipping the following re-writes. `copy` is `false` be default.
5792

5893
Record validation and normalization
5994
-----------------------------------
@@ -79,7 +114,7 @@ Tags are not supported for now. See https://github.com/bookingcom/nanotube/issue
79114
Design
80115
------
81116

82-
Please refer to the design doc _docs/design.md_.
117+
Design details are in the design [doc](docs/design.md).
83118

84119

85120
Acknowledgment

config/clusters.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
[[cluster]]
2-
name = "local0"
3-
type = "jump" # cluster type defines routing inside a cluster
2+
name = 'local0'
3+
type = 'jump' # cluster type defines routing inside a cluster
44
[[cluster.hosts]]
5-
name = "localhost" # FQDN or IP of the host
5+
name = 'localhost' # FQDN or IP of the host
66
port = 8001 # optional, overrides setting in main config
77
index = 0 # index in the hash ring
88
[[cluster.hosts]]
9-
name = "localhost"
9+
name = 'localhost'
1010
port = 8002
1111
index = 1
1212

1313
[[cluster]]
14-
name = "local1"
15-
type = "jump"
14+
name = 'local1'
15+
type = 'jump'
1616
[[cluster.hosts]]
17-
name = "localhost"
17+
name = 'localhost'
1818
port = 8101
1919
index = 0
2020
[[cluster.hosts]]
21-
name = "localhost"
21+
name = 'localhost'
2222
port = 8102
2323
index = 1
2424
[[cluster.hosts]]
25-
name = "localhost"
25+
name = 'localhost'
2626
port = 8103
2727
index = 2

config/rewrite.toml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
# Rewrite rules.
2-
# - all rules are applied to each record
3-
# - if rule mathches, metric path is rewriten
4-
# - if copy is true, new metric is created
1+
# E.g.
2+
# In: abcxxx
3+
# Out: cdexxx
4+
[[rewrite]]
5+
from = 'abc'
6+
to = 'cde'
57

8+
# E.g.
9+
# In: xxx.A99.foo.bar
10+
# Out:
11+
# - xxx.foo.bar.A99
12+
# - xxx.A99.foo.bar
613
[[rewrite]]
7-
from = "abc"
8-
to = "cde"
9-
copy = true
14+
from = '^xxx.([A-Za-z0-9_-]+).(.*)'
15+
to = 'xxx.$2.$1'
16+
copy = true
1017

config/rules.toml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
# Routing rules.
2-
# - all routing rules are applied to each incoming record;
3-
# - when regex in the rule matches, the record is sent to the clusters in the "clusters" list;
4-
# - many rules can be matched to each record;
5-
# - each record can be sent to a cluster at most once. If two rules send it to same cluster, only one instance will be sent;
6-
# - cluster names must be from the set defined in the clusters config
7-
# - Continue is used to signal whether to continue matching next set of rules for a record,
8-
# - or by default (or when continue is explicitly set to false), stop and move to next record
9-
101
[[rule]]
112
regexs = [
12-
".*a.*"
3+
'.*a.*'
134
]
145
clusters = [
15-
"local0"
6+
'local0'
167
]
178
continue = true
189

1910
[[rule]]
2011
regexs = [
21-
".*b.*"
12+
'.*b.*'
2213
]
2314
clusters = [
24-
"local1"
15+
'local1'
2516
]
17+

pkg/rewrites/rewrites.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,4 @@ func (rw Rewrites) RewriteMetric(record *rec.Rec) []*rec.Rec {
7777
}
7878
}
7979
return result
80-
8180
}

pkg/rewrites/rewrites_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func TestRewrites(t *testing.T) {
3939
}{
4040
{
4141
rewrites: "first",
42-
in: "abc",
43-
out: []string{"cde"},
42+
in: "abcxxx",
43+
out: []string{"cdexxx"},
4444
},
4545
{
4646
rewrites: "first",

0 commit comments

Comments
 (0)