Forgive me if this is the wrong place to ask, but was hoping to get some
help on properly identifying queries going to our primary/replica DB in
datadog's sequel integration.
The reason I'm asking here first, rather than datadog is because I think it
can be done and I have something working, but not sure if it's the correct
or most efficient way of doing it.
First off, to configure a database for tracking in DD, you call it like
this:
postgres_database =
Sequel.connect('postgres://user:password@host:port/database_name')
Datadog.configure(postgres_database, service_name: 'my-postgres-db')
The problem is, we don't have separate database objects for our
primary/replica. We have a single DB object specifying:
servers[:replica] = {host: replica_host}
to setup our replica and we use server(:replica) whenever we want to run a
query against the replica.
My rudimentary approach to getting this to work properly was to override
synchronize like this:
def synchronize(server=nil)
# Setup databases in datadog so we know which one queries are being run on.
if server == :replica
Datadog.configure(DB, service_name: 'postgres/replica')
else
Datadog.configure(DB, service_name: 'postgres/primary')
end
begin
@pool.hold(server || :default) do |conn|
# some extra tracing ...
yield conn
end
rescue => e
# log error
end
raise e
end
end
which seems like it does the right thing, but I have a suspicion that some
queries which explicitly use server(:replica) are getting tracked against
the primary, perhaps because of how the
connection pool works and threading?
Is there a more robust approach to what I'm doing above?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/bc7dde33-fdea-485b-ae29-5ddce3cf756f%40googlegroups.com.