dummy_log_generator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +9 -3
- data/dummy_log_generator.conf +2 -1
- data/lib/dummy_log_generator.rb +1 -0
- data/lib/dummy_log_generator/cli.rb +1 -0
- data/lib/dummy_log_generator/dsl.rb +3 -19
- data/lib/dummy_log_generator/formatter.rb +19 -0
- data/lib/dummy_log_generator/generator.rb +30 -26
- data/lib/dummy_log_generator/version.rb +1 -1
- data/lib/dummy_log_generator/worker.rb +7 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b77ee9d48bae1cb615e7b45a3c3cc2b58388c48
|
4
|
+
data.tar.gz: fbd14739b3aaf235d0e9e095c6d1777a4d6ae14c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae54272e33cec7b6871acf5f6b63402ae4f83bc264fe48abddd63fe6741fd2ad71dae41a380e827f23a8ce91a65189f84ddccb3d5edd0a5b2b512974aad8e9f0
|
7
|
+
data.tar.gz: 26ff83fa64e28e9c16b8163d3a2117f414da3add07f6082adb2f54af8706e497753a3a727b5ffedf704179d09d3b11a1343ba70cd6d3d4ce4be5bccc49aeba5e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,7 @@ configure 'sample' do
|
|
30
30
|
rate 500
|
31
31
|
delimiter "\t"
|
32
32
|
labeled false
|
33
|
+
field :id, type: :integer, countup: true
|
33
34
|
field :time, type: :datetime, format: "[%Y-%m-%d %H:%M:%S]", random: true
|
34
35
|
field :level, type: :string, any: %w[DEBUG INFO WARN ERROR]
|
35
36
|
field :method, type: :string, any: %w[GET POST PUT]
|
@@ -42,9 +43,9 @@ end
|
|
42
43
|
Running dummy_log_generator outputs like
|
43
44
|
|
44
45
|
```
|
45
|
-
[
|
46
|
-
[
|
47
|
-
[
|
46
|
+
360 [2031-02-09 15:01:07] DEBUG GET /api/v1/people 1.105236938958904 PcGw8kEi
|
47
|
+
361 [1991-08-26 13:03:05] WARN GET /api/v1/people 1.8938518088450287 RGOuoydG
|
48
|
+
362 [2037-11-04 15:32:38] DEBUG POST /api/v1/people 2.7431863060457538 rVij0nWP
|
48
49
|
```
|
49
50
|
|
50
51
|
## Configuration Parameters
|
@@ -97,6 +98,10 @@ You can specify following data types to your `field` parameters:
|
|
97
98
|
|
98
99
|
You can specify a range of integers, then the generator picks one in the range (uniform) randomly
|
99
100
|
|
101
|
+
* :countup
|
102
|
+
|
103
|
+
Generate countup data. Default: false
|
104
|
+
|
100
105
|
* :float
|
101
106
|
|
102
107
|
* :range
|
@@ -112,6 +117,7 @@ There is a [fluent-plugin-dummydata-producer](https://github.com/tagomoris/fluen
|
|
112
117
|
1. write tests
|
113
118
|
2. make it slim (remove active_support, etc)
|
114
119
|
3. outputs to a file (currently, outputs to STDOUT)
|
120
|
+
4. speed up (evaluate fields at only starting up)
|
115
121
|
|
116
122
|
## Contributing
|
117
123
|
|
data/dummy_log_generator.conf
CHANGED
@@ -2,7 +2,8 @@ configure 'sample' do
|
|
2
2
|
rate 500
|
3
3
|
delimiter "\t"
|
4
4
|
labeled false
|
5
|
-
field :
|
5
|
+
field :id, type: :integer, countup: true
|
6
|
+
field :time, type: :datetime, format: "[%Y-%m-%d %H:%M:%S]", random: false
|
6
7
|
field :level, type: :string, any: %w[DEBUG INFO WARN ERROR]
|
7
8
|
field :method, type: :string, any: %w[GET POST PUT]
|
8
9
|
field :uri, type: :string, any: %w[/api/v1/people /api/v1/textdata /api/v1/messages]
|
data/lib/dummy_log_generator.rb
CHANGED
@@ -13,6 +13,7 @@ module DummyLogGenerator
|
|
13
13
|
@options = @options.dup # avoid frozen
|
14
14
|
if options[:config] && File.exists?(options[:config])
|
15
15
|
dsl = instance_eval(File.read(options[:config]), options[:config])
|
16
|
+
@options[:generator] = dsl.generator
|
16
17
|
@options[:formatter] = dsl.formatter
|
17
18
|
@options[:rate] = dsl.config.rate
|
18
19
|
end
|
@@ -6,32 +6,16 @@ module DummyLogGenerator
|
|
6
6
|
@rate = 500
|
7
7
|
end
|
8
8
|
end
|
9
|
-
|
10
|
-
class Formatter
|
11
|
-
attr_accessor :labeled, :delimiter, :fields
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@labeled = true
|
15
|
-
@delimiter = "\t"
|
16
|
-
@fields = {}
|
17
|
-
end
|
18
|
-
|
19
|
-
def output(generated_params)
|
20
|
-
if labeled
|
21
|
-
generated_params.map {|key, val| "#{key}:#{val}" }.join(delimiter)
|
22
|
-
else
|
23
|
-
generated_params.values.join(delimiter)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
9
|
end
|
28
10
|
|
29
11
|
module DummyLogGenerator
|
30
12
|
class Dsl
|
13
|
+
attr_reader :generator
|
31
14
|
attr_reader :formatter
|
32
15
|
attr_reader :config
|
33
16
|
|
34
17
|
def initialize
|
18
|
+
@generator = Generator.new
|
35
19
|
@formatter = Formatter.new
|
36
20
|
@config = Config.new
|
37
21
|
end
|
@@ -41,7 +25,7 @@ module DummyLogGenerator
|
|
41
25
|
end
|
42
26
|
|
43
27
|
def field(name, opts)
|
44
|
-
|
28
|
+
generator.fields[name] = opts
|
45
29
|
end
|
46
30
|
|
47
31
|
def delimiter(delimiter)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module DummyLogGenerator
|
2
|
+
class Formatter
|
3
|
+
attr_accessor :labeled, :delimiter, :fields
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@labeled = true
|
7
|
+
@delimiter = "\t"
|
8
|
+
@fields = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def format(fields)
|
12
|
+
if labeled
|
13
|
+
fields.map {|key, val| "#{key}:#{val}" }.join(delimiter)
|
14
|
+
else
|
15
|
+
fields.values.join(delimiter)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,32 +1,33 @@
|
|
1
1
|
module DummyLogGenerator
|
2
2
|
class Generator
|
3
|
-
|
3
|
+
attr_accessor :fields
|
4
4
|
attr_reader :rand
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@
|
6
|
+
def initialize
|
7
|
+
@fields = {}
|
8
8
|
@rand = ::DummyLogGenerator::Random.new
|
9
9
|
end
|
10
10
|
|
11
|
-
def generate
|
12
|
-
|
13
|
-
|
11
|
+
def generate(prev_data = {})
|
12
|
+
data = {}
|
13
|
+
fields.each do |key, opts|
|
14
14
|
opts = opts.dup
|
15
15
|
type = opts.delete(:type)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
opts[:prev] = prev_data[key]
|
17
|
+
data[key] = case type
|
18
|
+
when :datetime
|
19
|
+
rand.datetime(opts)
|
20
|
+
when :string
|
21
|
+
rand.string(opts)
|
22
|
+
when :integer
|
23
|
+
rand.integer(opts)
|
24
|
+
when :float
|
25
|
+
rand.float(opts)
|
26
|
+
else
|
27
|
+
raise ConfigError.new(type)
|
28
|
+
end
|
28
29
|
end
|
29
|
-
|
30
|
+
data
|
30
31
|
end
|
31
32
|
alias_method :gen, :generate
|
32
33
|
end
|
@@ -37,24 +38,27 @@ module DummyLogGenerator
|
|
37
38
|
@chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a # no symbols and multi-bytes for now
|
38
39
|
end
|
39
40
|
|
40
|
-
def string(length: 8, any: nil)
|
41
|
-
|
41
|
+
def string(length: 8, any: nil, prev: nil)
|
42
|
+
if any
|
42
43
|
self.any(any)
|
43
44
|
else
|
44
45
|
Array.new(length){@chars[rand(@chars.size-1)]}.join
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
def
|
49
|
-
|
49
|
+
def integer(range: nil, countup: false, prev: nil)
|
50
|
+
if range
|
50
51
|
self.range(range)
|
52
|
+
elsif countup
|
53
|
+
prev ||= -1
|
54
|
+
prev + 1
|
51
55
|
else
|
52
56
|
rand(0..2,147,483,647)
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
56
|
-
def float(range: nil)
|
57
|
-
|
60
|
+
def float(range: nil, prev: nil)
|
61
|
+
if range
|
58
62
|
self.range(range)
|
59
63
|
else
|
60
64
|
r = rand(1..358)
|
@@ -62,7 +66,7 @@ module DummyLogGenerator
|
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
|
-
def datetime(format: "%Y-%m-%d %H:%M:%S.%3N", random: false)
|
69
|
+
def datetime(format: "%Y-%m-%d %H:%M:%S.%3N", random: false, prev: nil)
|
66
70
|
time = if random
|
67
71
|
y = rand(1970..2037);
|
68
72
|
m = rand(1..12);
|
@@ -7,13 +7,15 @@ module DummyLogGenerator
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def reload
|
10
|
-
@rate = config[:rate]
|
10
|
+
@rate = config[:rate]
|
11
11
|
@formatter = config[:formatter]
|
12
|
-
@generator =
|
12
|
+
@generator = config[:generator]
|
13
13
|
end
|
14
14
|
|
15
|
+
# thanks! ref. https://github.com/tagomoris/fluent-plugin-dummydata-producer/blob/a550fd4424f71cd9227e138c3c89f600ba40a0d5/lib/fluent/plugin/in_dummydata_producer.rb#L63
|
15
16
|
def run
|
16
17
|
batch_num = (@rate / 9).to_i + 1
|
18
|
+
prev_data = {}
|
17
19
|
while !@stop
|
18
20
|
current_time = Time.now.to_i
|
19
21
|
rate_count = 0
|
@@ -21,7 +23,9 @@ module DummyLogGenerator
|
|
21
23
|
while !@stop && rate_count < @rate && Time.now.to_i == current_time
|
22
24
|
batch_num.times do
|
23
25
|
# ToDo: what if generation is slower than I/O?
|
24
|
-
|
26
|
+
# We may should generate data and output in parallel
|
27
|
+
prev_data = @generator.generate(prev_data)
|
28
|
+
STDOUT.puts @formatter.format(prev_data)
|
25
29
|
end
|
26
30
|
rate_count += batch_num
|
27
31
|
sleep 0.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dummy_log_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sonots
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/dummy_log_generator/cli.rb
|
159
159
|
- lib/dummy_log_generator/dsl.rb
|
160
160
|
- lib/dummy_log_generator/error.rb
|
161
|
+
- lib/dummy_log_generator/formatter.rb
|
161
162
|
- lib/dummy_log_generator/generator.rb
|
162
163
|
- lib/dummy_log_generator/version.rb
|
163
164
|
- lib/dummy_log_generator/worker.rb
|