redis-stream 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e636f1c98003bb96c0ca288b66e7ec9e8a32232a2eb1a06c3c5291df97bed4b
4
- data.tar.gz: d9e9533cc0175ceb705d4f9d9964f5fb5f94c517df3bd3cd5614c12dc2962c76
3
+ metadata.gz: fbe96b36fe4773c01e41855ee855e5f9439173c5d49a29d2437a13387f6ee3e4
4
+ data.tar.gz: 8ed325cf47a32f25336bea011abcd1de73e4ab05807168a453d0b7408cf74ada
5
5
  SHA512:
6
- metadata.gz: b900b2614e55c5a470cf1b54f0751475c4186a9a1272bd1d0acefb0a9827139ed34d4e857494396333a2ff4c0f4556050df7400316f236502a4261f2916aab05
7
- data.tar.gz: cf969f706a177b0636f0100909987fc52fee799b502accae266a697524068d77ce9d12919b9bc80dda6acaa055d6ef9532a85b183fcfa0c0333ff55f0d89a507
6
+ metadata.gz: 312cf26889a74940ad75bab25350d8edd3c2edccca57229c141f2cd3c57c744b45909a9a9aa8318d0925d0f1fe2cd597d8fa4e18bac0353644464ccd72985d45
7
+ data.tar.gz: 0cd8e58a47892aca5f3cdb70a04372d8b92b72c24509404213e55d3978ac436a9b89c78b67bcd6078212b8f5996a148fb4ac6b6307ad5e21d41523fd86c62340
data/Gemfile.lock CHANGED
@@ -1,22 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-stream (0.3.0)
4
+ redis-stream (0.4.0)
5
5
  moneta (~> 1.2)
6
6
  multi_json (~> 1.14)
7
7
  redis (= 4.1.3)
8
+ zipkin-tracer (~> 0.43)
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
13
+ concurrent-ruby (1.1.5)
14
+ faraday (0.17.3)
15
+ multipart-post (>= 1.2, < 3)
12
16
  minitest (5.13.0)
13
17
  moneta (1.2.1)
14
18
  multi_json (1.14.1)
19
+ multipart-post (2.1.1)
20
+ rack (2.1.2)
15
21
  rake (10.5.0)
16
22
  redis (4.1.3)
23
+ sucker_punch (2.1.2)
24
+ concurrent-ruby (~> 1.0)
25
+ zipkin-tracer (0.43.0)
26
+ faraday (~> 0.13)
27
+ rack (>= 1.0)
28
+ sucker_punch (~> 2.0)
17
29
 
18
30
  PLATFORMS
19
31
  java
32
+ ruby
20
33
 
21
34
  DEPENDENCIES
22
35
  bundler (~> 2.0)
data/README.md CHANGED
@@ -27,8 +27,39 @@ Load the stream library
27
27
  require 'redis/stream'
28
28
  ```
29
29
  Available objects
30
- ### Redis::Stream::Client
31
30
  ### Redis::Stream::Config
31
+ Simple way to read and manage a config file. It looks for a config.yml file in the current and './config' directory.
32
+ #### _name_
33
+ name defaults to config.yml
34
+ ```ruby
35
+ include Redis::Stream
36
+ puts Config.name
37
+ Config.name = "test.yml"
38
+ ```
39
+ #### _path_
40
+ path to the config file
41
+ ```ruby
42
+ include Redis::Stream
43
+ puts Config.path
44
+ Config.path = "./configDEV"
45
+ ```
46
+ #### _[key]_
47
+ reads and writes the key or key/value from/to the config file
48
+ ```ruby
49
+ include Redis::Stream
50
+ puts Config[:cache]
51
+ Config[:cache] = "./cache"
52
+ ```
53
+
54
+ #### include?(key)
55
+ check if key exists in the config file
56
+ #### file_exists?()
57
+ check if the config file exists
58
+ #### _init_
59
+ This function is called implicitly. You do not need to call it
60
+
61
+
62
+ ### Redis::Stream::Client
32
63
  ### Redis::Stream::Inspect
33
64
  ### Redis::Stream::Type
34
65
  ### Redis::Stream::DataCache
@@ -6,23 +6,30 @@ require "thread"
6
6
  require "redis/stream/inspect"
7
7
  require "redis/stream/config"
8
8
  require "redis/stream/data_cache"
9
+ require "redis/stream/tracer/zipkin_tracer"
9
10
 
10
11
  class Redis
11
12
  module Stream
12
13
  class Client
13
14
  include Redis::Stream::Inspect
14
15
 
15
- attr_reader :logger, :name, :group, :consumer_id, :cache, :redis, :non_blocking
16
+ attr_reader :logger, :name, :group, :stream, :consumer_id, :cache, :redis, :non_blocking
16
17
 
17
18
  # Initialize: setup rstream
18
19
  # @param [String] stream_name name of the rstream
19
- # @param [String] group name of the rstream group
20
+ # @param [String] group_name name of the rstream group
21
+ # @param [String] name name of the Stream Client
20
22
  # @param [Object] options options can contain redis[host, port, db] and logger keys
21
23
  #
22
24
  # Example: Redis::Stream::Client.new("resolver", "stream", {"logger" => Logger.new(STDOUT)})
23
25
  # if group is nil or not supplied then no rstream group will be setup
24
26
  def initialize(stream_name, group_name = nil, name = rand(36 ** 7).to_s(36), options = {})
25
- default_options = {"host" => "127.0.0.1", "port" => 6379, "db" => 0, "config_file_path" => '.', "logger" => Logger.new(STDOUT)}
27
+ default_options = {"host" => "127.0.0.1",
28
+ "port" => 6379,
29
+ "db" => 0,
30
+ "config_file_path" => '.',
31
+ "logger" => Logger.new(STDOUT),
32
+ "zipkin_config" => {}}
26
33
  options = default_options.merge(options)
27
34
 
28
35
  Redis::Stream::Config.path = options['config_file_path']
@@ -32,7 +39,7 @@ class Redis
32
39
  db = options["db"]
33
40
  @logger = options["logger"]
34
41
  @cache = options.include?('caching') && options['caching'] ? Redis::Stream::DataCache.new : nil
35
-
42
+ @tracer = ZipkinTracer::RedisStreamHandler.new(self, options["zipkin_config"])
36
43
  @name = name
37
44
  @state = Redis::Stream::State::IDLE
38
45
  @stream = stream_name
@@ -60,12 +67,18 @@ class Redis
60
67
  @logger.info "#{@consumer_id} - Last ID = #{@last_id}"
61
68
  end
62
69
 
70
+ def trace(topic, span = nil, &block)
71
+ @tracer.trace(topic, span, &block)
72
+ end
73
+
74
+ def trace_error(msg, span, &block)
75
+ @tracer.trace_error(msg, span, &block)
76
+ end
77
+
63
78
 
64
79
  # add: add a message to the stream
65
80
  # @param [Object] data Any data you want to transmit
66
- # @param [String] to Name of the consumer can be "*" or "" or nil for any consumer
67
- # @param [String] group Name of the consumer group can be "*" or "" or nil for any group
68
- # @param [Stream::Type] type Type of message
81
+ # @param [Hash{String->String}] Options
69
82
  #
70
83
  # no passthrough variable here. The passthrough is available in the start method
71
84
  def add(data = {}, options = {})
@@ -87,11 +100,7 @@ class Redis
87
100
 
88
101
  # sync_add: same as add command but synchronous. Blocks call until a message arrives
89
102
  # @param [Object] data Any data you want to transmit
90
- # @param [String] to Name of the consumer can be "*" or "" or nil for any consumer
91
- # @param [String] group Name of the consumer group can be "*" or "" or nil for any group
92
- # @param [Stream::Type] type Type of message
93
- # @param [Integer] time_out Time out after x seconds
94
- # @param [Boolean] passthrough Receive all messages also the ones intended for other consumers
103
+ # @param [Hash{String->String}] Options
95
104
  def sync_add(data = {}, options = {})
96
105
  raise "Client isn't running" unless @state.eql?(Redis::Stream::State::RUNNING)
97
106
 
@@ -0,0 +1,66 @@
1
+ require 'socket'
2
+ require 'zipkin-tracer'
3
+
4
+ module ZipkinTracer
5
+ class RedisStreamHandler
6
+ def initialize(stream, config = nil)
7
+ @stream = stream
8
+
9
+ @config = Config.new(nil, config)
10
+ @tracer = TracerFactory.new.tracer(@config) rescue nil
11
+ end
12
+
13
+ def trace(topic, span=nil)
14
+ if @tracer.is_a?(Trace::NullSender)
15
+ yield nil if block_given?
16
+ else
17
+ trace_id = trace_id_from_span(span)
18
+ TraceContainer.with_trace_id(trace_id) do
19
+ trace_id = trace_id.next_id unless span.nil?
20
+ @tracer.with_new_span(trace_id, topic) do |new_span|
21
+ new_span.kind = Trace::Span::Kind::CLIENT
22
+ new_span.record("Session")
23
+ new_span.record_tag('group', @stream.group)
24
+ new_span.record_tag('stream',@stream.stream)
25
+ new_span.record_tag('client', @stream.name)
26
+
27
+ yield new_span if block_given?
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def trace_error(msg, span = nil)
34
+ if @tracer.is_a?(Trace::NullSender)
35
+ yield nil if block_given?
36
+ else
37
+ span.record_tag(Trace::Span::Tag::ERROR, msg)
38
+ yield span if block_given?
39
+ end
40
+ end
41
+
42
+ private
43
+ def trace_id_from_span(span=nil)
44
+ if span.nil?
45
+ span_id = TraceGenerator.new.generate_id
46
+ trace_id = TraceGenerator.new.generate_id_from_span_id(span_id)
47
+ parent_span_id = nil
48
+ sampled = false
49
+ flags = 0
50
+ shared = false
51
+ else
52
+ span_h = span.to_h
53
+ span_id = span_h[:id]
54
+ trace_id = span_h[:traceId]
55
+ parent_span_id = span_h[:parent_span_id]
56
+ sampled = false
57
+ flags = 0
58
+ shared = true
59
+ end
60
+
61
+ Trace::TraceId.new(trace_id, parent_span_id, span_id, sampled, flags, shared)
62
+ end
63
+
64
+
65
+ end
66
+ end
@@ -1,6 +1,6 @@
1
1
  #encoding: UTF-8
2
2
  class Redis
3
3
  module Stream
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
data/redis-stream.gemspec CHANGED
@@ -42,4 +42,5 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency "redis", "4.1.3"
43
43
  spec.add_dependency "moneta", "~> 1.2"
44
44
  spec.add_dependency "multi_json", "~> 1.14"
45
+ spec.add_dependency "zipkin-tracer", "~> 0.43"
45
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-24 00:00:00.000000000 Z
11
+ date: 2020-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: zipkin-tracer
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.43'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.43'
97
111
  description: Simple stream library using Redis Streams
98
112
  email:
99
113
  - mehmet@celik.be
@@ -119,6 +133,7 @@ files:
119
133
  - lib/redis/stream/group.rb
120
134
  - lib/redis/stream/inspect.rb
121
135
  - lib/redis/stream/state.rb
136
+ - lib/redis/stream/tracer/zipkin_tracer.rb
122
137
  - lib/redis/stream/type.rb
123
138
  - lib/redis/stream/version.rb
124
139
  - redis-stream.gemspec