Skip to content

Implement render_template & render_partial subscriptions #53

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

Merged
merged 12 commits into from
Dec 2, 2018

Conversation

ChrisBr
Copy link
Collaborator

@ChrisBr ChrisBr commented Nov 23, 2018

Initial proposal to implement subscriptions for 👀

  • render_template.action_view
  • render_partial.action_view

https://guides.rubyonrails.org/active_support_instrumentation.html#action-view

  • Implemented ActionView::RenderSubscription class to handle the events and write to influxdb
  • Extracted convert_timestamp method to a utils class

I would also propose to move InfluxDB::Rails.handle_action_controller_metrics and the lambda in Railties class to a dedicated class.

Thanks for providing feedback ❤️

@ChrisBr ChrisBr force-pushed the view-instrumentation branch 4 times, most recently from 140984e to caaf546 Compare November 24, 2018 16:58
@ChrisBr
Copy link
Collaborator Author

ChrisBr commented Nov 24, 2018

Ok, added now some unit and integration tests.

@ChrisBr ChrisBr force-pushed the view-instrumentation branch 2 times, most recently from 7717a24 to f418005 Compare November 24, 2018 17:33
@dmke
Copy link
Collaborator

dmke commented Nov 24, 2018

Sorry, I'm currently a bit busy. Give me a few days to get things in order.

At a first glance this looks promising. I'm not a big fan of Util classes, as they tend to end up cluttered with unrelated methods. For now, this is OK, but I'm tempted to move it toinfluxdb-ruby itself (as I can see the usefulness for other consumers).

I would also propose to move InfluxDB::Rails.handle_action_controller_metrics and the lambda in Railties class to a dedicated class.

If that clears things up, go ahead.

@ChrisBr
Copy link
Collaborator Author

ChrisBr commented Nov 26, 2018

Sorry, I'm currently a bit busy. Give me a few days to get things in order.

No worries, take your time ⌚

At a first glance this looks promising. I'm not a big fan of Util classes, as they tend to end up cluttered with unrelated methods. For now, this is OK, but I'm tempted to move it to influxdb-ruby itself (as I can see the usefulness for other consumers).

Right. Maybe we can move it to a TimeConversion module to limit the scope of the mixin for now?

If that clears things up, go ahead.

Ok, cool! I will try to move it to a dedicated class then.

@ChrisBr ChrisBr force-pushed the view-instrumentation branch 2 times, most recently from f60f1d4 to 34674f9 Compare November 27, 2018 22:51
@dmke
Copy link
Collaborator

dmke commented Nov 29, 2018

FYI: I've relocated the convert_timestamp method to the influxdb gem (v0.6.2, InfluxDB.convert_timestamp), and bumped the dependency here.

@ChrisBr ChrisBr force-pushed the view-instrumentation branch from 34674f9 to c25d336 Compare November 29, 2018 23:45
@ChrisBr
Copy link
Collaborator Author

ChrisBr commented Nov 29, 2018

FYI: I've relocated the convert_timestamp method to the influxdb gem (v0.6.2, InfluxDB.convert_timestamp), and bumped the dependency here.

👍 cool, I will update tomorrow.

I added two more features:

  • 6517dc3: Adding the location to the view renderer to track down in which controller action the view was renderer

  • 1042b80: Tracking of ActiveRecord SQL, the SQL gets normalized before inserted as tags

Thanks

@dmke
Copy link
Collaborator

dmke commented Nov 30, 2018

  • 6517dc3: Adding the location to the view renderer to track down in which controller action the view was renderer

Neat :-)

  • 1042b80: Tracking of ActiveRecord SQL, the SQL gets normalized before inserted as tags

