-
Notifications
You must be signed in to change notification settings - Fork 62
Implement SQL Subscriber #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
That would be great. As said, maybe I can also run it for a few days on our server. With the path element we pretty quickly experienced that it is not usable as a tag.
Hm, right. I will maybe dig a little into the skylight gem to see how they normalize the queries. |
Ok, seems skylight indeed does only store operation and table: require 'skylight'
result = Skylight.lex_sql("SELECT name FROM users WHERE id = 42")
puts result.inspect
# => ["SELECT FROM users", "SELECT name FROM users WHERE id = ?"] Additionally they do the normalization in a C extension. So I agree that we follow your suggestion to store operation and table as tags and the normalized query as a field value. Question: Do you think the regex will really be a problem performance wise? Do you have any other suggestion (except writing a C extension as well?). Or we just go ahead with the regex for now and implement a switch to disable this metric (e.g. when setting the series_name to nil / ""). What do you think? |
👍
I'd prefer not to write and/or maintain C extensions. Having an off-switch for a regex-based query instrumentation sounds great – but I'd have this feature disabled by default, where the consumer needs to opt-in. |
ceaaa4b
to
3637a8f
Compare
@dmke Rebased and implemented your feedback:
Please have a look again, thanks 👍 |
3637a8f
to
ca8a6f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, some nitpicks. I'm not sure whether the SimpleSubscriber
class add an unnecessary level of abstraction... let me think about this a bit.
README.md
Outdated
@@ -72,6 +73,10 @@ defined in `lib/influxdb/rails/configuration.rb` | |||
|
|||
Out of the box, you'll automatically get reporting of your controller, | |||
view, and db runtimes and rendering of template, partial and collection for each request. | |||
Reporting of SQL queries is disabled by default because it is still in experimental mode | |||
and currently requires String parsing which might cause performance issues on query | |||
intensive applications. You can enable it by setting the ``series_name_for_sql`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ``series_name_for_sql``
+ `series_name_for_sql`
timestamp: ts | ||
InfluxDB::Rails.client.write_point series_name, | ||
values: { value: value }, | ||
tags: tags(payload), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the optimization introduced in 1734e4f.
spec/unit/sql/query.rb
Outdated
end | ||
|
||
describe "#track?" do | ||
it { expect(described_class.new("INSERT").table_name).to be true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to confuse track?
with table_name
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right ... and it was not even executed because of the missing _spec.rb
postfix 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A shame Rubocop didn't catch that, whilst it complains about everything else :-D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That... causes too much work :-)
{ value: ((finished - started) * 1000).ceil } | ||
end | ||
|
||
def time_stamp(finished) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use timestamp
, not time_stamp
.
ActiveSupport instrumentation sql.active_record events are getting now also written into the InfluxDB. Therefore the RenderSubscriber was splitted into a base class which gets reused in the SqlSubscriber. The queries also getting normalized from parameters first, e.g. 'SELECT * FROM posts where id = 42' becomes 'SELECT * FROM posts where id = xxx'. This idea was shameless copied from http://stevenyue.com/blogs/tracking-sql-queries-in-rails/. https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record
ca8a6f5
to
3a46a3e
Compare
@dmke fixed
Hm, I see you ... however, the render and sql subscriber share quite some functionality 🤔 I was even thinking about moving everything into the Subscriber class and just overwrite the call method in |
Cleaner maybe, but this would be unnecessary implementation work for a temporary workaround. Pending #56, I'd like to resolve this in the next week, so you don't need to touch this ;-) |
Thanks for merging and releasing a new version ❤️ And happy birthday (xing...) 🍰 🎉 |
No problem (and thanks! 🎈) |
ActiveSupport instrumentation sql.active_record events are getting
now also written into the InfluxDB.
Therefore the RenderSubscriber was splitted into a base class
which gets reused in the SqlSubscriber.
The queries also getting normalized from parameters first, e.g.
'SELECT * FROM posts where id = 42' becomes
'SELECT * FROM posts where id = xxx'. This idea was shameless copied
from http://stevenyue.com/blogs/tracking-sql-queries-in-rails/.
https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record
This got extracted #53 and needs to get rebased as soon as #53 is merged.