test_analytics_search.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env python3
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. import argparse
  11. from materialize.buildkite_insights.buildkite_api.buildkite_config import (
  12. MZ_PIPELINES_WITH_WILDCARD,
  13. )
  14. from materialize.test_analytics.search import test_analytics_search_logic
  15. from materialize.test_analytics.search.test_analytics_search_source import (
  16. ANY_PIPELINE_VALUE,
  17. TestAnalyticsDataSource,
  18. )
  19. if __name__ == "__main__":
  20. parser = argparse.ArgumentParser(
  21. prog="test-analytics-annotation-search",
  22. formatter_class=argparse.RawDescriptionHelpFormatter,
  23. )
  24. parser.add_argument("--test-analytics-hostname", type=str, required=True)
  25. parser.add_argument("--test-analytics-username", type=str, required=True)
  26. parser.add_argument("--test-analytics-app-password", type=str, required=True)
  27. parser.add_argument(
  28. "pipeline",
  29. choices=MZ_PIPELINES_WITH_WILDCARD,
  30. type=str,
  31. help=f"Use {ANY_PIPELINE_VALUE} for all pipelines",
  32. )
  33. parser.add_argument("pattern", type=str, help="SQL LIKE pattern")
  34. parser.add_argument(
  35. "--branch",
  36. type=str,
  37. default=None,
  38. )
  39. parser.add_argument(
  40. "--only-failed-builds",
  41. default=False,
  42. action="store_true",
  43. )
  44. parser.add_argument("--build-step-key", action="append", default=[], type=str)
  45. parser.add_argument("--not-newer-than-build-number", type=int)
  46. parser.add_argument("--max-results", default=50, type=int)
  47. parser.add_argument(
  48. "--short",
  49. default=False,
  50. action="store_true",
  51. )
  52. parser.add_argument(
  53. "--oneline",
  54. default=False,
  55. action="store_true",
  56. )
  57. args = parser.parse_args()
  58. if args.short and args.oneline:
  59. print("Note: --oneline will be ignored if --short is set")
  60. if (
  61. args.not_newer_than_build_number is not None
  62. and args.pipeline == ANY_PIPELINE_VALUE
  63. ):
  64. print(
  65. "Combining a build number offset (--not-newer-than-build-number) and searching all pipelines does not make sense"
  66. )
  67. source = TestAnalyticsDataSource(
  68. test_analytics_hostname=args.test_analytics_hostname,
  69. test_analytics_username=args.test_analytics_username,
  70. test_analytics_app_password=args.test_analytics_app_password,
  71. )
  72. try:
  73. test_analytics_search_logic.start_search(
  74. search_source=source,
  75. pipeline_slug=args.pipeline,
  76. branch=args.branch,
  77. build_step_keys=args.build_step_key,
  78. only_failed_builds=args.only_failed_builds,
  79. not_newer_than_build_number=args.not_newer_than_build_number,
  80. like_pattern=args.pattern,
  81. max_results=args.max_results,
  82. short_result_presentation=args.short,
  83. one_line_match_presentation=args.oneline,
  84. )
  85. except Exception as e:
  86. print(f"Searching the test analytics database failed: {e}")
  87. print(
  88. "Please report the problem and consider using bin/buildkite-annotation-search in the mean time."
  89. )