-
Notifications
You must be signed in to change notification settings - Fork 253
Instrument network calls #101
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
This will make it easier to add instrumentation hooks. It also reduces the amount of duplication (for read, specifically).
Configure it on Net::LDAP instance and it will be passed to the Net::LDAP::Connection object.
Might need help with figuring out why jruby-1.9 is failing: https://travis-ci.org/ruby-ldap/ruby-net-ldap/jobs/33450895 |
Guess it's been failing consistently: https://travis-ci.org/ruby-ldap/ruby-net-ldap/builds |
Thinking about this as a way to get information about the content length on read: diff --git a/lib/net/ber/ber_parser.rb b/lib/net/ber/ber_parser.rb
index 682a599..47379b8 100644
--- a/lib/net/ber/ber_parser.rb
+++ b/lib/net/ber/ber_parser.rb
@@ -160,6 +160,7 @@ module Net::BER::BERParser
if -1 == content_length
raise Net::BER::BerError, "Indeterminite BER content length not implemented."
else
+ yield id, content_length if block_given?
data = read(content_length)
end
diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb
index 234a0a3..7c4c396 100644
--- a/lib/net/ldap.rb
+++ b/lib/net/ldap.rb
@@ -1268,14 +1268,17 @@ class Net::LDAP::Connection #:nodoc:
end
def read(syntax = Net::LDAP::AsnSyntax)
- instrument "read.net_ldap_connection", :syntax => syntax do
- @conn.read_ber(syntax)
+ instrument "read.net_ldap_connection", :conn => @conn, :syntax => syntax do |payload|
+ @conn.read_ber(syntax) do |id, content_length|
+ payload[:response_id] = id
+ payload[:content_length] = content_length
+ end
end
end
private :read
def write(packet)
- instrument "write.net_ldap_connection", :packet => packet do
+ instrument "write.net_ldap_connection", :conn => @conn, :packet => packet do
@conn.write(packet)
end
end |
Specifically, the |
Replicates the ActiveSupport::Notifications behavior.
This reverts commit ba4dfc2.
Allows us to use the same method for Net::LDAP and Net::LDAP::Connection.
@schaary would love some feedback on whether this will be considered for release or if I should instead maintain my own fork. Not sure what your contribution policies are, if they've changed since the last substantive |
search_result_ber.ber_identifier = Net::LDAP::PDU::SearchResult | ||
search_result = [2, search_result_ber] | ||
@tcp_socket.should_receive(:read_ber).and_return(search_data). | ||
and_return(search_result) |
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 could definitely be abstracted/extracted out.
Still need to update docs and instrument other methods similar to |
Only yields if block is given so #instrument can be called without one. Clarifies conditional behavior when service is set.
Turns out this could be useful even if it's unsupported. Includes documentation.
Tagging v0.7.0.
Bump master to 0.7.0
Allow failures from jruby 1.9
Pretty much removes what was there before since it was re-specing Net::LDAP::Connection#bind and wire level instrumentation.
This is because we modify what comes in (with, at the very least, :result).
This looks interesting—I'm not deep in the code enough to act on it myself, but this should probably be considered as I recall seeing a number of performance issues raised over time, and this should make it easier to find. I also agree with your general commentary about repeated complex stanzas, @mtodd. |
I realized that there were a couple unrelated changes merged into this branch (because I was reusing this branch to do work in github/ruby-net-ldap) from #102 and #103. I'm happy to fix that, though if those two PRs get merged before this, it should reduce the diff here (this is the route I would recommend). Any specific feedback that I can get working on here to get this into a state for merging? Any relevant documentation you feel is missing? |
Instrument network calls
This PR works to add hooks for instrumentation/logging around network calls.
This specific implementation works well with
ActiveSupport::Notifications
but does not depend on it, only on an object that responds toinstrument(event_name, payload, &block)
(like theMockInstrumentationService
for the tests).This wraps the new private methods
Net::LDAP::Connection#read
andNet::LDAP::Connection#write
.Thoughts?