Skip to content

Commit f82790d

Browse files
daschlMichael Nitschinger
authored andcommitted
SPY-157: Add Auth logging.
Motivation ---------- Debugging how long authentication steps take is currently not possible. Proper logging needs to be added in order to debug authentication timeframes. Modifications ------------- Added logging infrastructure for the individual steps (list sasl mechs, and challenge/response cycles), as well as a total amount on a per-node basis. If an individual step takes over 250ms it is WARNed instead of DEBUGed, and if the total auth step takes over 1 second it it also WARNed. Note that while these timings are fixed values, in general the operation taking this long points to something wrong since it is expected to take in the 1ms range. Result ------ Auth times can now be observed both in development and production, better pointing to possible issues. Change-Id: I3deab53332251263c5a6dcf3e2bfd75538dfb24c Reviewed-on: http://review.couchbase.org/34849 Reviewed-by: Matt Ingenthron <matt@couchbase.com> Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
1 parent 5de61d7 commit f82790d

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

src/main/java/net/spy/memcached/auth/AuthThread.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright (C) 2006-2009 Dustin Sallings
3-
* Copyright (C) 2009-2013 Couchbase, Inc.
3+
* Copyright (C) 2009-2014 Couchbase, Inc.
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
@@ -32,6 +32,7 @@
3232
import net.spy.memcached.MemcachedNode;
3333
import net.spy.memcached.OperationFactory;
3434
import net.spy.memcached.compat.SpyThread;
35+
import net.spy.memcached.compat.log.Level;
3536
import net.spy.memcached.ops.Operation;
3637
import net.spy.memcached.ops.OperationCallback;
3738
import net.spy.memcached.ops.OperationStatus;
@@ -41,6 +42,18 @@
4142
*/
4243
public class AuthThread extends SpyThread {
4344

45+
/**
46+
* If a SASL step takes longer than this period in milliseconds, a warning
47+
* will be issued instead of a debug message.
48+
*/
49+
public static final int AUTH_ROUNDTRIP_THRESHOLD = 250;
50+
51+
/**
52+
* If the total AUTH steps take longer than this period in milliseconds, a
53+
* warning will be issued instead of a debug message.
54+
*/
55+
public static final int AUTH_TOTAL_THRESHOLD = 1000;
56+
4457
public static final String MECH_SEPARATOR = " ";
4558

4659
private final MemcachedConnection conn;
@@ -108,17 +121,26 @@ public void complete() {
108121
@Override
109122
public void run() {
110123
final AtomicBoolean done = new AtomicBoolean();
124+
long totalStart = System.nanoTime();
111125

112126
String[] supportedMechs;
127+
long mechsStart = System.nanoTime();
113128
if (authDescriptor.getMechs() == null
114129
|| authDescriptor.getMechs().length == 0) {
115130
supportedMechs = listSupportedSASLMechanisms(done);
116131
} else {
117132
supportedMechs = authDescriptor.getMechs();
118133
}
134+
long mechsDiff = System.nanoTime() - mechsStart;
135+
String msg = String.format("SASL List Mechanisms took %dms on %s",
136+
mechsDiff, node.toString());
137+
Level level = mechsDiff
138+
>= AUTH_ROUNDTRIP_THRESHOLD ? Level.WARN : Level.DEBUG;
139+
getLogger().log(level, msg);
119140

120141
OperationStatus priorStatus = null;
121142
while (!done.get()) {
143+
long stepStart = System.nanoTime();
122144
final CountDownLatch latch = new CountDownLatch(1);
123145
final AtomicReference<OperationStatus> foundStatus =
124146
new AtomicReference<OperationStatus>();
@@ -163,6 +185,13 @@ public void complete() {
163185
op.cancel();
164186
}
165187
done.set(true); // If we were interrupted, tear down.
188+
} finally {
189+
long stepDiff = System.nanoTime() - stepStart;
190+
msg = String.format("SASL Step took %dms on %s",
191+
stepDiff, node.toString());
192+
level = mechsDiff
193+
>= AUTH_ROUNDTRIP_THRESHOLD ? Level.WARN : Level.DEBUG;
194+
getLogger().log(level, msg);
166195
}
167196

168197
// Get the new status to inspect it.
@@ -174,6 +203,12 @@ public void complete() {
174203
}
175204
}
176205
}
206+
207+
long totalDiff = System.nanoTime() - totalStart;
208+
msg = String.format("SASL Auth took %dms on %s",
209+
totalDiff, node.toString());
210+
level = mechsDiff >= AUTH_TOTAL_THRESHOLD ? Level.WARN : Level.DEBUG;
211+
getLogger().log(level, msg);
177212
}
178213

179214
private Operation buildOperation(OperationStatus st, OperationCallback cb,

0 commit comments

Comments
 (0)