test_analytics_db.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 analytics database."""
  10. from materialize import buildkite
  11. from materialize.test_analytics.config.mz_db_config import MzDbConfig
  12. from materialize.test_analytics.connector.test_analytics_connector import (
  13. DatabaseConnector,
  14. DatabaseConnectorImpl,
  15. DummyDatabaseConnector,
  16. )
  17. from materialize.test_analytics.data.bounded_memory.bounded_memory_minimal_search_storage import (
  18. BoundedMemoryMinimalSearchStorage,
  19. )
  20. from materialize.test_analytics.data.build.build_data_storage import BuildDataStorage
  21. from materialize.test_analytics.data.build.build_history_analysis import (
  22. BuildHistoryAnalysis,
  23. )
  24. from materialize.test_analytics.data.build_annotation.build_annotation_storage import (
  25. BuildAnnotationStorage,
  26. )
  27. from materialize.test_analytics.data.feature_benchmark.feature_benchmark_result_storage import (
  28. FeatureBenchmarkResultStorage,
  29. )
  30. from materialize.test_analytics.data.known_issues.known_issues_storage import (
  31. KnownIssuesStorage,
  32. )
  33. from materialize.test_analytics.data.output_consistency.output_consistency_stats_storage import (
  34. OutputConsistencyStatsStorage,
  35. )
  36. from materialize.test_analytics.data.parallel_benchmark.parallel_benchmark_result_storage import (
  37. ParallelBenchmarkResultStorage,
  38. )
  39. from materialize.test_analytics.data.product_limits.product_limits_result_storage import (
  40. ProductLimitsResultStorage,
  41. )
  42. from materialize.test_analytics.data.scalability_framework.scalability_framework_result_storage import (
  43. ScalabilityFrameworkResultStorage,
  44. )
  45. TEST_ANALYTICS_DATA_VERSION: int = 21
  46. class TestAnalyticsDb:
  47. __test__ = False
  48. def __init__(self, config: MzDbConfig):
  49. self.database_connector = self._create_database_connector(config)
  50. self.builds = BuildDataStorage(
  51. self.database_connector, TEST_ANALYTICS_DATA_VERSION
  52. )
  53. self.scalability_results = ScalabilityFrameworkResultStorage(
  54. self.database_connector
  55. )
  56. self.benchmark_results = FeatureBenchmarkResultStorage(self.database_connector)
  57. self.build_annotations = BuildAnnotationStorage(self.database_connector)
  58. self.build_history = BuildHistoryAnalysis(self.database_connector)
  59. self.output_consistency = OutputConsistencyStatsStorage(self.database_connector)
  60. self.known_issues = KnownIssuesStorage(self.database_connector)
  61. self.parallel_benchmark_results = ParallelBenchmarkResultStorage(
  62. self.database_connector
  63. )
  64. self.bounded_memory_search = BoundedMemoryMinimalSearchStorage(
  65. self.database_connector
  66. )
  67. self.product_limits_results = ProductLimitsResultStorage(
  68. self.database_connector
  69. )
  70. def _create_database_connector(self, config: MzDbConfig) -> DatabaseConnector:
  71. if config.enabled:
  72. return DatabaseConnectorImpl(
  73. config, current_data_version=TEST_ANALYTICS_DATA_VERSION, log_sql=True
  74. )
  75. else:
  76. return DummyDatabaseConnector(config)
  77. def submit_updates(self) -> None:
  78. """
  79. This will open a connection to the test-analytics database and submit the SQL statements.
  80. Make sure that this method is always invoked within a try-catch block.
  81. """
  82. self.database_connector.submit_update_statements()
  83. def on_upload_failed(self, e: Exception) -> None:
  84. self._communication_failed(f"Uploading results failed! {e}")
  85. def on_data_retrieval_failed(self, e: Exception) -> None:
  86. self._communication_failed(f"Loading data failed! {e}")
  87. def _communication_failed(self, message: str) -> None:
  88. if not buildkite.is_in_buildkite():
  89. print(message)
  90. if not self.shall_notify_qa_team():
  91. return
  92. buildkite.notify_qa_team_about_failure(message)
  93. def shall_notify_qa_team(self) -> bool:
  94. if buildkite.is_on_default_branch():
  95. return True
  96. settings = self.database_connector.try_get_or_query_settings()
  97. if settings is None:
  98. return True
  99. return not settings.only_notify_about_communication_failures_on_main