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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 239561651394dd1e8a834b4d6c96d4b40aa2477d
4
- data.tar.gz: 5359dbbd8aac2e4a62f6d6eceaac9bd8bbc39013
3
+ metadata.gz: 4b77ee9d48bae1cb615e7b45a3c3cc2b58388c48
4
+ data.tar.gz: fbd14739b3aaf235d0e9e095c6d1777a4d6ae14c
5
5
  SHA512:
6
- metadata.gz: 71dc67b5580ff0ece0e3d908728b3babfdc35755235e6577f94d3ff2b84dd45a93491f85117c4439d596bc0d54f48ef7aad69ba37e57c4d6408bffe40c077917
7
- data.tar.gz: 345b86a8f396f711ad09886df24af56eecc4f9c30edb63acb16b7d51b48c7b4557ff257c7646c2caa29ef39dfbd993616b2055f412a6780724dab4a56b4ff297
6
+ metadata.gz: ae54272e33cec7b6871acf5f6b63402ae4f83bc264fe48abddd63fe6741fd2ad71dae41a380e827f23a8ce91a65189f84ddccb3d5edd0a5b2b512974aad8e9f0
7
+ data.tar.gz: 26ff83fa64e28e9c16b8163d3a2117f414da3add07f6082adb2f54af8706e497753a3a727b5ffedf704179d09d3b11a1343ba70cd6d3d4ce4be5bccc49aeba5e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.0.2
2
+
3
+ Enhancement:
4
+
5
+ * Add `countup: true` suppert
6
+
1
7
  ### 0.0.1
2
8
 
3
9
  First version
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
- [1984-05-25 05:10:03] DEBUG GET /api/v1/people 4.451362369925074 fl8nmh4f
46
- [2027-11-04 02:58:01] INFO GET /api/v1/people 3.984084722909503 WhsvwEeF
47
- [1973-02-17 09:09:34] WARN GET /api/v1/people 2.290704255755689 3UyK3jgi
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
 
@@ -2,7 +2,8 @@ configure 'sample' do
2
2
  rate 500
3
3
  delimiter "\t"
4
4
  labeled false
5
- field :time, type: :datetime, format: "[%Y-%m-%d %H:%M:%S]", random: true
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]
@@ -2,6 +2,7 @@ require 'logger'
2
2
  require "dummy_log_generator/version"
3
3
  require "dummy_log_generator/error"
4
4
  require "dummy_log_generator/generator"
5
+ require "dummy_log_generator/formatter"
5
6
  require "dummy_log_generator/worker"
6
7
  require "dummy_log_generator/dsl"
7
8
 
@@ -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
- formatter.fields[name] = opts
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
- attr_reader :formatter
3
+ attr_accessor :fields
4
4
  attr_reader :rand
5
5
 
6
- def initialize(formatter)
7
- @formatter = formatter
6
+ def initialize
7
+ @fields = {}
8
8
  @rand = ::DummyLogGenerator::Random.new
9
9
  end
10
10
 
11
- def generate
12
- fields = {}
13
- formatter.fields.each do |key, opts|
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
- fields[key] = case type
17
- when :datetime
18
- rand.datetime(opts)
19
- when :string
20
- rand.string(opts)
21
- when :integer
22
- rand.integer(opts)
23
- when :float
24
- rand.float(opts)
25
- else
26
- raise ConfigError.new(type)
27
- end
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
- formatter.output(fields)
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
- unless any.nil?
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 interger(range: nil)
49
- unless range.nil?
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
- unless range.nil?
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);
@@ -1,3 +1,3 @@
1
1
  module DummyLogGenerator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -7,13 +7,15 @@ module DummyLogGenerator
7
7
  end
8
8
 
9
9
  def reload
10
- @rate = config[:rate] || 500 # msgs / sec
10
+ @rate = config[:rate]
11
11
  @formatter = config[:formatter]
12
- @generator = Generator.new(@formatter)
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
- STDOUT.puts @generator.generate
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.1
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