wallclock-lag.td 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # Test the contents of `mz_wallclock_lag_history`.
  10. #
  11. # These tests rely on testdrive's retry feature, as `mz_wallclock_lag_history`
  12. # is only refreshed periodically, so data is likely not immediately available.
  13. $ postgres-connect name=mz_system url=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  14. $ postgres-execute connection=mz_system
  15. ALTER SYSTEM SET wallclock_lag_recording_interval = '1s'
  16. > CREATE CLUSTER storage SIZE '1'
  17. > CREATE CLUSTER compute SIZE '1', REPLICATION FACTOR 2
  18. # Set up a bunch of frontiered objects and test that their wallclock lags get
  19. # reported and are reasonably small.
  20. > CREATE SOURCE src IN CLUSTER storage FROM LOAD GENERATOR counter (UP TO 100)
  21. > CREATE TABLE tbl (a int)
  22. > CREATE VIEW src_plus_tbl AS SELECT counter + a AS a FROM src, tbl
  23. > CREATE INDEX idx IN CLUSTER compute ON src_plus_tbl (a)
  24. > CREATE MATERIALIZED VIEW mv IN CLUSTER compute AS SELECT * FROM src_plus_tbl
  25. > CREATE MATERIALIZED VIEW mv_const IN CLUSTER compute AS SELECT 1
  26. > CREATE DEFAULT INDEX idx_const IN CLUSTER compute ON mv_const
  27. > CREATE CONNECTION kafka_conn
  28. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT)
  29. > CREATE CONNECTION csr_conn
  30. TO CONFLUENT SCHEMA REGISTRY (URL '${testdrive.schema-registry-url}')
  31. > CREATE SINK snk
  32. IN CLUSTER storage
  33. FROM mv
  34. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-sink1-${testdrive.seed}')
  35. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  36. ENVELOPE DEBEZIUM
  37. > SELECT DISTINCT ON(o.name, r.name)
  38. o.name, r.name, l.lag >= '0s', l.lag < '20s'
  39. FROM mz_internal.mz_wallclock_lag_history l
  40. JOIN mz_objects o ON o.id = l.object_id
  41. LEFT JOIN mz_cluster_replicas r ON r.id = l.replica_id
  42. WHERE l.object_id LIKE 'u%'
  43. ORDER BY o.name, r.name, l.occurred_at DESC
  44. idx r1 true true
  45. idx r2 true true
  46. idx_const r1 true true
  47. idx_const r2 true true
  48. mv r1 true true
  49. mv r2 true true
  50. mv <null> true true
  51. mv_const r1 true true
  52. mv_const r2 true true
  53. mv_const <null> true true
  54. snk <null> true true
  55. src <null> true true
  56. src_progress <null> true true
  57. tbl <null> true true
  58. > SELECT DISTINCT ON(o.name)
  59. o.name, l.lag >= '0s', l.lag < '20s'
  60. FROM mz_internal.mz_wallclock_global_lag_history l
  61. JOIN mz_objects o ON o.id = l.object_id
  62. WHERE l.object_id LIKE 'u%'
  63. ORDER BY o.name, l.occurred_at DESC
  64. idx true true
  65. idx_const true true
  66. mv true true
  67. mv_const true true
  68. snk true true
  69. src true true
  70. src_progress true true
  71. tbl true true
  72. > SELECT DISTINCT ON(o.name)
  73. o.name, l.lag >= '0s', l.lag < '20s'
  74. FROM mz_internal.mz_wallclock_global_lag_recent_history l
  75. JOIN mz_objects o ON o.id = l.object_id
  76. WHERE l.object_id LIKE 'u%'
  77. ORDER BY o.name, l.occurred_at DESC
  78. idx true true
  79. idx_const true true
  80. mv true true
  81. mv_const true true
  82. snk true true
  83. src true true
  84. src_progress true true
  85. tbl true true
  86. > SELECT o.name, l.lag >= '0s', l.lag < '20s'
  87. FROM mz_internal.mz_wallclock_global_lag l
  88. JOIN mz_objects o ON o.id = l.object_id
  89. WHERE l.object_id LIKE 'u%'
  90. idx true true
  91. idx_const true true
  92. mv true true
  93. mv_const true true
  94. snk true true
  95. src true true
  96. src_progress true true
  97. tbl true true
  98. > SELECT DISTINCT o.name, l.count > 0, l.labels
  99. FROM mz_internal.mz_wallclock_global_lag_histogram l
  100. JOIN mz_objects o ON o.id = l.object_id
  101. WHERE l.object_id LIKE 'u%' AND l.lag_seconds < 10
  102. idx true {}
  103. idx_const true {}
  104. mv true {}
  105. mv_const true {}
  106. snk true {}
  107. src true {}
  108. src_progress true {}
  109. tbl true {}
  110. # Test that history lag values are rounded to seconds.
  111. > SELECT DISTINCT ON(o.name, r.name)
  112. o.name, r.name, l.lag = date_trunc('second', l.lag)
  113. FROM mz_internal.mz_wallclock_lag_history l
  114. JOIN mz_objects o ON o.id = l.object_id
  115. LEFT JOIN mz_cluster_replicas r ON r.id = l.replica_id
  116. WHERE l.object_id LIKE 'u%'
  117. ORDER BY o.name, r.name, l.occurred_at DESC
  118. idx r1 true
  119. idx r2 true
  120. idx_const r1 true
  121. idx_const r2 true
  122. mv r1 true
  123. mv r2 true
  124. mv <null> true
  125. mv_const r1 true
  126. mv_const r2 true
  127. mv_const <null> true
  128. snk <null> true
  129. src <null> true
  130. src_progress <null> true
  131. tbl <null> true
  132. # Test annotation of histogram measurements with labels.
  133. $ postgres-execute connection=mz_system
  134. ALTER CLUSTER compute SET (WORKLOAD CLASS 'compute')
  135. ALTER CLUSTER storage SET (WORKLOAD CLASS 'storage')
  136. > SELECT DISTINCT o.name, l.count > 0, l.labels
  137. FROM mz_internal.mz_wallclock_global_lag_histogram l
  138. JOIN mz_objects o ON o.id = l.object_id
  139. WHERE l.object_id LIKE 'u%' AND l.lag_seconds < 10
  140. idx true "{}"
  141. idx true "{\"workload_class\":\"compute\"}"
  142. idx_const true "{}"
  143. idx_const true "{\"workload_class\":\"compute\"}"
  144. mv true "{}"
  145. mv true "{\"workload_class\":\"compute\"}"
  146. mv_const true "{}"
  147. mv_const true "{\"workload_class\":\"compute\"}"
  148. snk true "{}"
  149. snk true "{\"workload_class\":\"storage\"}"
  150. src true "{}"
  151. src true "{\"workload_class\":\"storage\"}"
  152. src_progress true "{}"
  153. tbl true "{}"
  154. # Test changing the histogram period interval.
  155. $ postgres-execute connection=mz_system
  156. ALTER SYSTEM SET wallclock_lag_histogram_period_interval = '1d'
  157. > CREATE TABLE tbl_1day (x int)
  158. > CREATE INDEX idx_1day IN CLUSTER compute ON tbl_1day (x)
  159. > SELECT DISTINCT
  160. o.name,
  161. l.period_end - l.period_start,
  162. date_trunc('day', l.period_start) = l.period_start,
  163. date_trunc('day', l.period_end) = l.period_end
  164. FROM mz_internal.mz_wallclock_global_lag_histogram l
  165. JOIN mz_objects o ON o.id = l.object_id
  166. WHERE o.name LIKE '%_1day'
  167. idx_1day 24:00:00 true true
  168. tbl_1day 24:00:00 true true
  169. $ postgres-execute connection=mz_system
  170. ALTER SYSTEM SET wallclock_lag_histogram_period_interval = '1h'
  171. > CREATE TABLE tbl_1hour (x int)
  172. > CREATE INDEX idx_1hour IN CLUSTER compute ON tbl_1day (x)
  173. > SELECT DISTINCT
  174. o.name,
  175. l.period_end - l.period_start,
  176. date_trunc('hour', l.period_start) = l.period_start,
  177. date_trunc('hour', l.period_end) = l.period_end
  178. FROM mz_internal.mz_wallclock_global_lag_histogram l
  179. JOIN mz_objects o ON o.id = l.object_id
  180. WHERE o.name LIKE '%_1hour'
  181. idx_1hour 01:00:00 true true
  182. tbl_1hour 01:00:00 true true
  183. # Test that lags of unreadable collections are NULL.
  184. > DROP CLUSTER storage CASCADE
  185. > DROP CLUSTER compute CASCADE
  186. > CREATE CLUSTER storage SIZE '1', REPLICATION FACTOR 0
  187. > CREATE CLUSTER compute SIZE '1'
  188. > CREATE SOURCE src IN CLUSTER storage FROM LOAD GENERATOR counter (UP TO 100)
  189. > CREATE INDEX idx IN CLUSTER compute ON src (counter)
  190. > CREATE MATERIALIZED VIEW mv IN CLUSTER compute AS SELECT * FROM src
  191. > CREATE SINK snk
  192. IN CLUSTER storage
  193. FROM mv
  194. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-sink1-${testdrive.seed}')
  195. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  196. ENVELOPE DEBEZIUM
  197. > SELECT DISTINCT o.name, r.name, l.lag
  198. FROM mz_internal.mz_wallclock_lag_history l
  199. JOIN mz_objects o ON o.id = l.object_id
  200. LEFT JOIN mz_cluster_replicas r ON r.id = l.replica_id
  201. WHERE l.object_id LIKE 'u%' AND o.cluster_id IS NOT NULL
  202. idx r1 <null>
  203. mv r1 <null>
  204. mv <null> <null>
  205. snk <null> <null>
  206. src <null> <null>
  207. > SELECT DISTINCT o.name, l.lag_seconds
  208. FROM mz_internal.mz_wallclock_global_lag_histogram l
  209. JOIN mz_objects o ON o.id = l.object_id
  210. WHERE l.object_id LIKE 'u%' AND o.cluster_id IS NOT NULL
  211. idx <null>
  212. mv <null>
  213. snk <null>
  214. src <null>
  215. > DROP CLUSTER storage CASCADE
  216. > DROP CLUSTER compute CASCADE