Skip to content
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

Group metrics per request (breakdown table) #117

Open
ChrisBr opened this issue May 13, 2020 · 0 comments
Open

Group metrics per request (breakdown table) #117

ChrisBr opened this issue May 13, 2020 · 0 comments

Comments

@ChrisBr
Copy link
Collaborator

ChrisBr commented May 13, 2020

The request id is a unique UUID and therefore we store it in a field. Unfortunately fields can not be grouped in InfluxDB. For ActiveRecord SQL, the data schema looks for instance like this

requed_id name location value
123-456 Post Load PostController#index 100
123-456 Post Load PostController#index 80
123-456 User Load PostController#index 100

With this data schema we can only calculate the total count of all requests, total averages etc.

image

However, I would like to count on a per request basis, something like this:

requed_id name location count avg_value
123-456 Post Load PostController#index 2 90
123-456 User Load PostController#index 1 100

This has several advantages

  1. Better performance because we have precalculated values
  2. We can spot issues like n+1 queries or missing memoization

I thought about several options

  1. Continuous queries
    We use a continuous query to downsample our metrics every X seconds. I haven't looked into it in detail but I assume we will run into the same limitation that we can not group by a field in InfluxDB.

  2. Group in gem
    We would need to do the grouping as pre processing and then write another metric to InfluxDB. We already have Current so we could just store everything in a hash there and then write it together with process_action.action_controller. So for ActiveRecord SQL we could just do something like

# Store all SQL queries in Current attributes
Current.summary = { }
Current.summary["User Load"] ||= []
Current.summary["User Load"] << 100
Current.summary
# => { "User Load" => [100], "Post Load" => [100, 80] }

# Store the metrics with process_action.action_controller
Current.summary.each do |key, value|
  count = value.length
  avg_value = value / count
  Metric.new(
    hook_name: "summary",
    values: { count: count, avg_value: avg_value }
  ).write
end
@ChrisBr ChrisBr changed the title Group metrics per request Group metrics per request (breakdown table) May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant