utracker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +21 -0
- data/Rakefile +5 -0
- data/examples/services.out +122 -0
- data/examples/services.rb +113 -0
- data/lib/utracker.rb +51 -0
- data/lib/utracker/logger.rb +27 -0
- data/lib/utracker/logger/stdout_logger.rb +19 -0
- data/lib/utracker/message.rb +49 -0
- data/lib/utracker/version.rb +3 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/utracker/logger/event_spec.rb +18 -0
- data/spec/utracker/logger_spec.rb +38 -0
- data/spec/utracker/message/logging_spec.rb +29 -0
- data/spec/utracker/message_spec.rb +69 -0
- data/spec/utracker_spec.rb +66 -0
- data/utracker.gemspec +28 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4ee4c98911ffef4acc63f4a59993a7993fa0c2f
|
4
|
+
data.tar.gz: f13b2bfeba7ca0d2203456041d15ba95eb7846b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd6d3ec4c8e7b2dfd79dea5f9f0c19caae604643e49a086a8a22eabc7e6b08fc13f6f1d06bef22e38ee0133af7fd1c033f67d2c2d932b1e10895df116aecfdd8
|
7
|
+
data.tar.gz: 766d32f041b8f10dfb3772667304f3730da9c86ae1553e4b6801e28206b55f8b53e1f5409845f023e33d5190cc2c3d791b29118e2c5f0f7f3b9b832f6adb9fa0
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Nicolas Zermati
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Micro-tracker
|
2
|
+
|
3
|
+
[](https://travis-ci.org/nicoolas25/micro-tracker)
|
4
|
+
[](https://codeclimate.com/github/nicoolas25/micro-tracker)
|
5
|
+
[](https://codeclimate.com/github/nicoolas25/micro-tracker)
|
6
|
+
|
7
|
+
Modern web application are more and more designed with micro-services. Those services exchange messages in order to communicate with each other. Eventually your architecture ends with a graph of services that could be quite complex. Micro-tracker is all about tracking this micro-service's interactions in order to know which service received which message, when and from which other service. It will help you monitor your architecture and debug faster.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
* [x] Assign an unique identifier to each packed message.
|
12
|
+
* [x] Retrieve the unique identifier when the message in unpacked.
|
13
|
+
* [x] Log events concerning a message.
|
14
|
+
* [x] Create messages using a parent message.
|
15
|
+
* [x] Allow to filter the payload in logs.
|
16
|
+
|
17
|
+
## Useful tools on top of this
|
18
|
+
|
19
|
+
* [ ] Broken service alert
|
20
|
+
* [ ] Scaling advisor
|
21
|
+
* [ ] Replay messages after a failure
|
data/Rakefile
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
{"datetime":"2015-03-07 17:53:28 +0100","service":"bob","description":"seeding","uuid":"7603cd5a-d5bb-4524-a1f8-3ac8f7177592","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
2
|
+
{"datetime":"2015-03-07 17:53:28 +0100","service":"carl","description":"seeding","uuid":"15eb6c10-af13-44fa-ae7d-d76d4f7729e7","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
3
|
+
{"datetime":"2015-03-07 17:53:28 +0100","service":"alice","description":"handle","uuid":"7603cd5a-d5bb-4524-a1f8-3ac8f7177592","parent_uuid":null,"payload":null}
|
4
|
+
{"datetime":"2015-03-07 17:53:28 +0100","service":"alice","description":"reply","uuid":"ceec2889-77ab-451b-a119-0dc717551a6c","parent_uuid":"7603cd5a-d5bb-4524-a1f8-3ac8f7177592","payload":"Unleash the kraken!"}
|
5
|
+
{"datetime":"2015-03-07 17:53:29 +0100","service":"carl","description":"seeding","uuid":"e29d7d4f-3163-4923-ac16-b007b1c659a5","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
6
|
+
{"datetime":"2015-03-07 17:53:29 +0100","service":"bob","description":"handle","uuid":"15eb6c10-af13-44fa-ae7d-d76d4f7729e7","parent_uuid":null,"payload":null}
|
7
|
+
{"datetime":"2015-03-07 17:53:29 +0100","service":"bob","description":"handle","uuid":"ceec2889-77ab-451b-a119-0dc717551a6c","parent_uuid":"7603cd5a-d5bb-4524-a1f8-3ac8f7177592","payload":null}
|
8
|
+
{"datetime":"2015-03-07 17:53:29 +0100","service":"bob","description":"handle","uuid":"e29d7d4f-3163-4923-ac16-b007b1c659a5","parent_uuid":null,"payload":null}
|
9
|
+
{"datetime":"2015-03-07 17:53:29 +0100","service":"alice","description":"seeding","uuid":"245ddf65-c921-4731-a60d-2b5d28cad8e0","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
10
|
+
{"datetime":"2015-03-07 17:53:29 +0100","service":"carl","description":"seeding","uuid":"39f30422-ee7e-4469-8333-0196a6808d5c","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
11
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"handle","uuid":"245ddf65-c921-4731-a60d-2b5d28cad8e0","parent_uuid":null,"payload":null}
|
12
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"handle","uuid":"39f30422-ee7e-4469-8333-0196a6808d5c","parent_uuid":null,"payload":null}
|
13
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"reply","uuid":"9e6f9b3f-f833-4746-9e6f-c632efd336a8","parent_uuid":"39f30422-ee7e-4469-8333-0196a6808d5c","payload":"Unleash the kraken!"}
|
14
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"alice","description":"seeding","uuid":"f59aef5d-0c06-4d6a-9cd2-8e7070811986","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
15
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"seeding","uuid":"705f73cc-8536-48a1-a7ba-cacc14b030f9","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
16
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"handle","uuid":"9e6f9b3f-f833-4746-9e6f-c632efd336a8","parent_uuid":"39f30422-ee7e-4469-8333-0196a6808d5c","payload":null}
|
17
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"reply","uuid":"96868291-38bf-4df7-92c2-0fa3a5096ec6","parent_uuid":"9e6f9b3f-f833-4746-9e6f-c632efd336a8","payload":"Unleash the kraken!"}
|
18
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"handle","uuid":"f59aef5d-0c06-4d6a-9cd2-8e7070811986","parent_uuid":null,"payload":null}
|
19
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"reply","uuid":"2f0a5201-08c1-499c-bb13-118c471bd606","parent_uuid":"f59aef5d-0c06-4d6a-9cd2-8e7070811986","payload":"Unleash the kraken!"}
|
20
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"handle","uuid":"705f73cc-8536-48a1-a7ba-cacc14b030f9","parent_uuid":null,"payload":null}
|
21
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"reply","uuid":"06b6b7c1-82aa-46cc-8109-ad6c5ab28e46","parent_uuid":"705f73cc-8536-48a1-a7ba-cacc14b030f9","payload":"Unleash the kraken!"}
|
22
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"handle","uuid":"2f0a5201-08c1-499c-bb13-118c471bd606","parent_uuid":"f59aef5d-0c06-4d6a-9cd2-8e7070811986","payload":null}
|
23
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"reply","uuid":"325da575-195e-4ef0-aac8-d1f9c7fe569d","parent_uuid":"2f0a5201-08c1-499c-bb13-118c471bd606","payload":"Unleash the kraken!"}
|
24
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"handle","uuid":"06b6b7c1-82aa-46cc-8109-ad6c5ab28e46","parent_uuid":"705f73cc-8536-48a1-a7ba-cacc14b030f9","payload":null}
|
25
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"reply","uuid":"339ebac6-9b11-48cc-bf3c-6130a13308db","parent_uuid":"06b6b7c1-82aa-46cc-8109-ad6c5ab28e46","payload":"Unleash the kraken!"}
|
26
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"handle","uuid":"339ebac6-9b11-48cc-bf3c-6130a13308db","parent_uuid":"06b6b7c1-82aa-46cc-8109-ad6c5ab28e46","payload":null}
|
27
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"carl","description":"reply","uuid":"2a9a827c-4bc8-4990-8d5a-311603cf7be7","parent_uuid":"339ebac6-9b11-48cc-bf3c-6130a13308db","payload":"Unleash the kraken!"}
|
28
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"handle","uuid":"2a9a827c-4bc8-4990-8d5a-311603cf7be7","parent_uuid":"339ebac6-9b11-48cc-bf3c-6130a13308db","payload":null}
|
29
|
+
{"datetime":"2015-03-07 17:53:30 +0100","service":"bob","description":"reply","uuid":"2732845d-4092-437b-b77b-9bd7e5cc889d","parent_uuid":"2a9a827c-4bc8-4990-8d5a-311603cf7be7","payload":"Unleash the kraken!"}
|
30
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"alice","description":"handle","uuid":"96868291-38bf-4df7-92c2-0fa3a5096ec6","parent_uuid":"9e6f9b3f-f833-4746-9e6f-c632efd336a8","payload":null}
|
31
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"alice","description":"reply","uuid":"cce72675-249b-41ce-a6be-b85528ba4d9d","parent_uuid":"96868291-38bf-4df7-92c2-0fa3a5096ec6","payload":"Unleash the kraken!"}
|
32
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"alice","description":"handle","uuid":"325da575-195e-4ef0-aac8-d1f9c7fe569d","parent_uuid":"2f0a5201-08c1-499c-bb13-118c471bd606","payload":null}
|
33
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"alice","description":"handle","uuid":"2732845d-4092-437b-b77b-9bd7e5cc889d","parent_uuid":"2a9a827c-4bc8-4990-8d5a-311603cf7be7","payload":null}
|
34
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"carl","description":"seeding","uuid":"406035d8-92be-4823-890c-35e2318bd93e","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
35
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"alice","description":"seeding","uuid":"50e177a7-add9-4772-94c3-9b31e6fafdc9","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
36
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"bob","description":"handle","uuid":"cce72675-249b-41ce-a6be-b85528ba4d9d","parent_uuid":"96868291-38bf-4df7-92c2-0fa3a5096ec6","payload":null}
|
37
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"bob","description":"handle","uuid":"406035d8-92be-4823-890c-35e2318bd93e","parent_uuid":null,"payload":null}
|
38
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"alice","description":"seeding","uuid":"1120b8ba-fed5-4b18-a0f0-d8e25b06d6eb","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
39
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"bob","description":"handle","uuid":"1120b8ba-fed5-4b18-a0f0-d8e25b06d6eb","parent_uuid":null,"payload":null}
|
40
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"bob","description":"reply","uuid":"08cf626a-497b-4152-bb8c-bc8ddef3beac","parent_uuid":"1120b8ba-fed5-4b18-a0f0-d8e25b06d6eb","payload":"Unleash the kraken!"}
|
41
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"bob","description":"seeding","uuid":"4f4eb765-8cd5-438e-a86c-59939d47e619","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
42
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"bob","description":"seeding","uuid":"c95438f5-2f2b-410b-8b16-5ea337539442","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
43
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"alice","description":"handle","uuid":"08cf626a-497b-4152-bb8c-bc8ddef3beac","parent_uuid":"1120b8ba-fed5-4b18-a0f0-d8e25b06d6eb","payload":null}
|
44
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"carl","description":"handle","uuid":"50e177a7-add9-4772-94c3-9b31e6fafdc9","parent_uuid":null,"payload":null}
|
45
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"carl","description":"handle","uuid":"4f4eb765-8cd5-438e-a86c-59939d47e619","parent_uuid":null,"payload":null}
|
46
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"carl","description":"handle","uuid":"c95438f5-2f2b-410b-8b16-5ea337539442","parent_uuid":null,"payload":null}
|
47
|
+
{"datetime":"2015-03-07 17:53:31 +0100","service":"carl","description":"reply","uuid":"ea2b9e63-369d-47b3-9838-0ad06bce9172","parent_uuid":"c95438f5-2f2b-410b-8b16-5ea337539442","payload":"Unleash the kraken!"}
|
48
|
+
{"datetime":"2015-03-07 17:53:32 +0100","service":"alice","description":"handle","uuid":"ea2b9e63-369d-47b3-9838-0ad06bce9172","parent_uuid":"c95438f5-2f2b-410b-8b16-5ea337539442","payload":null}
|
49
|
+
{"datetime":"2015-03-07 17:53:32 +0100","service":"bob","description":"seeding","uuid":"49699852-af43-4b2d-b379-b4b73582b6bc","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
50
|
+
{"datetime":"2015-03-07 17:53:32 +0100","service":"bob","description":"seeding","uuid":"36f365d7-e898-480e-b8f6-79f8d08563fa","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
51
|
+
{"datetime":"2015-03-07 17:53:32 +0100","service":"carl","description":"handle","uuid":"49699852-af43-4b2d-b379-b4b73582b6bc","parent_uuid":null,"payload":null}
|
52
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"alice","description":"handle","uuid":"36f365d7-e898-480e-b8f6-79f8d08563fa","parent_uuid":null,"payload":null}
|
53
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"alice","description":"reply","uuid":"b2f41e71-29ae-4b5c-b4b4-9bd6266627f3","parent_uuid":"36f365d7-e898-480e-b8f6-79f8d08563fa","payload":"Unleash the kraken!"}
|
54
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"carl","description":"handle","uuid":"b2f41e71-29ae-4b5c-b4b4-9bd6266627f3","parent_uuid":"36f365d7-e898-480e-b8f6-79f8d08563fa","payload":null}
|
55
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"carl","description":"reply","uuid":"d7b27970-440f-4e66-bc91-71280bedda09","parent_uuid":"b2f41e71-29ae-4b5c-b4b4-9bd6266627f3","payload":"Unleash the kraken!"}
|
56
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"bob","description":"seeding","uuid":"bf7875fe-47b0-474d-a7b4-4ac1213d45f7","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
57
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"alice","description":"handle","uuid":"d7b27970-440f-4e66-bc91-71280bedda09","parent_uuid":"b2f41e71-29ae-4b5c-b4b4-9bd6266627f3","payload":null}
|
58
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"alice","description":"handle","uuid":"bf7875fe-47b0-474d-a7b4-4ac1213d45f7","parent_uuid":null,"payload":null}
|
59
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"alice","description":"reply","uuid":"eb990e42-d696-408f-abbf-ae59e1fad48f","parent_uuid":"bf7875fe-47b0-474d-a7b4-4ac1213d45f7","payload":"Unleash the kraken!"}
|
60
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"alice","description":"seeding","uuid":"62621a3c-421d-4522-b350-eff01a16b124","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
61
|
+
{"datetime":"2015-03-07 17:53:33 +0100","service":"carl","description":"seeding","uuid":"3101a633-e149-44f2-9ef5-242b79bf71aa","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
62
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"alice","description":"seeding","uuid":"6da9a2de-f5aa-445f-b33a-5934ce83f7e1","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
63
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"alice","description":"seeding","uuid":"cb1f35cd-4377-4385-93f3-50654496882d","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
64
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"carl","description":"seeding","uuid":"aa89a165-fce7-4bf2-becf-092637a8d580","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
65
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"handle","uuid":"eb990e42-d696-408f-abbf-ae59e1fad48f","parent_uuid":"bf7875fe-47b0-474d-a7b4-4ac1213d45f7","payload":null}
|
66
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"reply","uuid":"41ad3d87-798a-411f-a5c9-80b9b3d1cd8f","parent_uuid":"eb990e42-d696-408f-abbf-ae59e1fad48f","payload":"Unleash the kraken!"}
|
67
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"handle","uuid":"62621a3c-421d-4522-b350-eff01a16b124","parent_uuid":null,"payload":null}
|
68
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"reply","uuid":"29ecd3dc-7808-4367-9c17-67aca0b6af6a","parent_uuid":"62621a3c-421d-4522-b350-eff01a16b124","payload":"Unleash the kraken!"}
|
69
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"handle","uuid":"3101a633-e149-44f2-9ef5-242b79bf71aa","parent_uuid":null,"payload":null}
|
70
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"handle","uuid":"6da9a2de-f5aa-445f-b33a-5934ce83f7e1","parent_uuid":null,"payload":null}
|
71
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"handle","uuid":"cb1f35cd-4377-4385-93f3-50654496882d","parent_uuid":null,"payload":null}
|
72
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"reply","uuid":"495ff98d-5d22-4453-ab1d-aca353a1ebb9","parent_uuid":"cb1f35cd-4377-4385-93f3-50654496882d","payload":"Unleash the kraken!"}
|
73
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"handle","uuid":"aa89a165-fce7-4bf2-becf-092637a8d580","parent_uuid":null,"payload":null}
|
74
|
+
{"datetime":"2015-03-07 17:53:34 +0100","service":"bob","description":"seeding","uuid":"b79df28f-520c-4c71-8626-ec538deb334a","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
75
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"alice","description":"handle","uuid":"495ff98d-5d22-4453-ab1d-aca353a1ebb9","parent_uuid":"cb1f35cd-4377-4385-93f3-50654496882d","payload":null}
|
76
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"alice","description":"handle","uuid":"b79df28f-520c-4c71-8626-ec538deb334a","parent_uuid":null,"payload":null}
|
77
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"carl","description":"handle","uuid":"41ad3d87-798a-411f-a5c9-80b9b3d1cd8f","parent_uuid":"eb990e42-d696-408f-abbf-ae59e1fad48f","payload":null}
|
78
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"carl","description":"handle","uuid":"29ecd3dc-7808-4367-9c17-67aca0b6af6a","parent_uuid":"62621a3c-421d-4522-b350-eff01a16b124","payload":null}
|
79
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"bob","description":"seeding","uuid":"fa8c079d-c17b-487a-926e-93141994fd7a","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
80
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"carl","description":"handle","uuid":"fa8c079d-c17b-487a-926e-93141994fd7a","parent_uuid":null,"payload":null}
|
81
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"alice","description":"seeding","uuid":"a3b29277-692a-454a-b0a0-9b159d98ab7c","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
82
|
+
{"datetime":"2015-03-07 17:53:35 +0100","service":"bob","description":"seeding","uuid":"1784a058-7a29-4d26-a048-5579524ad642","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
83
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"carl","description":"handle","uuid":"a3b29277-692a-454a-b0a0-9b159d98ab7c","parent_uuid":null,"payload":null}
|
84
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"carl","description":"reply","uuid":"bc63b3c5-f047-48e4-a061-d6945b55715c","parent_uuid":"a3b29277-692a-454a-b0a0-9b159d98ab7c","payload":"Unleash the kraken!"}
|
85
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"bob","description":"handle","uuid":"bc63b3c5-f047-48e4-a061-d6945b55715c","parent_uuid":"a3b29277-692a-454a-b0a0-9b159d98ab7c","payload":null}
|
86
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"bob","description":"reply","uuid":"5f2bf717-9801-4407-888a-b0588ddedb46","parent_uuid":"bc63b3c5-f047-48e4-a061-d6945b55715c","payload":"Unleash the kraken!"}
|
87
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"bob","description":"seeding","uuid":"6777cd1e-16ce-4f77-8490-19565eb28ac4","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
88
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"alice","description":"handle","uuid":"1784a058-7a29-4d26-a048-5579524ad642","parent_uuid":null,"payload":null}
|
89
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"alice","description":"reply","uuid":"c9766eda-6e48-483f-b5ad-b00daca6dbfc","parent_uuid":"1784a058-7a29-4d26-a048-5579524ad642","payload":"Unleash the kraken!"}
|
90
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"alice","description":"handle","uuid":"5f2bf717-9801-4407-888a-b0588ddedb46","parent_uuid":"bc63b3c5-f047-48e4-a061-d6945b55715c","payload":null}
|
91
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"alice","description":"reply","uuid":"61970d7a-f0b8-40de-a3cc-80d2e2711bbb","parent_uuid":"5f2bf717-9801-4407-888a-b0588ddedb46","payload":"Unleash the kraken!"}
|
92
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"bob","description":"handle","uuid":"61970d7a-f0b8-40de-a3cc-80d2e2711bbb","parent_uuid":"5f2bf717-9801-4407-888a-b0588ddedb46","payload":null}
|
93
|
+
{"datetime":"2015-03-07 17:53:36 +0100","service":"bob","description":"seeding","uuid":"71f0e7b8-e14e-4037-997c-aa5f74a54c8f","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
94
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"carl","description":"handle","uuid":"6777cd1e-16ce-4f77-8490-19565eb28ac4","parent_uuid":null,"payload":null}
|
95
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"carl","description":"reply","uuid":"637a5251-fd82-4a6f-8dff-24942ea0221f","parent_uuid":"6777cd1e-16ce-4f77-8490-19565eb28ac4","payload":"Unleash the kraken!"}
|
96
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"carl","description":"handle","uuid":"c9766eda-6e48-483f-b5ad-b00daca6dbfc","parent_uuid":"1784a058-7a29-4d26-a048-5579524ad642","payload":null}
|
97
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"carl","description":"handle","uuid":"71f0e7b8-e14e-4037-997c-aa5f74a54c8f","parent_uuid":null,"payload":null}
|
98
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"alice","description":"seeding","uuid":"9efbffe6-b66e-4a04-9fbc-9796d67de36d","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
99
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"carl","description":"seeding","uuid":"c003f62c-8991-46b4-9c63-04aa9a082302","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
100
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"bob","description":"handle","uuid":"637a5251-fd82-4a6f-8dff-24942ea0221f","parent_uuid":"6777cd1e-16ce-4f77-8490-19565eb28ac4","payload":null}
|
101
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"bob","description":"reply","uuid":"ab3a28d4-b659-4acb-a1ff-97a2e7d9560f","parent_uuid":"637a5251-fd82-4a6f-8dff-24942ea0221f","payload":"Unleash the kraken!"}
|
102
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"bob","description":"handle","uuid":"9efbffe6-b66e-4a04-9fbc-9796d67de36d","parent_uuid":null,"payload":null}
|
103
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"bob","description":"handle","uuid":"c003f62c-8991-46b4-9c63-04aa9a082302","parent_uuid":null,"payload":null}
|
104
|
+
{"datetime":"2015-03-07 17:53:37 +0100","service":"bob","description":"reply","uuid":"0dfdd041-f39c-4d20-ac8e-56c20fe508e0","parent_uuid":"c003f62c-8991-46b4-9c63-04aa9a082302","payload":"Unleash the kraken!"}
|
105
|
+
{"datetime":"2015-03-07 17:53:38 +0100","service":"bob","description":"seeding","uuid":"de56b6d0-7c80-463f-9cc1-944242b62220","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
106
|
+
{"datetime":"2015-03-07 17:53:38 +0100","service":"carl","description":"handle","uuid":"0dfdd041-f39c-4d20-ac8e-56c20fe508e0","parent_uuid":"c003f62c-8991-46b4-9c63-04aa9a082302","payload":null}
|
107
|
+
{"datetime":"2015-03-07 17:53:38 +0100","service":"carl","description":"reply","uuid":"3cd3c414-835e-4bea-aa3d-32150c55c1e2","parent_uuid":"0dfdd041-f39c-4d20-ac8e-56c20fe508e0","payload":"Unleash the kraken!"}
|
108
|
+
{"datetime":"2015-03-07 17:53:38 +0100","service":"carl","description":"handle","uuid":"de56b6d0-7c80-463f-9cc1-944242b62220","parent_uuid":null,"payload":null}
|
109
|
+
{"datetime":"2015-03-07 17:53:38 +0100","service":"alice","description":"handle","uuid":"ab3a28d4-b659-4acb-a1ff-97a2e7d9560f","parent_uuid":"637a5251-fd82-4a6f-8dff-24942ea0221f","payload":null}
|
110
|
+
{"datetime":"2015-03-07 17:53:38 +0100","service":"alice","description":"reply","uuid":"d7395c32-9f7f-4178-8f32-9400cdef8215","parent_uuid":"ab3a28d4-b659-4acb-a1ff-97a2e7d9560f","payload":"Unleash the kraken!"}
|
111
|
+
{"datetime":"2015-03-07 17:53:38 +0100","service":"alice","description":"seeding","uuid":"0dc4b684-9d8c-4639-8cce-430f08d58256","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
112
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"carl","description":"handle","uuid":"d7395c32-9f7f-4178-8f32-9400cdef8215","parent_uuid":"ab3a28d4-b659-4acb-a1ff-97a2e7d9560f","payload":null}
|
113
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"bob","description":"handle","uuid":"3cd3c414-835e-4bea-aa3d-32150c55c1e2","parent_uuid":"0dfdd041-f39c-4d20-ac8e-56c20fe508e0","payload":null}
|
114
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"bob","description":"reply","uuid":"46e38712-75f2-463c-a329-9e387093e2f1","parent_uuid":"3cd3c414-835e-4bea-aa3d-32150c55c1e2","payload":"Unleash the kraken!"}
|
115
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"bob","description":"handle","uuid":"0dc4b684-9d8c-4639-8cce-430f08d58256","parent_uuid":null,"payload":null}
|
116
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"bob","description":"seeding","uuid":"279f3587-86ca-4886-9c32-6dc1eb0b5d30","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
117
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"alice","description":"handle","uuid":"279f3587-86ca-4886-9c32-6dc1eb0b5d30","parent_uuid":null,"payload":null}
|
118
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"alice","description":"reply","uuid":"ae7eb7ad-3d84-4390-81fa-6e3be2b47d9f","parent_uuid":"279f3587-86ca-4886-9c32-6dc1eb0b5d30","payload":"Unleash the kraken!"}
|
119
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"alice","description":"seeding","uuid":"4a858f70-f0ad-4846-b04e-17f519ba3ddf","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
120
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"carl","description":"handle","uuid":"46e38712-75f2-463c-a329-9e387093e2f1","parent_uuid":"3cd3c414-835e-4bea-aa3d-32150c55c1e2","payload":null}
|
121
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"carl","description":"handle","uuid":"ae7eb7ad-3d84-4390-81fa-6e3be2b47d9f","parent_uuid":"279f3587-86ca-4886-9c32-6dc1eb0b5d30","payload":null}
|
122
|
+
{"datetime":"2015-03-07 17:53:39 +0100","service":"carl","description":"seeding","uuid":"abf8e50f-3aa6-4a8a-b4e5-76c76d2b86c0","parent_uuid":null,"payload":"Let me tell you a secret:<hidden>"}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#
|
2
|
+
# In this example 3 bots are sending each other messages. Each bot run in a
|
3
|
+
# separated thread. A bot follows this behaviour:
|
4
|
+
#
|
5
|
+
# 1. Check its inbox (queue)
|
6
|
+
# 2. If there is no message in the queue, he sends a message to another bot
|
7
|
+
# 3. If there is some message in the queue he reads them one by one
|
8
|
+
# 4. For each read message, the robot can send a message to another bot
|
9
|
+
# 5. The bot rests
|
10
|
+
#
|
11
|
+
# For the steps 2, 3 and 4 the bot will log the following events:
|
12
|
+
#
|
13
|
+
# - seeding
|
14
|
+
# - handle
|
15
|
+
# - reply
|
16
|
+
#
|
17
|
+
|
18
|
+
|
19
|
+
lib = File.expand_path('../lib', __FILE__)
|
20
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
21
|
+
|
22
|
+
require 'thread'
|
23
|
+
require 'utracker'
|
24
|
+
|
25
|
+
BOTS = {
|
26
|
+
'alice' => nil,
|
27
|
+
'bob' => nil,
|
28
|
+
'carl' => nil,
|
29
|
+
}
|
30
|
+
|
31
|
+
class Bot
|
32
|
+
attr_accessor :queue
|
33
|
+
|
34
|
+
def initialize(name)
|
35
|
+
@name = name
|
36
|
+
@queue = Queue.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def run
|
40
|
+
loop do
|
41
|
+
consume_queue
|
42
|
+
rest
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def thread
|
47
|
+
Thread.current
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def consume_queue
|
53
|
+
if @queue.empty?
|
54
|
+
if target = others.sample
|
55
|
+
message = Utracker::Message.pack("Let me tell you a secret:12345")
|
56
|
+
target.queue.push(message.to_json)
|
57
|
+
message.log('seeding')
|
58
|
+
end
|
59
|
+
else
|
60
|
+
until @queue.empty?
|
61
|
+
serialization = @queue.pop
|
62
|
+
handle(serialization)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def handle(serialization)
|
68
|
+
message = Utracker::Message.unpack(serialization)
|
69
|
+
message.log('handle', hide_payload: true)
|
70
|
+
reply_to(message)
|
71
|
+
end
|
72
|
+
|
73
|
+
def reply_to(message)
|
74
|
+
if rand(2) == 0 && (target = others.sample)
|
75
|
+
reply = message.pack('Unleash the kraken!')
|
76
|
+
target.queue.push(reply.to_json)
|
77
|
+
reply.log('reply')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def others
|
82
|
+
BOTS.each_with_object([]) do |(name, bot), list|
|
83
|
+
list << bot if bot && name != @name
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def rest
|
88
|
+
sleep rand
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
threads = BOTS.keys.map do |name|
|
94
|
+
Thread.new do
|
95
|
+
Utracker.configure do |config|
|
96
|
+
config[:service_name] = name
|
97
|
+
config[:formatter] = ->(payload) {
|
98
|
+
payload.gsub(/secret:\d+/, "secret:<hidden>")
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
Bot.new(name).tap do |bot|
|
103
|
+
BOTS[name] = bot
|
104
|
+
bot.run
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
begin
|
110
|
+
threads.each(&:join)
|
111
|
+
rescue Interrupt
|
112
|
+
threads.each(&:terminate)
|
113
|
+
end
|
data/lib/utracker.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "utracker/version"
|
2
|
+
|
3
|
+
module Utracker
|
4
|
+
|
5
|
+
autoload :Logger, 'utracker/logger'
|
6
|
+
autoload :StdoutLogger, 'utracker/logger/stdout_logger'
|
7
|
+
|
8
|
+
autoload :Message, 'utracker/message'
|
9
|
+
|
10
|
+
DEFAULT_FORMATTER = ->(payload){ payload }
|
11
|
+
|
12
|
+
module ModuleMethods
|
13
|
+
|
14
|
+
def config
|
15
|
+
Thread.current[:utracker_config] ||= default_configuration.freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
def logger
|
19
|
+
Thread.current[:utracker_logger] ||= (config[:logger] || config[:logger_class].new)
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure
|
23
|
+
self.config = default_configuration
|
24
|
+
yield config
|
25
|
+
self.logger = nil
|
26
|
+
self.config.freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def config=(new_config)
|
32
|
+
Thread.current[:utracker_config] = new_config
|
33
|
+
end
|
34
|
+
|
35
|
+
def logger=(new_logger)
|
36
|
+
Thread.current[:utracker_logger] = new_logger
|
37
|
+
end
|
38
|
+
|
39
|
+
def default_configuration
|
40
|
+
Hash.new{ |_, key| fail "Missing key '#{key}' in Utracker's configuration." }.tap do |hash|
|
41
|
+
hash[:logger] = nil
|
42
|
+
hash[:logger_class] = Utracker::StdoutLogger
|
43
|
+
hash[:formatter] = DEFAULT_FORMATTER
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
extend ModuleMethods
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Utracker::Logger
|
2
|
+
|
3
|
+
Event = Struct.new(:datetime, :service, :description, :message, :options) do
|
4
|
+
def payload
|
5
|
+
return if options[:hide_payload]
|
6
|
+
Utracker.config[:formatter][message.content]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def log(message, description, options={})
|
11
|
+
event = Event.new(
|
12
|
+
Time.now,
|
13
|
+
Utracker.config[:service_name],
|
14
|
+
description,
|
15
|
+
message,
|
16
|
+
options
|
17
|
+
)
|
18
|
+
write(event)
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def write(event)
|
24
|
+
fail 'Please implement me in subclasses.'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
class Utracker::StdoutLogger < Utracker::Logger
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def write(event)
|
8
|
+
hash = {
|
9
|
+
datetime: event.datetime.to_s,
|
10
|
+
service: event.service,
|
11
|
+
description: event.description,
|
12
|
+
uuid: event.message.uuid,
|
13
|
+
parent_uuid: event.message.parent_uuid,
|
14
|
+
payload: event.payload,
|
15
|
+
}
|
16
|
+
STDOUT.puts MultiJson.dump(hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
class Utracker::Message
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
private :new
|
9
|
+
|
10
|
+
def pack(payload, parent_uuid: nil)
|
11
|
+
new(uuid: SecureRandom.uuid, content: payload, parent_uuid: parent_uuid)
|
12
|
+
end
|
13
|
+
|
14
|
+
def unpack(serialized_message)
|
15
|
+
hash = MultiJson.load(serialized_message)
|
16
|
+
new(uuid: hash['uuid'],
|
17
|
+
content: hash['content'],
|
18
|
+
parent_uuid: hash['parent_uuid'])
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :uuid
|
24
|
+
attr_reader :parent_uuid
|
25
|
+
attr_reader :content
|
26
|
+
|
27
|
+
def initialize(uuid:, content:, parent_uuid: nil)
|
28
|
+
@uuid = uuid
|
29
|
+
@content = content
|
30
|
+
@parent_uuid = parent_uuid
|
31
|
+
end
|
32
|
+
|
33
|
+
def log(event, options={})
|
34
|
+
Utracker.logger.log(self, event, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def pack(payload)
|
38
|
+
self.class.pack(payload, parent_uuid: @uuid)
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_json
|
42
|
+
MultiJson.dump({
|
43
|
+
'uuid' => @uuid,
|
44
|
+
'parent_uuid' => @parent_uuid,
|
45
|
+
'content' => @content,
|
46
|
+
})
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'utracker'
|
5
|
+
|
6
|
+
require 'pry-byebug'
|
7
|
+
require 'timecop'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.expect_with :rspec do |expectations|
|
11
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
12
|
+
end
|
13
|
+
|
14
|
+
config.mock_with :rspec do |mocks|
|
15
|
+
mocks.verify_partial_doubles = true
|
16
|
+
end
|
17
|
+
|
18
|
+
# See: http://www.rubydoc.info/github/rspec/rspec-core/RSpec/Core/Configuration#disable_monkey_patching%21-instance_method
|
19
|
+
config.disable_monkey_patching!
|
20
|
+
|
21
|
+
config.order = :random
|
22
|
+
Kernel.srand config.seed
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec.describe Utracker::Logger::Event do
|
2
|
+
let(:event) { described_class.new(nil, nil, nil, message, options) }
|
3
|
+
let(:message) { double('Message', content: 'Hello') }
|
4
|
+
let(:options) { {} }
|
5
|
+
|
6
|
+
describe "#payload" do
|
7
|
+
before do
|
8
|
+
Utracker.configure do |config|
|
9
|
+
config[:formatter] = ->(_){ formatter_result }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { event.payload }
|
14
|
+
let(:formatter_result) { double }
|
15
|
+
|
16
|
+
it { is_expected.to be formatter_result }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
RSpec.describe Utracker::Logger do
|
2
|
+
before do
|
3
|
+
Utracker.configure { |config| config[:service_name] = service_name }
|
4
|
+
end
|
5
|
+
|
6
|
+
let(:instance) { described_class.new }
|
7
|
+
let(:service_name) { 'Test suite service' }
|
8
|
+
|
9
|
+
describe '#log' do
|
10
|
+
subject(:log_event) { instance.log(message, description) }
|
11
|
+
|
12
|
+
let(:message) { double('Message') }
|
13
|
+
let(:description) { 'event description' }
|
14
|
+
|
15
|
+
it 'writes an event built with the current time, service name, description and message' do
|
16
|
+
Timecop.freeze do
|
17
|
+
expect(instance).to receive(:write) do |event|
|
18
|
+
expect(event.datetime).to eq Time.now
|
19
|
+
expect(event.service).to eq service_name
|
20
|
+
expect(event.description).to eq description
|
21
|
+
expect(event.message).to eq message
|
22
|
+
end
|
23
|
+
log_event
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when there is a hide_payload argument' do
|
28
|
+
subject(:log_event) { instance.log(message, description, hide_payload: true) }
|
29
|
+
|
30
|
+
it 'passes the option to the write method as an option' do
|
31
|
+
expect(instance).to receive(:write) do |event|
|
32
|
+
expect(event.payload).to be_nil
|
33
|
+
end
|
34
|
+
log_event
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec.describe Utracker::Message do
|
2
|
+
describe '#log' do
|
3
|
+
subject(:log_event) { message.log(event) }
|
4
|
+
|
5
|
+
before do
|
6
|
+
allow(Utracker).to receive(:logger).and_return(logger)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:message) { described_class.pack('payload') }
|
10
|
+
let(:event) { 'event description' }
|
11
|
+
let(:logger) { double('Logger', log: true) }
|
12
|
+
|
13
|
+
it 'logs the event using the Utracker logger' do
|
14
|
+
expect(Utracker.logger).to receive(:log).with(message, event, {})
|
15
|
+
log_event
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'whith extra options as last argument' do
|
19
|
+
subject(:log_event) { message.log(event, options) }
|
20
|
+
|
21
|
+
let(:options) { double('Hash') }
|
22
|
+
|
23
|
+
it 'passes the options to the Utracker logger' do
|
24
|
+
expect(Utracker.logger).to receive(:log).with(message, event, options)
|
25
|
+
log_event
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
RSpec.describe Utracker::Message do
|
2
|
+
let(:packed_message) { described_class.pack(payload) }
|
3
|
+
let(:unpacked_message) { described_class.unpack(serialization) }
|
4
|
+
let(:serialization) { packed_message.to_json }
|
5
|
+
let(:payload) { {'this' => 'is my mayload'} }
|
6
|
+
|
7
|
+
describe 'instanciation by packing a payload' do
|
8
|
+
subject { packed_message }
|
9
|
+
it { is_expected.to be_a described_class }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'instanciation by unpacking a Message serialization' do
|
13
|
+
subject { unpacked_message }
|
14
|
+
it { is_expected.to be_a described_class }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#uuid' do
|
18
|
+
subject { instance.uuid }
|
19
|
+
|
20
|
+
context 'when we packed a payload' do
|
21
|
+
let(:instance) { packed_message }
|
22
|
+
it { is_expected.to match /^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/ }
|
23
|
+
it { is_expected.to eq instance.uuid }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when we unpacked a serialized payload' do
|
27
|
+
let(:instance) { unpacked_message }
|
28
|
+
it { is_expected.to eq packed_message.uuid }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#content' do
|
33
|
+
subject { instance.content }
|
34
|
+
|
35
|
+
context 'when we packed a payload' do
|
36
|
+
let(:instance) { packed_message }
|
37
|
+
it { is_expected.to eq payload }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when we unpacked a serialized payload' do
|
41
|
+
let(:instance) { unpacked_message }
|
42
|
+
it { is_expected.to eq payload }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#pack' do
|
47
|
+
subject { packed_message.pack(payload) }
|
48
|
+
it { is_expected.to be_a described_class }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#parent_uuid' do
|
52
|
+
subject { instance.parent_uuid }
|
53
|
+
|
54
|
+
context 'when the message was packed by the class' do
|
55
|
+
let(:instance) { packed_message }
|
56
|
+
it { is_expected.to eq nil }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when the message was packed by another message' do
|
60
|
+
let(:instance) { packed_message.pack(payload) }
|
61
|
+
it { is_expected.to eq packed_message.uuid }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when the message was serialized' do
|
65
|
+
let(:instance) { Utracker::Message.unpack(packed_message.pack(payload).to_json) }
|
66
|
+
it { is_expected.to eq packed_message.uuid }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
RSpec.describe Utracker do
|
2
|
+
let(:config) { Utracker.config }
|
3
|
+
before { Utracker.configure {} }
|
4
|
+
|
5
|
+
describe ".config" do
|
6
|
+
subject { config }
|
7
|
+
it { is_expected.to be_a Hash }
|
8
|
+
it { is_expected.to be_frozen }
|
9
|
+
|
10
|
+
describe "the default :logger value" do
|
11
|
+
subject { config[:logger] }
|
12
|
+
it { is_expected.to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "the default :logger_class value" do
|
16
|
+
subject { config[:logger_class] }
|
17
|
+
it { is_expected.to be Utracker::StdoutLogger }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "the default :formatter value" do
|
21
|
+
subject { config[:formatter] }
|
22
|
+
it { is_expected.to be_an_instance_of Proc }
|
23
|
+
|
24
|
+
describe "the default formatter" do
|
25
|
+
subject { config[:formatter][its_argument] }
|
26
|
+
let(:its_argument) { double }
|
27
|
+
it { is_expected.to be its_argument }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".configure" do
|
33
|
+
before { Utracker.configure(&block) }
|
34
|
+
|
35
|
+
describe "the resulting config[:key] value" do
|
36
|
+
subject { config[:key] }
|
37
|
+
|
38
|
+
context "when the value has been defined in the configure's block" do
|
39
|
+
let(:block) { proc do |hash| hash[:key] = :value end }
|
40
|
+
it { is_expected.to eq :value }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the value has not been defined in the configure's block" do
|
44
|
+
let(:block) { proc do |hash| hash[:other_key] = :value end }
|
45
|
+
it { expect{ subject }.to raise_error }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".logger" do
|
51
|
+
subject { Utracker.logger }
|
52
|
+
it { is_expected.to be_a Utracker::Logger }
|
53
|
+
|
54
|
+
context 'when the :logger_class config key had been configured' do
|
55
|
+
before { Utracker.configure { |config| config[:logger_class] = logger_class } }
|
56
|
+
let(:logger_class) { Time }
|
57
|
+
it { is_expected.to be_a logger_class }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when the :logger config key had been configured' do
|
61
|
+
before { Utracker.configure { |config| config[:logger] = logger } }
|
62
|
+
let(:logger) { double('Logger') }
|
63
|
+
it { is_expected.to be logger }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/utracker.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'utracker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "utracker"
|
8
|
+
spec.version = Utracker::VERSION
|
9
|
+
spec.authors = ["Nicolas ZERMATI"]
|
10
|
+
spec.email = ["nicoolas25@gmail.com"]
|
11
|
+
spec.summary = %q{Track micro-services interactions.}
|
12
|
+
spec.homepage = "https://github.com/nicoolas25/micro-tracker"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "multi_json"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
25
|
+
spec.add_development_dependency "pry-byebug"
|
26
|
+
spec.add_development_dependency "timecop"
|
27
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: utracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas ZERMATI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- nicoolas25@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".ruby-version"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- examples/services.out
|
127
|
+
- examples/services.rb
|
128
|
+
- lib/utracker.rb
|
129
|
+
- lib/utracker/logger.rb
|
130
|
+
- lib/utracker/logger/stdout_logger.rb
|
131
|
+
- lib/utracker/message.rb
|
132
|
+
- lib/utracker/version.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- spec/utracker/logger/event_spec.rb
|
135
|
+
- spec/utracker/logger_spec.rb
|
136
|
+
- spec/utracker/message/logging_spec.rb
|
137
|
+
- spec/utracker/message_spec.rb
|
138
|
+
- spec/utracker_spec.rb
|
139
|
+
- utracker.gemspec
|
140
|
+
homepage: https://github.com/nicoolas25/micro-tracker
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.2.2
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Track micro-services interactions.
|
164
|
+
test_files:
|
165
|
+
- spec/spec_helper.rb
|
166
|
+
- spec/utracker/logger/event_spec.rb
|
167
|
+
- spec/utracker/logger_spec.rb
|
168
|
+
- spec/utracker/message/logging_spec.rb
|
169
|
+
- spec/utracker/message_spec.rb
|
170
|
+
- spec/utracker_spec.rb
|