info.tcl 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. proc cmdstat {cmd} {
  2. return [cmdrstat $cmd r]
  3. }
  4. proc errorstat {cmd} {
  5. return [errorrstat $cmd r]
  6. }
  7. start_server {tags {"info" "external:skip"}} {
  8. start_server {} {
  9. test {errorstats: failed call authentication error} {
  10. r config resetstat
  11. assert_match {} [errorstat ERR]
  12. assert_equal [s total_error_replies] 0
  13. catch {r auth k} e
  14. assert_match {ERR AUTH*} $e
  15. assert_match {*count=1*} [errorstat ERR]
  16. assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat auth]
  17. assert_equal [s total_error_replies] 1
  18. r config resetstat
  19. assert_match {} [errorstat ERR]
  20. }
  21. test {errorstats: failed call within MULTI/EXEC} {
  22. r config resetstat
  23. assert_match {} [errorstat ERR]
  24. assert_equal [s total_error_replies] 0
  25. r multi
  26. r set a b
  27. r auth a
  28. catch {r exec} e
  29. assert_match {ERR AUTH*} $e
  30. assert_match {*count=1*} [errorstat ERR]
  31. assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat set]
  32. assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat auth]
  33. assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat exec]
  34. assert_equal [s total_error_replies] 1
  35. # MULTI/EXEC command errors should still be pinpointed to him
  36. catch {r exec} e
  37. assert_match {ERR EXEC without MULTI} $e
  38. assert_match {*calls=2,*,rejected_calls=0,failed_calls=1} [cmdstat exec]
  39. assert_match {*count=2*} [errorstat ERR]
  40. assert_equal [s total_error_replies] 2
  41. }
  42. test {errorstats: failed call within LUA} {
  43. r config resetstat
  44. assert_match {} [errorstat ERR]
  45. assert_equal [s total_error_replies] 0
  46. catch {r eval {redis.pcall('XGROUP', 'CREATECONSUMER', 's1', 'mygroup', 'consumer') return } 0} e
  47. assert_match {*count=1*} [errorstat ERR]
  48. assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat xgroup\\|createconsumer]
  49. assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat eval]
  50. # EVAL command errors should still be pinpointed to him
  51. catch {r eval a} e
  52. assert_match {ERR wrong*} $e
  53. assert_match {*calls=1,*,rejected_calls=1,failed_calls=0} [cmdstat eval]
  54. assert_match {*count=2*} [errorstat ERR]
  55. assert_equal [s total_error_replies] 2
  56. }
  57. test {errorstats: failed call NOSCRIPT error} {
  58. r config resetstat
  59. assert_equal [s total_error_replies] 0
  60. assert_match {} [errorstat NOSCRIPT]
  61. catch {r evalsha NotValidShaSUM 0} e
  62. assert_match {NOSCRIPT*} $e
  63. assert_match {*count=1*} [errorstat NOSCRIPT]
  64. assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat evalsha]
  65. assert_equal [s total_error_replies] 1
  66. r config resetstat
  67. assert_match {} [errorstat NOSCRIPT]
  68. }
  69. test {errorstats: failed call NOGROUP error} {
  70. r config resetstat
  71. assert_match {} [errorstat NOGROUP]
  72. r del mystream
  73. r XADD mystream * f v
  74. catch {r XGROUP CREATECONSUMER mystream mygroup consumer} e
  75. assert_match {NOGROUP*} $e
  76. assert_match {*count=1*} [errorstat NOGROUP]
  77. assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat xgroup\\|createconsumer]
  78. r config resetstat
  79. assert_match {} [errorstat NOGROUP]
  80. }
  81. test {errorstats: rejected call unknown command} {
  82. r config resetstat
  83. assert_equal [s total_error_replies] 0
  84. assert_match {} [errorstat ERR]
  85. catch {r asdf} e
  86. assert_match {ERR unknown*} $e
  87. assert_match {*count=1*} [errorstat ERR]
  88. assert_equal [s total_error_replies] 1
  89. r config resetstat
  90. assert_match {} [errorstat ERR]
  91. }
  92. test {errorstats: rejected call within MULTI/EXEC} {
  93. r config resetstat
  94. assert_equal [s total_error_replies] 0
  95. assert_match {} [errorstat ERR]
  96. r multi
  97. catch {r set} e
  98. assert_match {ERR wrong number of arguments*} $e
  99. catch {r exec} e
  100. assert_match {EXECABORT*} $e
  101. assert_match {*count=1*} [errorstat ERR]
  102. assert_match {*count=1*} [errorstat EXECABORT]
  103. assert_equal [s total_error_replies] 2
  104. assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
  105. assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat multi]
  106. assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat exec]
  107. assert_equal [s total_error_replies] 2
  108. r config resetstat
  109. assert_match {} [errorstat ERR]
  110. }
  111. test {errorstats: rejected call due to wrong arity} {
  112. r config resetstat
  113. assert_equal [s total_error_replies] 0
  114. assert_match {} [errorstat ERR]
  115. catch {r set k} e
  116. assert_match {ERR wrong number of arguments*} $e
  117. assert_match {*count=1*} [errorstat ERR]
  118. assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
  119. # ensure that after a rejected command, valid ones are counted properly
  120. r set k1 v1
  121. r set k2 v2
  122. assert_match {calls=2,*,rejected_calls=1,failed_calls=0} [cmdstat set]
  123. assert_equal [s total_error_replies] 1
  124. }
  125. test {errorstats: rejected call by OOM error} {
  126. r config resetstat
  127. assert_equal [s total_error_replies] 0
  128. assert_match {} [errorstat OOM]
  129. r config set maxmemory 1
  130. catch {r set a b} e
  131. assert_match {OOM*} $e
  132. assert_match {*count=1*} [errorstat OOM]
  133. assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
  134. assert_equal [s total_error_replies] 1
  135. r config resetstat
  136. assert_match {} [errorstat OOM]
  137. }
  138. test {errorstats: rejected call by authorization error} {
  139. r config resetstat
  140. assert_equal [s total_error_replies] 0
  141. assert_match {} [errorstat NOPERM]
  142. r ACL SETUSER alice on >p1pp0 ~cached:* +get +info +config
  143. r auth alice p1pp0
  144. catch {r set a b} e
  145. assert_match {NOPERM*} $e
  146. assert_match {*count=1*} [errorstat NOPERM]
  147. assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
  148. assert_equal [s total_error_replies] 1
  149. r config resetstat
  150. assert_match {} [errorstat NOPERM]
  151. }
  152. }
  153. start_server {} {
  154. test {Unsafe command names are sanitized in INFO output} {
  155. catch {r host:} e
  156. set info [r info commandstats]
  157. assert_match {*cmdstat_host_:calls=1*} $info
  158. }
  159. }
  160. }