Tracking query times #232

Closed
scottrobertson opened this Issue Nov 28, 2016 · 7 comments

Comments

Projects
None yet
3 participants
@scottrobertson

Hey. We use scoutapp.com for monitoring.

We currently track our non NoBrainer queries, but we need a way to track the queries performed by NoBrainer. What we do for manual queries is wrap it in the following:

self.instrument("RethinkDB", RethinkDB::RPP.pp(query)) do
  # call .run
end

Can you think of a way to do this globally for all NoBrainer queries? Wrapping each call is not possible (it would be incredibly messy)

@jeroenvisser101

This comment has been minimized.

Show comment
Hide comment
@jeroenvisser101

jeroenvisser101 Nov 28, 2016

Contributor

Hey @scottrobertson, we instrument our queries for Appsignal (which is great btw)

I've adapted what we use and that should work for you:

require "nobrainer"

if defined?(ScoutApp) # Adapt to match your module
  class RethinkdDBInstrumentation < NoBrainer::QueryRunner::Middleware
    def call(env)
      ScoutApp.instrument("RethinkDB", RethinkDB::RPP.pp(env[:query])) do
        @runner.call(env)
      end
    end
  end

  NoBrainer::QueryRunner.stack.insert_after(
    NoBrainer::QueryRunner::Profiler,
    RethinkdDBInstrumentation
  )
end

PS. We've been using this, but we're still figuring out how to filter parameters from this (so it wouldn't send data to the monitoring party), do you know if there's any easy way to do that? Preferably without regex magic?

Contributor

jeroenvisser101 commented Nov 28, 2016

Hey @scottrobertson, we instrument our queries for Appsignal (which is great btw)

I've adapted what we use and that should work for you:

require "nobrainer"

if defined?(ScoutApp) # Adapt to match your module
  class RethinkdDBInstrumentation < NoBrainer::QueryRunner::Middleware
    def call(env)
      ScoutApp.instrument("RethinkDB", RethinkDB::RPP.pp(env[:query])) do
        @runner.call(env)
      end
    end
  end

  NoBrainer::QueryRunner.stack.insert_after(
    NoBrainer::QueryRunner::Profiler,
    RethinkdDBInstrumentation
  )
end

PS. We've been using this, but we're still figuring out how to filter parameters from this (so it wouldn't send data to the monitoring party), do you know if there's any easy way to do that? Preferably without regex magic?

@scottrobertson

This comment has been minimized.

Show comment
Hide comment
@scottrobertson

scottrobertson Nov 28, 2016

@jeroenvisser101 awesome, that is perfect. Thank you! I wasnt aware of insert_after

@jeroenvisser101 awesome, that is perfect. Thank you! I wasnt aware of insert_after

@scottrobertson

This comment has been minimized.

Show comment
Hide comment
@scottrobertson

scottrobertson Nov 28, 2016

PS. We've been using this, but we're still figuring out how to filter parameters from this (so it wouldn't send data to the monitoring party), do you know if there's any easy way to do that? Preferably without regex magic?

Not yet sadly. The only way I can find is regex at the moment :(

PS. We've been using this, but we're still figuring out how to filter parameters from this (so it wouldn't send data to the monitoring party), do you know if there's any easy way to do that? Preferably without regex magic?

Not yet sadly. The only way I can find is regex at the moment :(

@jeroenvisser101

This comment has been minimized.

Show comment
Hide comment
@jeroenvisser101

jeroenvisser101 Nov 28, 2016

Contributor

Ah, too bad, thanks anyways :)

Contributor

jeroenvisser101 commented Nov 28, 2016

Ah, too bad, thanks anyways :)

@nviennot

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Nov 28, 2016

Owner

You can get instrumentation by doing:

class YourProfiler
  def on_query(env)
    # env is a hash with a bunch of info.
    # see https://github.com/nviennot/nobrainer/blob/master/lib/no_brainer/profiler/logger.rb for example usage
  end

  NoBrainer::Profiler.register(self.new)
end

I'm not sure how to filter out params from the query in a systematic manner :/

Owner

nviennot commented Nov 28, 2016

You can get instrumentation by doing:

class YourProfiler
  def on_query(env)
    # env is a hash with a bunch of info.
    # see https://github.com/nviennot/nobrainer/blob/master/lib/no_brainer/profiler/logger.rb for example usage
  end

  NoBrainer::Profiler.register(self.new)
end

I'm not sure how to filter out params from the query in a systematic manner :/

@scottrobertson

This comment has been minimized.

Show comment
Hide comment
@scottrobertson

scottrobertson Nov 28, 2016

Nice! Thank you

Nice! Thank you

@jeroenvisser101

This comment has been minimized.

Show comment
Hide comment
@jeroenvisser101

jeroenvisser101 Nov 28, 2016

Contributor

@nviennot that one is even better, thanks, will adapt ours too :)

Contributor

jeroenvisser101 commented Nov 28, 2016

@nviennot that one is even better, thanks, will adapt ours too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment