File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -49,9 +49,12 @@ class Client
49
49
# +:ssl_ca_cert+:: ssl CA certificate, chainfile or CA path.
50
50
# The system CA path is automatically included
51
51
# +:retry+:: number of times a failed request should be retried. Defaults to infinite.
52
- def initialize ( database = nil , **opts )
52
+ def initialize ( database = nil , config = nil , **opts )
53
+ raise ArgumentError , "provide config or opts, not both" if
54
+ config && !opts . empty?
55
+
53
56
opts [ :database ] = database if database . is_a? String
54
- @config = InfluxDB ::Config . new ( **opts )
57
+ @config = config || InfluxDB ::Config . new ( **opts )
55
58
@stopped = false
56
59
@writer = find_writer
57
60
@@ -82,7 +85,9 @@ def now
82
85
83
86
def find_writer
84
87
if config . async?
85
- InfluxDB ::Writer ::Async . new ( self , config . async )
88
+ client = InfluxDB ::Client . new nil , config . writer_config
89
+
90
+ InfluxDB ::Writer ::Async . new ( client , config . async )
86
91
elsif config . udp . is_a? ( Hash )
87
92
InfluxDB ::Writer ::UDP . new ( self , **config . udp )
88
93
elsif config . udp?
Original file line number Diff line number Diff line change @@ -83,6 +83,12 @@ def initialize(url: nil, **opts)
83
83
configure_hosts! opts [ :hosts ] || opts [ :host ] || "localhost" . freeze
84
84
end
85
85
86
+ def initialize_copy ( source )
87
+ super
88
+
89
+ configure_hosts! source . hosts
90
+ end
91
+
86
92
def udp?
87
93
udp != false
88
94
end
@@ -105,7 +111,15 @@ def hosts
105
111
end
106
112
end
107
113
108
- private
114
+ def writer_config
115
+ writer_config = dup
116
+
117
+ writer_config . set_ivar! :async , false
118
+
119
+ writer_config
120
+ end
121
+
122
+ protected
109
123
110
124
def set_ivar! ( name , value )
111
125
case name
@@ -118,6 +132,8 @@ def set_ivar!(name, value)
118
132
instance_variable_set "@#{ name } " , value
119
133
end
120
134
135
+ private
136
+
121
137
def normalize_retry_option ( value )
122
138
case value
123
139
when Integer then value
Original file line number Diff line number Diff line change 6
6
let ( :client ) { described_class . new ( async : async_options ) }
7
7
let ( :subject ) { client }
8
8
let ( :stub_url ) { "http://localhost:8086/write?db=&p=root&precision=s&u=root" }
9
- let ( :worker ) { client . writer . worker }
9
+ let ( :writer ) { client . writer }
10
+ let ( :worker ) { writer . worker }
10
11
11
12
specify { expect ( subject . writer ) . to be_a ( InfluxDB ::Writer ::Async ) }
12
13
40
41
41
42
it "writes aggregate payload to the client" do
42
43
queue = Queue . new
43
- allow ( client ) . to receive ( :write ) do |*args |
44
+ allow_any_instance_of ( InfluxDB :: Client ) . to receive ( :write ) do |_ , *args |
44
45
queue . push ( args )
45
46
end
46
47
61
62
62
63
it "writes separated payloads for each {precision, retention_policy, database} set" do
63
64
queue = Queue . new
64
- allow ( client ) . to receive ( :write ) do |*args |
65
+ allow_any_instance_of ( InfluxDB :: Client ) . to receive ( :write ) do |_ , *args |
65
66
queue . push ( args )
66
67
end
67
68
You can’t perform that action at this time.
0 commit comments