Skip to content

Commit 5d2b9bd

Browse files
ChrisBrhennevogel
authored andcommitted
Rename values to fields
Because this is how they're called in InfluxDB.
1 parent 8e70e7a commit 5d2b9bd

25 files changed

+63
-57
lines changed

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Automatically instrument your Ruby on Rails applications and write the metrics d
2525
Add the gem to your `Gemfile`:
2626

2727
```console
28-
echo 'gem "influxdb-rails"' >>Gemfile
28+
echo 'gem "influxdb-rails"' >> Gemfile
2929
bundle install
3030
```
3131

@@ -50,7 +50,7 @@ Reported ActiveSupport instrumentation hooks:
5050
- [start\_processing.action\_controller](https://guides.rubyonrails.org/active_support_instrumentation.html#start-processing-action-controller)
5151
- [process\_action.action\_controller](https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller)
5252

53-
Reported values:
53+
Reported fields:
5454

5555
```ruby
5656
controller: 48.467,
@@ -83,7 +83,7 @@ Reported ActiveSupport instrumentation hooks:
8383
- [render\_partial.action\_view](https://guides.rubyonrails.org/active_support_instrumentation.html#render-partial-action-view)
8484
- [render\_collection.action\_view](https://guides.rubyonrails.org/active_support_instrumentation.html#render-collection-action-view)
8585

86-
Reported values:
86+
Reported fields:
8787

8888
```ruby
8989
value: 48.467,
@@ -109,7 +109,7 @@ Reported ActiveSupport instrumentation hooks:
109109
- [sql.active\_record](https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record)
110110
- [instantiation.active\_record](https://guides.rubyonrails.org/active_support_instrumentation.html#instantiation-active-record)
111111

112-
Reported SQL values:
112+
Reported fields:
113113

114114
```ruby
115115
sql: "SELECT \"posts\".* FROM \"posts\"",
@@ -153,7 +153,7 @@ Reported ActiveSupport instrumentation hooks:
153153
- [enqueue.active\_job](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-active-job)
154154
- [perform.active\_job](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job)
155155

156-
Reported values:
156+
Reported fields:
157157

158158
```ruby
159159
value: 89.467
@@ -177,7 +177,7 @@ Reported ActiveSupport instrumentation hooks:
177177

178178
- [deliver.action\_mailer](https://guides.rubyonrails.org/active_support_instrumentation.html#deliver-action-mailer)
179179

180-
Reported values:
180+
Reported fields:
181181

182182
```ruby
183183
value: 1
@@ -194,12 +194,13 @@ Reported tags:
194194

195195
## Configuration
196196

197-
The only setting you actually need to configure is the name of the database
198-
within the InfluxDB server instance (don't forget to create this database!).
197+
The only settings you actually need to configure are the organization, bucket and access token.
199198

200199
```ruby
201200
InfluxDB::Rails.configure do |config|
202-
config.client.database = "rails"
201+
config.client.org = "org"
202+
config.client.bucket = "bucket"
203+
config.client.token = "token"
203204
end
204205
```
205206

@@ -234,7 +235,7 @@ class ApplicationController
234235

235236
def set_influx_data
236237
InfluxDB::Rails.current.tags = { user: current_user.id }
237-
InfluxDB::Rails.current.values = { redis_value: redis_value }
238+
InfluxDB::Rails.current.fields = { redis_value: redis_value }
238239
end
239240
end
240241
```
@@ -243,7 +244,7 @@ end
243244
If you want to add custom instrumentation, you can wrap any code into a block instrumentation
244245

245246
```ruby
246-
InfluxDB::Rails.instrument "expensive_operation", tags: { }, values: { } do
247+
InfluxDB::Rails.instrument "expensive_operation", tags: { }, fields: { } do
247248
expensive_operation
248249
end
249250
```
@@ -258,23 +259,23 @@ Reported tags:
258259
name: "expensive_operation"
259260
```
260261

261-
Reported values:
262+
Reported fields:
262263
```ruby
263264
value: 100 # execution time of the block in ms
264265
```
265266

266267
You can also overwrite the `value`
267268

268269
```ruby
269-
InfluxDB::Rails.instrument "user_count", values: { value: 1 } do
270+
InfluxDB::Rails.instrument "user_count", fields: { value: 1 } do
270271
User.create(name: 'mickey', surname: 'mouse')
271272
end
272273
```
273274

274275
or call it even without a block
275276

276277
```ruby
277-
InfluxDB::Rails.instrument "temperature", values: { value: 25 }
278+
InfluxDB::Rails.instrument "temperature", fields: { value: 25 }
278279
```
279280

280281
### Custom client configuration
@@ -285,15 +286,17 @@ to your InfluxDB server. You can access this client as well, and perform
285286
arbitrary operations on your data:
286287

287288
```ruby
288-
InfluxDB::Rails.client.write_point "events",
289+
InfluxDB::Rails.write_api.write(
290+
name: "events",
289291
tags: { url: "/foo", user_id: current_user.id, location: InfluxDB::Rails.current.location },
290-
values: { value: 0 }
292+
fields: { value: 0 }
293+
)
291294
```
292295

293296
If you do that, it might be useful to add the current context to these custom
294297
data points which can get accessed with `InfluxDB::Rails.current.location`.
295298

296-
See [influxdb-ruby](http://github.com/influxdata/influxdb-ruby) for a
299+
See [influxdb-client](https://github.com/influxdata/influxdb-client-ruby) for a
297300
full list of configuration options and detailed usage.
298301

299302
### Disabling hooks

lib/influxdb/rails/context.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Rails
33
class Context
44
def reset
55
Thread.current[:_influxdb_rails_tags] = {}
6-
Thread.current[:_influxdb_rails_values] = {}
6+
Thread.current[:_influxdb_rails_fields] = {}
77
end
88

99
def tags
@@ -14,12 +14,12 @@ def tags=(tags)
1414
Thread.current[:_influxdb_rails_tags] = self.tags.merge(tags)
1515
end
1616

17-
def values
18-
Thread.current[:_influxdb_rails_values].to_h
17+
def fields
18+
Thread.current[:_influxdb_rails_fields].to_h
1919
end
2020

21-
def values=(values)
22-
Thread.current[:_influxdb_rails_values] = self.values.merge(values)
21+
def fields=(fields)
22+
Thread.current[:_influxdb_rails_fields] = self.fields.merge(fields)
2323
end
2424
end
2525
end

lib/influxdb/rails/metric.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
module InfluxDB
44
module Rails
55
class Metric
6-
def initialize(configuration:, timestamp:, tags: {}, values: {})
6+
def initialize(configuration:, timestamp:, tags: {}, fields: {})
77
@configuration = configuration
88
@timestamp = timestamp
99
@tags = tags
10-
@values = values
10+
@fields = fields
1111
end
1212

1313
def write
@@ -16,11 +16,11 @@ def write
1616

1717
private
1818

19-
attr_reader :configuration, :tags, :values, :timestamp
19+
attr_reader :configuration, :tags, :fields, :timestamp
2020

2121
def data
2222
{
23-
fields: values.merge(InfluxDB::Rails.current.values),
23+
fields: fields.merge(InfluxDB::Rails.current.fields),
2424
tags: Tags.new(tags: tags, config: configuration).to_h,
2525
name: configuration.measurement_name,
2626
time: timestamp.utc,

lib/influxdb/rails/middleware/action_mailer_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Middleware
66
class ActionMailerSubscriber < Subscriber # :nodoc:
77
private
88

9-
def values
9+
def fields
1010
{ value: 1 }
1111
end
1212

lib/influxdb/rails/middleware/active_job_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ActiveJobSubscriber < Subscriber # :nodoc:
1313
}.freeze
1414
private_constant :JOB_STATE
1515

16-
def values
16+
def fields
1717
{
1818
value: value,
1919
}

lib/influxdb/rails/middleware/active_record_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Middleware
77
class ActiveRecordSubscriber < Subscriber # :nodoc:
88
private
99

10-
def values
10+
def fields
1111
{
1212
value: duration,
1313
record_count: payload[:record_count],

lib/influxdb/rails/middleware/block_instrumentation_subscriber.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module Middleware
66
class BlockInstrumentationSubscriber < Subscriber
77
private
88

9-
def values
9+
def fields
1010
{
1111
value: duration,
12-
}.merge(payload[:values].to_h)
12+
}.merge(payload[:fields].to_h)
1313
end
1414

1515
def tags

lib/influxdb/rails/middleware/render_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Middleware
66
class RenderSubscriber < Subscriber # :nodoc:
77
private
88

9-
def values
9+
def fields
1010
{
1111
value: duration,
1212
count: payload[:count],

lib/influxdb/rails/middleware/request_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def tags
2323
}
2424
end
2525

26-
def values
26+
def fields
2727
{
2828
controller: duration,
2929
view: (payload[:view_runtime] || 0).ceil,

lib/influxdb/rails/middleware/sql_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Middleware
77
class SqlSubscriber < Subscriber # :nodoc:
88
private
99

10-
def values
10+
def fields
1111
{
1212
value: duration,
1313
sql: InfluxDB::Rails::Sql::Normalizer.new(payload[:sql]).perform,

lib/influxdb/rails/middleware/subscriber.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def write
3939

4040
def metric
4141
InfluxDB::Rails::Metric.new(
42-
values: values,
42+
fields: fields,
4343
tags: tags,
4444
configuration: configuration,
4545
timestamp: finish
@@ -50,7 +50,7 @@ def tags
5050
raise NotImplementedError, "must be implemented in subclass"
5151
end
5252

53-
def values
53+
def fields
5454
raise NotImplementedError, "must be implemented in subclass"
5555
end
5656

lib/influxdb/rails/railtie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Railtie < ::Rails::Railtie # :nodoc:
1313
ActiveSupport.on_load(:action_controller) do
1414
before_action do
1515
current = InfluxDB::Rails.current
16-
current.values = { request_id: request.request_id } if request.respond_to?(:request_id)
16+
current.fields = { request_id: request.request_id } if request.respond_to?(:request_id)
1717
end
1818
end
1919

spec/integration/influxdb_rails_sends_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
body: "rails,hook=block_instrumentation,location=raw,name=name,server=hostname value=1i 1514797200000000000"
1111
)
1212

13-
InfluxDB::Rails.instrument "name", values: { value: 1 }
13+
InfluxDB::Rails.instrument "name", fields: { value: 1 }
1414

1515
assert_requested(request, times: 1)
1616
end

spec/requests/action_controller_metrics_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
format: :html,
2525
http_method: "GET"
2626
),
27-
values: a_hash_including(
27+
fields: a_hash_including(
2828
view: be_between(1, 500),
2929
db: be_between(1, 500),
3030
controller: be_between(1, 500)
@@ -46,8 +46,11 @@
4646
tags_middleware: :tags_middleware
4747
),
4848
fields: a_hash_including(
49-
additional_value: :value,
50-
request_id: :request_id
49+
additional_field: :value,
50+
request_id: :request_id,
51+
view: be_between(1, 500),
52+
db: be_between(1, 500),
53+
controller: be_between(1, 500)
5154
)
5255
)
5356
end

spec/requests/action_mailer_deliver_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
mailer: "MetricMailer"
2424
),
2525
fields: a_hash_including(
26-
additional_value: :value,
26+
additional_field: :value,
2727
request_id: :request_id,
2828
value: 1
2929
)

spec/requests/action_view_collection_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
filename: include("spec/support/views/metrics/_item.html.erb")
2424
),
2525
fields: a_hash_including(
26-
additional_value: :value,
26+
additional_field: :value,
2727
count: 3,
2828
request_id: :request_id,
2929
value: be_between(1, 500)

spec/requests/action_view_partial_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
filename: include("spec/support/views/metrics/_item.html.erb")
2323
),
2424
fields: a_hash_including(
25-
additional_value: :value,
25+
additional_field: :value,
2626
request_id: :request_id,
2727
value: be_between(1, 500)
2828
)

spec/requests/action_view_template_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
filename: include("spec/support/views/metrics/index.html.erb")
2323
),
2424
fields: a_hash_including(
25-
additional_value: :value,
25+
additional_field: :value,
2626
request_id: :request_id,
2727
value: be_between(1, 500)
2828
)

spec/requests/active_job_enqueue_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
state: "queued"
2626
),
2727
fields: a_hash_including(
28-
additional_value: :value,
28+
additional_field: :value,
2929
request_id: :request_id,
3030
value: 1
3131
)

spec/requests/active_record_instantiation_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class_name: "Metric"
2525
),
2626
fields: a_hash_including(
27-
additional_value: :value,
27+
additional_field: :value,
2828
request_id: :request_id,
2929
value: be_between(1, 500),
3030
record_count: 1

spec/requests/active_record_sql_metrics_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
operation: "INSERT"
2727
),
2828
fields: a_hash_including(
29-
additional_value: :value,
29+
additional_field: :value,
3030
request_id: :request_id,
3131
value: be_between(1, 500),
3232
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
@@ -47,7 +47,7 @@
4747
operation: "INSERT"
4848
),
4949
fields: a_hash_including(
50-
additional_value: :value,
50+
additional_field: :value,
5151
request_id: :request_id,
5252
value: be_between(1, 500),
5353
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"

0 commit comments

Comments
 (0)