After reverting payload[:path] (#54), I wonder if this wouldn't have the same effect... I would rather have the normalized query as field value, and use table name and operation as tags (i.e. select * from users where id = xxx would yield tags: { table_name: "users", op: "select" }, values: { query: "select * ..." }). What do you think?

to follow Single Responsibilty and improve testing.
This also allows to introduce more subscriber with the same interface in the future.
to write ActionView render measurements to InfluxDB.

This commit subscribes to the following events:
* render_template.action_view
* render_partial.action_view

https://guides.rubyonrails.org/active_support_instrumentation.html#action-view

Fix InfluxCommunity#51
To know where from which controller action
the template was rendered.
@ChrisBr ChrisBr force-pushed the view-instrumentation branch from c25d336 to 4470416 Compare November 30, 2018 08:05
@ChrisBr
Copy link
Collaborator Author

ChrisBr commented Nov 30, 2018

@dmke I rebased now on the tag middleware changes and also removed the timestamp conversion module.

After reverting payload[:path] (#54), I wonder if this wouldn't have the same effect... I would rather have the normalized query as field value, and use table name and operation as tags (i.e. select * from users where id = xxx would yield tags: { table_name: "users", op: "select" }, values: { query: "select * ..." }). What do you think?

I guess / hope not as I only track SELECT INSERT UPDATE DELETE and they get normalized from their parameters so I guess the number of different queries will be limited. But I can try it out for a few days and check what happens...

I just would like to do queries like:

SELECT value FROM rails.sql GROUP_BY sql;

to see the slowest queries. I'm not too familiar with InfluxDB yet but would that be possible with a field value or what would be the advantage of the field value except that it is not limited in the number of different values like a tag?).

I can also move this last commit to a dedicated PR so that we can get in the PR and continue discussion in the other PR?

@ChrisBr
Copy link
Collaborator Author

ChrisBr commented Nov 30, 2018

I would like to get something like this:

selection_013

Skylight does something similar, they combine it with the partial and view results:

selection_014

Would that be possible with a field value? Otherwise maybe we can normalize the queries even more? But I really see a huge advantage in measuring this data 🔍

@dmke
Copy link
Collaborator

dmke commented Nov 30, 2018

I guess / hope not as I only track SELECT INSERT UPDATE DELETE and they get normalized from their parameters so I guess the number of different queries will be limited. But I can try it out for a few days and check what happens...

I'll sample a few queries from a few different Rails apps I've access to, and throw it against your normalizer. I suspect the interesting queries (those with sub-sejects, joins, and/or group-by clauses) are going to be boiled down too much. I fear that the simple regex is both too simple has a too large CPU footprint (I've seen hundrets of queries on a single page).

I just would like [...] to see the slowest queries. I'm not too familiar with InfluxDB yet but would that be possible with a field value or what would be the advantage of the field value except that it is not limited in the number of different values like a tag?).

Tags are automatically indexed and allow to be GROUP BY'ed on the server. Fields may hold arbitrary data, but you cannot use field keys in GROUP BY clauses. You may want to GROUP BY sql, if you need to sample the average (or other percentiles) for analysis.

Say you want to see the average query time in the last 24 hours in 1 hour slices, for each query. This is what you'd send to the server:

select mean(value) from "rails.sql" where time > now() - 1d group by time(1h), sql

If sql is a field, this would not be possible.

Skylight does something similar, they combine it with the partial and view results

That looks to me, as if the omit the conditions from the query (I see select from venues, but no select from venue where x in (y). This suggests two tags (table_name and op).

I can also move this last commit to a dedicated PR so that we can get in the PR and continue discussion in the other PR?

Yeah, let's do that for now.

@ChrisBr ChrisBr mentioned this pull request Nov 30, 2018
because otherwise they always run in the same order which
can cause dependencies between the specs.
@ChrisBr ChrisBr force-pushed the view-instrumentation branch from 4470416 to 8bdbbec Compare November 30, 2018 10:33
@ChrisBr
Copy link
Collaborator Author

ChrisBr commented Nov 30, 2018

I can also move this last commit to a dedicated PR so that we can get in the PR and continue discussion in the other PR?

Yeah, let's do that for now.

Dropped and opened https://github.com/influxdata/influxdb-rails/pull/55

Because it got promoted to influxdb-ruby.
@ChrisBr ChrisBr force-pushed the view-instrumentation branch from 8bdbbec to b8f4765 Compare November 30, 2018 17:44
@dmke dmke mentioned this pull request Nov 30, 2018
4 tasks
Copy link
Collaborator

@dmke dmke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from a few nitpicks, I like what I see.

@dmke dmke added this to the 1.0 milestone Dec 1, 2018
@ChrisBr ChrisBr force-pushed the view-instrumentation branch from 246e585 to 84fe374 Compare December 1, 2018 15:24
@ChrisBr
Copy link
Collaborator Author

ChrisBr commented Dec 1, 2018

@dmke thanks for the review, implemented your suggestions.

@dmke dmke merged commit 84fe374 into InfluxCommunity:1.0-beta Dec 2, 2018
@dmke
Copy link
Collaborator

dmke commented Dec 2, 2018

I've changed a few bits (Rubocop was still producing output), but this is now merged.

@ChrisBr ChrisBr deleted the view-instrumentation branch January 13, 2019 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants