02-build-job.sql 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. -- meta data of (the latest retry of) each eventually successful build job
  10. CREATE OR REPLACE VIEW v_successful_build_jobs AS
  11. SELECT
  12. b.build_id,
  13. bj.build_job_id,
  14. bj.build_step_id,
  15. b.branch,
  16. b.pipeline,
  17. b.build_number,
  18. b.commit_hash,
  19. b.mz_version,
  20. b.date,
  21. concat('https://buildkite.com/materialize/', b.pipeline, '/builds/', b.build_number, '#', bj.build_job_id),
  22. bj.build_step_key,
  23. bj.shard_index
  24. FROM build b
  25. INNER JOIN build_job bj
  26. ON b.build_id = bj.build_id
  27. WHERE bj.success = TRUE
  28. AND bj.is_latest_retry = TRUE;
  29. CREATE OR REPLACE VIEW v_build_job_success_unsharded AS
  30. SELECT
  31. bj.build_id,
  32. bj.build_step_key,
  33. date_trunc('day', min(bj.start_time)) AS day,
  34. -- success when no shard failed
  35. sum(CASE WHEN bj.success THEN 0 ELSE 1 END) = 0 AS success,
  36. sum(extract(EPOCH FROM (bj.end_time - bj.start_time))) AS duration_in_sec,
  37. count(*) as count_shards
  38. FROM build_job bj
  39. WHERE bj.is_latest_retry = TRUE
  40. GROUP BY
  41. bj.build_id,
  42. bj.build_step_key
  43. ;
  44. CREATE OR REPLACE MATERIALIZED VIEW mv_recent_build_job_success_on_main_v2
  45. IN CLUSTER test_analytics AS
  46. SELECT * FROM (
  47. SELECT
  48. row_number() OVER (
  49. PARTITION BY pipeline, build_step_key, shard_index
  50. ORDER BY build_number DESC
  51. ),
  52. pipeline,
  53. build_step_key,
  54. shard_index,
  55. build_number,
  56. build.build_id,
  57. build_job_id,
  58. success AS build_step_success
  59. FROM build_job
  60. INNER JOIN build
  61. ON build.build_id = build_job.build_id AND build.branch = 'main' AND is_latest_retry = TRUE
  62. ) WHERE row_number <= 5
  63. ;
  64. ALTER VIEW v_successful_build_jobs OWNER TO qa;
  65. ALTER VIEW v_build_job_success_unsharded OWNER TO qa;
  66. ALTER MATERIALIZED VIEW mv_recent_build_job_success_on_main_v2 OWNER TO qa;
  67. GRANT SELECT ON TABLE mv_recent_build_job_success_on_main_v2 TO "hetzner-ci";