Skip to content

Commit 5100e7a

Browse files
ingenthrTrond Norbye
authored and
Trond Norbye
committed
Added new stats to track sasl authentication.
Two new stats, auth_cmds and auth_unknowns have been added to allow end users to track how often authentications commands are submitted and when they "fail". Successes can be calculated by clients. Rename to auth_errors and add to protocol.txt.
1 parent 8c0a108 commit 5100e7a

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

doc/protocol.txt

+3
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ integers separated by a colon (treat this as a floating point number).
396396
| cas_hits | 64u | Number of successful CAS reqs. |
397397
| cas_badval | 64u | Number of CAS reqs for which a key was |
398398
| | | found, but the CAS value did not match. |
399+
| auth_cmds | 64u | Number of authentication commands |
400+
| | | handled, success or failure. |
401+
| auth_errors | 64u | Number of failed authentications. |
399402
| evictions | 64u | Number of valid items removed from cache |
400403
| | | to free memory for new items |
401404
| bytes_read | 64u | Total number of bytes read by this server |

memcached.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,9 @@ static void process_bin_complete_sasl_auth(conn *c) {
16031603
switch(result) {
16041604
case SASL_OK:
16051605
write_bin_response(c, "Authenticated", 0, 0, strlen("Authenticated"));
1606+
pthread_mutex_lock(&c->thread->stats.mutex);
1607+
c->thread->stats.auth_cmds++;
1608+
pthread_mutex_unlock(&c->thread->stats.mutex);
16061609
break;
16071610
case SASL_CONTINUE:
16081611
add_bin_header(c, PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE, 0, 0, outlen);
@@ -1616,6 +1619,10 @@ static void process_bin_complete_sasl_auth(conn *c) {
16161619
if (settings.verbose)
16171620
fprintf(stderr, "Unknown sasl response: %d\n", result);
16181621
write_bin_error(c, PROTOCOL_BINARY_RESPONSE_AUTH_ERROR, 0);
1622+
pthread_mutex_lock(&c->thread->stats.mutex);
1623+
c->thread->stats.auth_cmds++;
1624+
c->thread->stats.auth_errors++;
1625+
pthread_mutex_unlock(&c->thread->stats.mutex);
16191626
}
16201627
}
16211628

@@ -2394,6 +2401,8 @@ static void server_stats(ADD_STAT add_stats, conn *c) {
23942401
APPEND_STAT("cas_misses", "%llu", (unsigned long long)thread_stats.cas_misses);
23952402
APPEND_STAT("cas_hits", "%llu", (unsigned long long)slab_stats.cas_hits);
23962403
APPEND_STAT("cas_badval", "%llu", (unsigned long long)slab_stats.cas_badval);
2404+
APPEND_STAT("auth_cmds", "%llu", (unsigned long long)thread_stats.auth_cmds);
2405+
APPEND_STAT("auth_errors", "%llu", (unsigned long long)thread_stats.auth_errors);
23972406
APPEND_STAT("bytes_read", "%llu", (unsigned long long)thread_stats.bytes_read);
23982407
APPEND_STAT("bytes_written", "%llu", (unsigned long long)thread_stats.bytes_written);
23992408
APPEND_STAT("limit_maxbytes", "%llu", (unsigned long long)settings.maxbytes);
@@ -4465,7 +4474,7 @@ int main (int argc, char **argv) {
44654474
settings.binding_protocol = binary_prot;
44664475
} else {
44674476
if (settings.binding_protocol != binary_prot) {
4468-
fprintf(stderr, "WARNING: You shouldn't allow the ASCII protocol while using SASL\n");
4477+
fprintf(stderr, "ERROR: You cannot allow the ASCII protocol while using SASL.\n");
44694478
exit(EX_USAGE);
44704479
}
44714480
}

memcached.h

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ struct thread_stats {
219219
uint64_t bytes_written;
220220
uint64_t flush_cmds;
221221
uint64_t conn_yields; /* # of yields for connections (-R option)*/
222+
uint64_t auth_cmds;
223+
uint64_t auth_errors;
222224
struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES];
223225
};
224226

t/binary-sasl.t

+14-1
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,24 @@ $check->('x','somevalue');
209209
}
210210
$empty->('x');
211211

212+
# check the SASL stats, make sure they track things correctly
213+
214+
# while authenticated, get current counter
215+
{
216+
my %stats = $mc->stats();
217+
ok(! $status);
218+
}
219+
220+
# then reauth, failing
221+
222+
# then reauth, suceeding
223+
224+
# get new stats and check that we have the expected counters
212225

213226
# Along with the assertion added to the code to verify we're staying
214227
# within bounds when we do a stats detail dump (detail turned on at
215228
# the top).
216-
#my %stats = $mc->stats('detail dump');
229+
# my %stats = $mc->stats('detail dump');
217230

218231
# ######################################################################
219232
# Test ends around here.

thread.c

+6
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ void threadlocal_stats_reset(void) {
484484
threads[ii].stats.bytes_written = 0;
485485
threads[ii].stats.flush_cmds = 0;
486486
threads[ii].stats.conn_yields = 0;
487+
threads[ii].stats.auth_cmds = 0;
488+
threads[ii].stats.auth_errors = 0;
487489

488490
for(sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) {
489491
threads[ii].stats.slab_stats[sid].set_cmds = 0;
@@ -512,6 +514,8 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) {
512514
stats->bytes_read = 0;
513515
stats->flush_cmds = 0;
514516
stats->conn_yields = 0;
517+
stats->auth_cmds = 0;
518+
stats->auth_errors = 0;
515519

516520
memset(stats->slab_stats, 0,
517521
sizeof(struct slab_stats) * MAX_NUMBER_OF_SLAB_CLASSES);
@@ -529,6 +533,8 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) {
529533
stats->bytes_written += threads[ii].stats.bytes_written;
530534
stats->flush_cmds += threads[ii].stats.flush_cmds;
531535
stats->conn_yields += threads[ii].stats.conn_yields;
536+
stats->auth_cmds += threads[ii].stats.auth_cmds;
537+
stats->auth_errors += threads[ii].stats.auth_errors;
532538

533539
for (sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) {
534540
stats->slab_stats[sid].set_cmds +=

0 commit comments

Comments
 (0)