slowlog.tcl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
  2. test {SLOWLOG - check that it starts with an empty log} {
  3. if {$::external} {
  4. r slowlog reset
  5. }
  6. r slowlog len
  7. } {0}
  8. test {SLOWLOG - only logs commands taking more time than specified} {
  9. r config set slowlog-log-slower-than 100000
  10. r ping
  11. assert_equal [r slowlog len] 0
  12. r debug sleep 0.2
  13. assert_equal [r slowlog len] 1
  14. } {} {needs:debug}
  15. test {SLOWLOG - max entries is correctly handled} {
  16. r config set slowlog-log-slower-than 0
  17. r config set slowlog-max-len 10
  18. for {set i 0} {$i < 100} {incr i} {
  19. r ping
  20. }
  21. r slowlog len
  22. } {10}
  23. test {SLOWLOG - GET optional argument to limit output len works} {
  24. llength [r slowlog get 5]
  25. } {5}
  26. test {SLOWLOG - RESET subcommand works} {
  27. r config set slowlog-log-slower-than 100000
  28. r slowlog reset
  29. r slowlog len
  30. } {0}
  31. test {SLOWLOG - logged entry sanity check} {
  32. r client setname foobar
  33. r debug sleep 0.2
  34. set e [lindex [r slowlog get] 0]
  35. assert_equal [llength $e] 6
  36. if {!$::external} {
  37. assert_equal [lindex $e 0] 105
  38. }
  39. assert_equal [expr {[lindex $e 2] > 100000}] 1
  40. assert_equal [lindex $e 3] {debug sleep 0.2}
  41. assert_equal {foobar} [lindex $e 5]
  42. } {} {needs:debug}
  43. test {SLOWLOG - Certain commands are omitted that contain sensitive information} {
  44. r config set slowlog-log-slower-than 0
  45. r slowlog reset
  46. r config set masterauth ""
  47. r acl setuser slowlog-test-user +get +set
  48. r config set slowlog-log-slower-than 0
  49. r config set slowlog-log-slower-than 10000
  50. set slowlog_resp [r slowlog get]
  51. # Make sure normal configs work, but the two sensitive
  52. # commands are omitted or redacted
  53. assert_equal 4 [llength $slowlog_resp]
  54. assert_equal {slowlog reset} [lindex [lindex [r slowlog get] 3] 3]
  55. assert_equal {config set masterauth (redacted)} [lindex [lindex [r slowlog get] 2] 3]
  56. assert_equal {acl setuser (redacted) (redacted) (redacted)} [lindex [lindex [r slowlog get] 1] 3]
  57. assert_equal {config set slowlog-log-slower-than 0} [lindex [lindex [r slowlog get] 0] 3]
  58. } {} {needs:repl}
  59. test {SLOWLOG - Some commands can redact sensitive fields} {
  60. r config set slowlog-log-slower-than 0
  61. r slowlog reset
  62. r migrate [srv 0 host] [srv 0 port] key 9 5000
  63. r migrate [srv 0 host] [srv 0 port] key 9 5000 AUTH user
  64. r migrate [srv 0 host] [srv 0 port] key 9 5000 AUTH2 user password
  65. r config set slowlog-log-slower-than 10000
  66. # Make sure all 3 commands were logged, but the sensitive fields are omitted
  67. assert_equal 4 [llength [r slowlog get]]
  68. assert_match {* key 9 5000} [lindex [lindex [r slowlog get] 2] 3]
  69. assert_match {* key 9 5000 AUTH (redacted)} [lindex [lindex [r slowlog get] 1] 3]
  70. assert_match {* key 9 5000 AUTH2 (redacted) (redacted)} [lindex [lindex [r slowlog get] 0] 3]
  71. } {} {needs:repl}
  72. test {SLOWLOG - Rewritten commands are logged as their original command} {
  73. r config set slowlog-log-slower-than 0
  74. # Test rewriting client arguments
  75. r sadd set a b c d e
  76. r slowlog reset
  77. # SPOP is rewritten as DEL when all keys are removed
  78. r spop set 10
  79. assert_equal {spop set 10} [lindex [lindex [r slowlog get] 0] 3]
  80. # Test replacing client arguments
  81. r slowlog reset
  82. # GEOADD is replicated as ZADD
  83. r geoadd cool-cities -122.33207 47.60621 Seattle
  84. assert_equal {geoadd cool-cities -122.33207 47.60621 Seattle} [lindex [lindex [r slowlog get] 0] 3]
  85. # Test replacing a single command argument
  86. r set A 5
  87. r slowlog reset
  88. # GETSET is replicated as SET
  89. r getset a 5
  90. assert_equal {getset a 5} [lindex [lindex [r slowlog get] 0] 3]
  91. # INCRBYFLOAT calls rewrite multiple times, so it's a special case
  92. r set A 0
  93. r slowlog reset
  94. # INCRBYFLOAT is replicated as SET
  95. r INCRBYFLOAT A 1.0
  96. assert_equal {INCRBYFLOAT A 1.0} [lindex [lindex [r slowlog get] 0] 3]
  97. # blocked BLPOP is replicated as LPOP
  98. set rd [redis_deferring_client]
  99. $rd blpop l 0
  100. wait_for_blocked_clients_count 1 50 100
  101. r multi
  102. r lpush l foo
  103. r slowlog reset
  104. r exec
  105. $rd read
  106. $rd close
  107. assert_equal {blpop l 0} [lindex [lindex [r slowlog get] 0] 3]
  108. }
  109. test {SLOWLOG - commands with too many arguments are trimmed} {
  110. r config set slowlog-log-slower-than 0
  111. r slowlog reset
  112. r sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  113. set e [lindex [r slowlog get] end-1]
  114. lindex $e 3
  115. } {sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 {... (2 more arguments)}}
  116. test {SLOWLOG - too long arguments are trimmed} {
  117. r config set slowlog-log-slower-than 0
  118. r slowlog reset
  119. set arg [string repeat A 129]
  120. r sadd set foo $arg
  121. set e [lindex [r slowlog get] end-1]
  122. lindex $e 3
  123. } {sadd set foo {AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... (1 more bytes)}}
  124. test {SLOWLOG - EXEC is not logged, just executed commands} {
  125. r config set slowlog-log-slower-than 100000
  126. r slowlog reset
  127. assert_equal [r slowlog len] 0
  128. r multi
  129. r debug sleep 0.2
  130. r exec
  131. assert_equal [r slowlog len] 1
  132. set e [lindex [r slowlog get] 0]
  133. assert_equal [lindex $e 3] {debug sleep 0.2}
  134. } {} {needs:debug}
  135. test {SLOWLOG - can clean older entries} {
  136. r client setname lastentry_client
  137. r config set slowlog-max-len 1
  138. r debug sleep 0.2
  139. assert {[llength [r slowlog get]] == 1}
  140. set e [lindex [r slowlog get] 0]
  141. assert_equal {lastentry_client} [lindex $e 5]
  142. } {} {needs:debug}
  143. test {SLOWLOG - can be disabled} {
  144. r config set slowlog-max-len 1
  145. r config set slowlog-log-slower-than 1
  146. r slowlog reset
  147. r debug sleep 0.2
  148. assert_equal [r slowlog len] 1
  149. r config set slowlog-log-slower-than -1
  150. r slowlog reset
  151. r debug sleep 0.2
  152. assert_equal [r slowlog len] 0
  153. } {} {needs:debug}
  154. test {SLOWLOG - count must be >= -1} {
  155. assert_error "ERR count should be greater than or equal to -1" {r slowlog get -2}
  156. assert_error "ERR count should be greater than or equal to -1" {r slowlog get -222}
  157. }
  158. test {SLOWLOG - get all slow logs} {
  159. r config set slowlog-log-slower-than 0
  160. r config set slowlog-max-len 3
  161. r slowlog reset
  162. r set key test
  163. r sadd set a b c
  164. r incr num
  165. r lpush list a
  166. assert_equal [r slowlog len] 3
  167. assert_equal 0 [llength [r slowlog get 0]]
  168. assert_equal 1 [llength [r slowlog get 1]]
  169. assert_equal 3 [llength [r slowlog get -1]]
  170. assert_equal 3 [llength [r slowlog get 3]]
  171. }
  172. }