test_metrics.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. from textwrap import dedent
  10. from materialize.cloudtest.app.materialize_application import MaterializeApplication
  11. def test_replica_metrics(mz: MaterializeApplication) -> None:
  12. mz.testdrive.run(
  13. input=dedent(
  14. """
  15. > CREATE CLUSTER my_cluster REPLICAS (my_replica (SIZE '4-4'))
  16. > SELECT process_id
  17. FROM mz_internal.mz_cluster_replica_metrics m
  18. JOIN mz_cluster_replicas cr ON m.replica_id = cr.id
  19. WHERE
  20. cr.name = 'my_replica' AND
  21. m.cpu_nano_cores IS NOT NULL AND
  22. m.memory_bytes IS NOT NULL
  23. 0
  24. 1
  25. 2
  26. 3
  27. > SELECT DISTINCT process_id
  28. FROM mz_internal.mz_cluster_replica_metrics_history m
  29. JOIN mz_cluster_replicas cr ON m.replica_id = cr.id
  30. WHERE
  31. cr.name = 'my_replica' AND
  32. m.cpu_nano_cores IS NOT NULL AND
  33. m.memory_bytes IS NOT NULL
  34. 0
  35. 1
  36. 2
  37. 3
  38. > DROP CLUSTER my_cluster
  39. """
  40. ),
  41. )
  42. def test_prometheus_sql_metrics(mz: MaterializeApplication) -> None:
  43. # We need a source to have any metrics under `metrics/mz_storage
  44. mz.testdrive.run(
  45. input=dedent(
  46. """
  47. > CREATE SOURCE counter FROM LOAD GENERATOR COUNTER
  48. """
  49. ),
  50. )
  51. def check_metrics(metric_group_name: str, metric_name: str):
  52. metrics = mz.environmentd.http_get(f"/metrics/{metric_group_name}")
  53. found = False
  54. for metric in metrics.splitlines():
  55. if metric.startswith(metric_name):
  56. found = True
  57. assert found, "could not read metrics"
  58. check_metrics("mz_frontier", "mz_read_frontier")
  59. check_metrics("mz_usage", "mz_clusters_count")
  60. check_metrics("mz_compute", "mz_compute_replica_park_duration_seconds_total")
  61. check_metrics("mz_storage", "mz_storage_objects")