spark-sentinel 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. spark_sentinel-0.1.0/.gitignore +32 -0
  2. spark_sentinel-0.1.0/CHANGELOG.md +23 -0
  3. spark_sentinel-0.1.0/CONTRIBUTING.md +144 -0
  4. spark_sentinel-0.1.0/LICENSE +201 -0
  5. spark_sentinel-0.1.0/PKG-INFO +194 -0
  6. spark_sentinel-0.1.0/README.md +151 -0
  7. spark_sentinel-0.1.0/docs/rule-catalog.md +63 -0
  8. spark_sentinel-0.1.0/lab/gallery/README.md +85 -0
  9. spark_sentinel-0.1.0/pyproject.toml +101 -0
  10. spark_sentinel-0.1.0/src/spark_sentinel/__init__.py +3 -0
  11. spark_sentinel-0.1.0/src/spark_sentinel/__main__.py +5 -0
  12. spark_sentinel-0.1.0/src/spark_sentinel/analysis.py +331 -0
  13. spark_sentinel-0.1.0/src/spark_sentinel/cli.py +390 -0
  14. spark_sentinel-0.1.0/src/spark_sentinel/config.py +138 -0
  15. spark_sentinel-0.1.0/src/spark_sentinel/docs_links.py +51 -0
  16. spark_sentinel-0.1.0/src/spark_sentinel/findings.py +294 -0
  17. spark_sentinel-0.1.0/src/spark_sentinel/parser.py +476 -0
  18. spark_sentinel-0.1.0/src/spark_sentinel/plan.py +188 -0
  19. spark_sentinel-0.1.0/src/spark_sentinel/profiles.py +42 -0
  20. spark_sentinel-0.1.0/src/spark_sentinel/reader.py +334 -0
  21. spark_sentinel-0.1.0/src/spark_sentinel/report/__init__.py +152 -0
  22. spark_sentinel-0.1.0/src/spark_sentinel/report/_code.py +33 -0
  23. spark_sentinel-0.1.0/src/spark_sentinel/report/html.py +121 -0
  24. spark_sentinel-0.1.0/src/spark_sentinel/report/markdown.py +96 -0
  25. spark_sentinel-0.1.0/src/spark_sentinel/report/templates/report.html.j2 +217 -0
  26. spark_sentinel-0.1.0/src/spark_sentinel/report/text.py +87 -0
  27. spark_sentinel-0.1.0/src/spark_sentinel/rules/__init__.py +111 -0
  28. spark_sentinel-0.1.0/src/spark_sentinel/rules/_common.py +75 -0
  29. spark_sentinel-0.1.0/src/spark_sentinel/rules/conf.py +94 -0
  30. spark_sentinel-0.1.0/src/spark_sentinel/rules/files.py +102 -0
  31. spark_sentinel-0.1.0/src/spark_sentinel/rules/gc.py +101 -0
  32. spark_sentinel-0.1.0/src/spark_sentinel/rules/joins.py +130 -0
  33. spark_sentinel-0.1.0/src/spark_sentinel/rules/parallelism.py +192 -0
  34. spark_sentinel-0.1.0/src/spark_sentinel/rules/partitions.py +162 -0
  35. spark_sentinel-0.1.0/src/spark_sentinel/rules/plan_smells.py +239 -0
  36. spark_sentinel-0.1.0/src/spark_sentinel/rules/skew.py +200 -0
  37. spark_sentinel-0.1.0/src/spark_sentinel/rules/spill.py +110 -0
  38. spark_sentinel-0.1.0/src/spark_sentinel/store.py +324 -0
  39. spark_sentinel-0.1.0/tests/conftest.py +179 -0
  40. spark_sentinel-0.1.0/tests/fixtures/.gitkeep +0 -0
  41. spark_sentinel-0.1.0/tests/fixtures/eventlogs/clean_rolled/eventlog_v2_local-1795455921113/.appstatus_local-1795455921113.crc +0 -0
  42. spark_sentinel-0.1.0/tests/fixtures/eventlogs/clean_rolled/eventlog_v2_local-1795455921113/appstatus_local-1795455921113 +0 -0
  43. spark_sentinel-0.1.0/tests/fixtures/eventlogs/clean_rolled/eventlog_v2_local-1795455921113/events_1_local-1795455921113.zstd +0 -0
  44. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/clean/eventlog_v2_local-1795525473883/.appstatus_local-1795525473883.crc +0 -0
  45. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/clean/eventlog_v2_local-1795525473883/appstatus_local-1795525473883 +0 -0
  46. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/clean/eventlog_v2_local-1795525473883/events_1_local-1795525473883.zstd +0 -0
  47. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/cross_join/eventlog_v2_local-1795532786148/.appstatus_local-1795532786148.crc +0 -0
  48. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/cross_join/eventlog_v2_local-1795532786148/appstatus_local-1795532786148 +0 -0
  49. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/cross_join/eventlog_v2_local-1795532786148/events_1_local-1795532786148.zstd +0 -0
  50. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/few_tasks/eventlog_v2_local-1795536477846/.appstatus_local-1795536477846.crc +0 -0
  51. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/few_tasks/eventlog_v2_local-1795536477846/appstatus_local-1795536477846 +0 -0
  52. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/few_tasks/eventlog_v2_local-1795536477846/events_1_local-1795536477846.zstd +0 -0
  53. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/gc_pressure/eventlog_v2_local-1795536370854/.appstatus_local-1795536370854.crc +0 -0
  54. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/gc_pressure/eventlog_v2_local-1795536370854/appstatus_local-1795536370854 +0 -0
  55. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/gc_pressure/eventlog_v2_local-1795536370854/events_1_local-1795536370854.zstd +0 -0
  56. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/over_partitioned/eventlog_v2_local-1795525587477/.appstatus_local-1795525587477.crc +0 -0
  57. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/over_partitioned/eventlog_v2_local-1795525587477/appstatus_local-1795525587477 +0 -0
  58. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/over_partitioned/eventlog_v2_local-1795525587477/events_1_local-1795525587477.zstd +0 -0
  59. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/python_udf/eventlog_v2_local-1795536497682/.appstatus_local-1795536497682.crc +0 -0
  60. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/python_udf/eventlog_v2_local-1795536497682/appstatus_local-1795536497682 +0 -0
  61. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/python_udf/eventlog_v2_local-1795536497682/events_1_local-1795536497682.zstd +0 -0
  62. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/skew/eventlog_v2_local-1795525495428/.appstatus_local-1795525495428.crc +0 -0
  63. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/skew/eventlog_v2_local-1795525495428/appstatus_local-1795525495428 +0 -0
  64. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/skew/eventlog_v2_local-1795525495428/events_1_local-1795525495428.zstd +0 -0
  65. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/small_files/eventlog_v2_local-1795525558236/.appstatus_local-1795525558236.crc +0 -0
  66. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/small_files/eventlog_v2_local-1795525558236/appstatus_local-1795525558236 +0 -0
  67. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/small_files/eventlog_v2_local-1795525558236/events_1_local-1795525558236.zstd +0 -0
  68. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/spill/eventlog_v2_local-1795525514226/.appstatus_local-1795525514226.crc +0 -0
  69. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/spill/eventlog_v2_local-1795525514226/appstatus_local-1795525514226 +0 -0
  70. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/spill/eventlog_v2_local-1795525514226/events_1_local-1795525514226.zstd +0 -0
  71. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/udf_filter/eventlog_v2_local-1795525541006/.appstatus_local-1795525541006.crc +0 -0
  72. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/udf_filter/eventlog_v2_local-1795525541006/appstatus_local-1795525541006 +0 -0
  73. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/udf_filter/eventlog_v2_local-1795525541006/events_1_local-1795525541006.zstd +0 -0
  74. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/window_no_partition/eventlog_v2_local-1795536354927/.appstatus_local-1795536354927.crc +0 -0
  75. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/window_no_partition/eventlog_v2_local-1795536354927/appstatus_local-1795536354927 +0 -0
  76. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery/window_no_partition/eventlog_v2_local-1795536354927/events_1_local-1795536354927.zstd +0 -0
  77. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/clean/local-1795534146043.zstd +0 -0
  78. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/cross_join/local-1795534244168.zstd +0 -0
  79. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/few_tasks/local-1795536547640.zstd +0 -0
  80. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/gc_pressure/local-1795536580725.zstd +0 -0
  81. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/over_partitioned/local-1795534227219.zstd +0 -0
  82. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/python_udf/local-1795536566068.zstd +0 -0
  83. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/skew/local-1795534157177.zstd +0 -0
  84. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/small_files/local-1795534205208.zstd +0 -0
  85. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/spill/local-1795534172033.zstd +0 -0
  86. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/udf_filter/local-1795534192462.zstd +0 -0
  87. spark_sentinel-0.1.0/tests/fixtures/eventlogs/gallery-spark35/window_no_partition/local-1795536532758.zstd +0 -0
  88. spark_sentinel-0.1.0/tests/test_analysis.py +338 -0
  89. spark_sentinel-0.1.0/tests/test_cli.py +24 -0
  90. spark_sentinel-0.1.0/tests/test_findings.py +150 -0
  91. spark_sentinel-0.1.0/tests/test_matrix.py +324 -0
  92. spark_sentinel-0.1.0/tests/test_parser.py +435 -0
  93. spark_sentinel-0.1.0/tests/test_reader.py +314 -0
  94. spark_sentinel-0.1.0/tests/test_report.py +333 -0
  95. spark_sentinel-0.1.0/tests/test_rules.py +262 -0
  96. spark_sentinel-0.1.0/tests/test_rules_docs_batch.py +319 -0
  97. spark_sentinel-0.1.0/tests/test_stack.py +58 -0
  98. spark_sentinel-0.1.0/tests/test_store.py +335 -0
@@ -0,0 +1,32 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+
10
+ # Tools
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ .coverage
14
+ htmlcov/
15
+
16
+ # Spark output from lab jobs
17
+ lab/out/
18
+ lab/eventlogs/
19
+ spark-warehouse/
20
+ metastore_db/
21
+ derby.log
22
+
23
+ # Sentinel output
24
+ .sentinel/
25
+
26
+ # Editors / OS
27
+ .vscode/
28
+ .idea/
29
+ .DS_Store
30
+ Thumbs.db
31
+ *:Zone.Identifier
32
+ lab/data/
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-11-24)
4
+
5
+ First release.
6
+
7
+ **Rules (13)**, each citing the Spark or PySpark doc section its advice follows:
8
+ SKEW001 task skew (data vs compute vs GC), SPILL001 spill to disk, GC001 garbage-collection
9
+ pressure, FILES001 small output files, PART001 / PART002 too many / too few shuffle partitions,
10
+ PAR001 fewer tasks than cores, PLAN001 Python UDF in a filter, PLAN002 cartesian or nested-loop
11
+ join, PLAN003 all data through one task, PLAN004 missed broadcast join, PLAN005 row-by-row Python
12
+ UDF, CONF001 automatic optimizations turned off.
13
+
14
+ **Commands:** `analyze` (text, Markdown, HTML and JSON reports; `--profile`, `--select`,
15
+ `--ignore`, `--threshold`, `--fail-on`; `sentinel.toml`), `ingest`, `sql`, `apps`, `rules`,
16
+ `inspect`, `parse`, `doctor`.
17
+
18
+ **Event logs:** plain, zstd and gzip; single files and rolled `eventlog_v2_*` folders; logs of
19
+ apps still running or that crashed; symlinked log folders. Spark 3.5 and 4.x.
20
+
21
+ **Testing:** a gallery of 11 Spark jobs (10 with a deliberate problem, 1 clean), with logs from
22
+ Spark 4.3 and 3.5. Every job must trigger exactly its rules and the clean job none, under both
23
+ threshold profiles.
@@ -0,0 +1,144 @@
1
+ # Contributing to Spark Sentinel
2
+
3
+ Thanks for helping. The most valuable contribution is a new rule: one more Spark performance
4
+ problem that Sentinel can find and explain. This guide covers setup, the layout, how to add a
5
+ rule, and how releases work.
6
+
7
+ ## Setup
8
+
9
+ ```bash
10
+ git clone https://github.com/r4otxrhs3/spark-sentinel.git
11
+ cd spark-sentinel
12
+ python3 -m venv .venv && source .venv/bin/activate
13
+ pip install -e ".[dev,lab]" # lab = PySpark, only needed to run the gallery jobs
14
+
15
+ pytest # the whole suite runs in ~30 s, no Spark needed
16
+ ruff check . && ruff format --check .
17
+ ```
18
+
19
+ Running the gallery jobs (to create new event logs) needs Java 17 or 21. On Windows, use WSL.
20
+
21
+ ## Layout
22
+
23
+ ```
24
+ src/spark_sentinel/
25
+ reader.py find logs, decompress (plain, zstd, gzip), stream lines; rolled logs
26
+ parser.py events -> tables (spec: docs/eventlog-fields.md)
27
+ store.py tables -> Parquet warehouse, queried with DuckDB
28
+ plan.py read formatted physical plans: final-plan nodes, tree, runtime sizes
29
+ analysis.py runs rules; AnalysisContext gives rules SQL access, config, locations
30
+ findings.py the Finding every rule returns
31
+ rules/ one module per family of rules
32
+ docs_links.py links to the Spark docs sections rules cite
33
+ report/ text, Markdown, HTML and JSON reports
34
+ profiles.py threshold profiles (default, laptop)
35
+ lab/gallery/ PySpark jobs that cause each problem on purpose, plus a clean job
36
+ tests/ pytest; tests/fixtures/eventlogs holds the gallery's logs (Spark 4.3, 3.5)
37
+ docs/ event-log field spec, rule catalog, images
38
+ scripts/ maintenance scripts (the demo GIF)
39
+ ```
40
+
41
+ ## Adding a rule
42
+
43
+ A rule is only as good as its false-alarm rate, so every rule goes through the same loop. Look
44
+ at an existing rule of the same kind first (`rules/spill.py` for metric rules,
45
+ `rules/joins.py` for plan rules).
46
+
47
+ **1. Reproduce the problem.** Write `lab/gallery/<problem>.py`, a small PySpark job that causes
48
+ it on purpose (copy an existing one; `_spark.start()` sets up event logging). Add it to `JOBS`
49
+ in `lab/gallery/run_all.py` and run it:
50
+
51
+ ```bash
52
+ SENTINEL_DEFAULT_EVENTLOG=1 python lab/gallery/run_all.py <problem>
53
+ ```
54
+
55
+ Check the signal is clear (and not merely a side effect of a laptop run). Spark can surprise
56
+ you: it may optimize the problem away, or the first wave of tasks may be slow from JVM warm-up.
57
+
58
+ **2. Find the signal with SQL before writing code.**
59
+
60
+ ```bash
61
+ sentinel ingest lab/eventlogs/gallery/<problem>
62
+ sentinel sql "SELECT stage_id, count(*), median(duration_ms), max(duration_ms) FROM tasks GROUP BY 1"
63
+ sentinel parse lab/eventlogs/gallery/<problem> --show sql # the physical plans
64
+ ```
65
+
66
+ **3. Write the rule** in `src/spark_sentinel/rules/` (new module or an existing one):
67
+
68
+ ```python
69
+ class MyRule(Rule):
70
+ id = "AREA001" # letters + 3 digits, unique
71
+ name = "Short name"
72
+ category = "plan"
73
+ description = "One or two sentences: what's wrong and why it costs time."
74
+ thresholds = {"min_bytes": 512 * MB} # every number you compare against
75
+ docs = (docs_links.SOME_SECTION,) # the Spark docs the advice follows
76
+
77
+ def evaluate(self, ctx: AnalysisContext) -> Iterator[Finding]:
78
+ for row in ctx.rows("SELECT ... HAVING x >= ?", [self.t("min_bytes")]):
79
+ yield Finding(
80
+ rule_id=self.id,
81
+ severity=Severity.MEDIUM,
82
+ title=f"Stage {row['stage_id']}: ...",
83
+ location=ctx.locate_stage(row["stage_id"], row["stage_attempt"]),
84
+ evidence=(Evidence("...", row["x"], Unit.BYTES, target, "target"),),
85
+ cause="What happened, in one or two sentences.",
86
+ fix=("The most effective fix first, as a full sentence.",),
87
+ )
88
+ ```
89
+
90
+ Defining the class registers it. Things the tests will hold you to:
91
+
92
+ - **Titles** start with `Stage N:`, `Query N:` or `App:`. **Causes and fixes** are full
93
+ sentences. **Evidence** never shows `None`, `nan` or `inf`.
94
+ - **Ratios in SQL** need `NULLIF(x, 0)`: in DuckDB `x / 0` is `inf`, not `NULL`.
95
+ - **Plan rules** read `ctx.plans` (the final plan after AQE), never the raw text: a plan lists
96
+ every node twice.
97
+ - **Settings**: use `ctx.conf(key)`, which fills in Spark's defaults. A missing key means
98
+ "default", not "off".
99
+ - **Cite the docs**: add the section to `docs_links.py` if it isn't there, with its anchor.
100
+
101
+ **4. Tune it on the whole gallery**, not just your job: it must fire on its job and stay silent
102
+ on every other one, especially `clean`. If it needs lower thresholds on laptop-sized data, add
103
+ them to the `laptop` profile in `profiles.py`.
104
+
105
+ **5. Add the fixtures and tests.**
106
+
107
+ - Copy the job's log into `tests/fixtures/eventlogs/gallery/<problem>/` (Spark 4.x) and, from a
108
+ Spark 3.5 run, into `gallery-spark35/` (compress it with zstd; see the existing ones).
109
+ - Add a column for your rule to the table in `lab/gallery/README.md`: `✅` fires with default
110
+ thresholds, `✅*` only with the laptop profile, `x2` if it fires on two stages.
111
+ `tests/test_matrix.py` reads that table, so the matrix, quality-contract and false-alarm
112
+ tests now cover your rule.
113
+ - Add boundary tests (fires exactly at the threshold, not one below) and tests for each cause
114
+ your rule diagnoses, using the synthetic `AppBuilder` in `tests/conftest.py`.
115
+ - Add the rule to `docs/rule-catalog.md` and the table in `README.md`.
116
+
117
+ **6. Check that your tests can fail.** Break your rule on purpose (flip a `>=`, drop a condition)
118
+ and make sure a test goes red.
119
+
120
+ ## Style
121
+
122
+ - `ruff check . && ruff format .` before committing; CI runs both.
123
+ - Write user-facing text (titles, causes, fixes, docs) in plain language: say what happened and
124
+ what to do, with the numbers.
125
+
126
+ ## Releasing (maintainers)
127
+
128
+ One-time setup, so GitHub can publish without any stored password or token:
129
+
130
+ 1. On [pypi.org](https://pypi.org), go to *Your account → Publishing → Add a new pending
131
+ publisher* and enter: project `spark-sentinel`, owner `r4otxrhs3`, repository
132
+ `spark-sentinel`, workflow `release.yml`, environment `pypi`.
133
+ 2. On GitHub, create an environment called `pypi` (*Settings → Environments*).
134
+
135
+ Each release:
136
+
137
+ 1. Update `__version__` in `src/spark_sentinel/__init__.py` and add a section to
138
+ `CHANGELOG.md`.
139
+ 2. Commit, then tag and push: `git tag v0.1.0 && git push origin main v0.1.0`.
140
+ 3. The `Release` workflow checks that the tag matches the version, runs the tests, builds,
141
+ checks the package, and publishes to PyPI.
142
+
143
+ To regenerate the demo GIF after changing the report format: `pip install pillow` then
144
+ `python scripts/make_demo_gif.py`.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.5
2
+ Name: spark-sentinel
3
+ Version: 0.1.0
4
+ Summary: Find performance problems in Apache Spark jobs from their event logs: skew, spill, small files, bad joins, Python UDFs and more.
5
+ Project-URL: Homepage, https://github.com/r4otxrhs3/spark-sentinel
6
+ Project-URL: Repository, https://github.com/r4otxrhs3/spark-sentinel
7
+ Project-URL: Issues, https://github.com/r4otxrhs3/spark-sentinel/issues
8
+ Project-URL: Changelog, https://github.com/r4otxrhs3/spark-sentinel/blob/main/CHANGELOG.md
9
+ Project-URL: Rules, https://github.com/r4otxrhs3/spark-sentinel/blob/main/docs/rule-catalog.md
10
+ Author: Rittika Sarkar
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: apache-spark,ci,data-engineering,event-log,linter,performance,pyspark,spark
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Science/Research
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Database
26
+ Classifier: Topic :: Software Development :: Quality Assurance
27
+ Classifier: Topic :: System :: Monitoring
28
+ Requires-Python: >=3.11
29
+ Requires-Dist: duckdb>=1.1.3
30
+ Requires-Dist: jinja2>=3.1.4
31
+ Requires-Dist: orjson>=3.10
32
+ Requires-Dist: pyarrow>=18
33
+ Requires-Dist: typer>=0.13.1
34
+ Requires-Dist: zstandard>=0.23
35
+ Provides-Extra: dev
36
+ Requires-Dist: build>=1.2; extra == 'dev'
37
+ Requires-Dist: pytest>=8; extra == 'dev'
38
+ Requires-Dist: ruff>=0.8; extra == 'dev'
39
+ Requires-Dist: twine>=6; extra == 'dev'
40
+ Provides-Extra: lab
41
+ Requires-Dist: pyspark>=4.0; extra == 'lab'
42
+ Description-Content-Type: text/markdown
43
+
44
+ # Spark Sentinel
45
+
46
+ [![PyPI](https://img.shields.io/pypi/v/spark-sentinel)](https://pypi.org/project/spark-sentinel/)
47
+ [![Python](https://img.shields.io/pypi/pyversions/spark-sentinel)](https://pypi.org/project/spark-sentinel/)
48
+ [![CI](https://github.com/r4otxrhs3/spark-sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/r4otxrhs3/spark-sentinel/actions/workflows/ci.yml)
49
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/r4otxrhs3/spark-sentinel/blob/main/LICENSE)
50
+
51
+ **Find performance problems in Apache Spark jobs from their event logs, and learn how to fix
52
+ them.** Skew, spill, small files, missed broadcast joins, row-by-row Python UDFs, idle cores and
53
+ more, each traced to the stage and SQL query that caused it, with a concrete fix and a link to
54
+ the Spark documentation behind it.
55
+
56
+ ![Spark Sentinel analysing a skewed job in the terminal](https://raw.githubusercontent.com/r4otxrhs3/spark-sentinel/main/docs/images/demo.gif)
57
+
58
+ - **No code changes.** It reads the event log Spark already writes (the same file the History
59
+ Server uses).
60
+ - **No cluster needed.** Runs on your laptop, on logs from anywhere: local runs, Databricks, EMR,
61
+ Kubernetes, Spark 3.5 and 4.x.
62
+ - **Made for CI.** `--fail-on high` turns a performance regression into a failed build.
63
+
64
+ ## Install
65
+
66
+ ```bash
67
+ pipx install spark-sentinel # or: pip install spark-sentinel
68
+ uvx spark-sentinel analyze ... # or run it without installing
69
+ ```
70
+
71
+ Python 3.11+. You don't need Spark or Java to run Sentinel, only an event log.
72
+
73
+ ## Quick start
74
+
75
+ 1. Turn on event logging for your Spark job:
76
+
77
+ ```python
78
+ spark = (
79
+ SparkSession.builder.config("spark.eventLog.enabled", "true")
80
+ .config("spark.eventLog.dir", "file:///tmp/spark-events")
81
+ .getOrCreate()
82
+ )
83
+ ```
84
+
85
+ On a cluster, logs are usually already on: look where `spark.eventLog.dir` points and copy
86
+ the log to your machine.
87
+
88
+ 2. Analyze it:
89
+
90
+ ```bash
91
+ sentinel analyze /tmp/spark-events # every log in the folder
92
+ sentinel analyze /tmp/spark-events -f html -o report.html
93
+ ```
94
+
95
+ 3. Small local runs finish in seconds, so their problems are small too. Use the laptop profile
96
+ to see them: `sentinel analyze /tmp/spark-events --profile laptop`.
97
+
98
+ The HTML report is one self-contained file that works offline, in light and dark mode:
99
+
100
+ ![The HTML report: verdict, app index and a skew finding with evidence bars](https://raw.githubusercontent.com/r4otxrhs3/spark-sentinel/main/docs/images/report.png)
101
+
102
+ ## What it finds
103
+
104
+ | Rule | Problem | Based on (Spark docs) |
105
+ |---|---|---|
106
+ | `SKEW001` | One task takes far longer than its siblings; tells data skew from compute skew | [Optimizing Skew Join](https://spark.apache.org/docs/latest/sql-performance-tuning.html#optimizing-skew-join) |
107
+ | `SPILL001` | Tasks spill to disk for lack of execution memory | [Memory Usage of Reduce Tasks](https://spark.apache.org/docs/latest/tuning.html#memory-usage-of-reduce-tasks) |
108
+ | `GC001` | Tasks spend a large share of their time in garbage collection | [Garbage Collection Tuning](https://spark.apache.org/docs/latest/tuning.html#garbage-collection-tuning) |
109
+ | `FILES001` | A write produces many small files | [Coalesce Hints](https://spark.apache.org/docs/latest/sql-performance-tuning.html#coalesce-hints) |
110
+ | `PART001` | Too many shuffle partitions for the data | [Coalescing Post Shuffle Partitions](https://spark.apache.org/docs/latest/sql-performance-tuning.html#coalescing-post-shuffle-partitions) |
111
+ | `PART002` | Too few shuffle partitions: huge tasks | [Tuning Partitions](https://spark.apache.org/docs/latest/sql-performance-tuning.html#tuning-partitions) |
112
+ | `PAR001` | A long stage with fewer tasks than cores | [Level of Parallelism](https://spark.apache.org/docs/latest/tuning.html#level-of-parallelism) |
113
+ | `PLAN001` | A Python UDF in a filter blocks pushdown into the file scan | [Arrow Python UDFs](https://spark.apache.org/docs/latest/api/python/tutorial/sql/arrow_pandas.html#arrow-python-udfs) |
114
+ | `PLAN002` | A join without an equality key: cartesian or nested-loop join | [Join Strategy Hints](https://spark.apache.org/docs/latest/sql-performance-tuning.html#join-strategy-hints) |
115
+ | `PLAN003` | All of a query's data goes through one task (e.g. a window without `partitionBy`) | [Avoid computation on single partition](https://spark.apache.org/docs/latest/api/python/tutorial/pandas_on_spark/best_practices.html#avoid-computation-on-single-partition) |
116
+ | `PLAN004` | A sort-merge join where one side was small enough to broadcast | [Automatically Broadcasting Joins](https://spark.apache.org/docs/latest/sql-performance-tuning.html#automatically-broadcasting-joins) |
117
+ | `PLAN005` | A Python UDF runs row by row instead of in Arrow batches | [Arrow Python UDFs](https://spark.apache.org/docs/latest/api/python/tutorial/sql/arrow_pandas.html#arrow-python-udfs) |
118
+ | `CONF001` | Settings that switch off Spark's automatic optimizations (info) | [Adaptive Query Execution](https://spark.apache.org/docs/latest/sql-performance-tuning.html#adaptive-query-execution) |
119
+
120
+ The [rule catalog](https://github.com/r4otxrhs3/spark-sentinel/blob/main/docs/rule-catalog.md)
121
+ maps every section of Spark's tuning guides to the symptom Sentinel looks for, including what's
122
+ planned next and what an event log can't show. `sentinel rules` lists the rules with their
123
+ thresholds.
124
+
125
+ Every rule is tested against a [gallery of deliberately bad Spark jobs](https://github.com/r4otxrhs3/spark-sentinel/tree/main/lab/gallery),
126
+ run on Spark 3.5 and 4.3: each job must trigger its rule, and a clean job must trigger none.
127
+
128
+ ## Use it in CI
129
+
130
+ ```bash
131
+ sentinel analyze path/to/eventlogs --fail-on high -f md -o sentinel.md
132
+ ```
133
+
134
+ | Exit code | Meaning |
135
+ |---|---|
136
+ | 0 | Analysis ran; nothing at or above `--fail-on` (default: never fail on findings) |
137
+ | 1 | A finding at or above `--fail-on` |
138
+ | 2 | Bad options or config |
139
+ | 3 | An event log couldn't be read, or a rule crashed |
140
+
141
+ Settings can live in a `sentinel.toml` next to your code (command-line options override it):
142
+
143
+ ```toml
144
+ profile = "default" # or "laptop" for small test jobs
145
+ fail_on = "high"
146
+ format = "md"
147
+ ignore = ["CONF001"]
148
+
149
+ [thresholds.SKEW001]
150
+ min_time_lost_ms = 60000
151
+ ```
152
+
153
+ ## Commands
154
+
155
+ | Command | What it does |
156
+ |---|---|
157
+ | `sentinel analyze PATH...` | Read logs (if given) and report problems: `--format text\|md\|html\|json`, `--profile`, `--select`, `--ignore`, `--threshold RULE.name=value`, `--fail-on` |
158
+ | `sentinel ingest PATH` | Parse logs once into a local Parquet warehouse (`.sentinel/`) |
159
+ | `sentinel sql "SELECT ..."` | Query the stored tables (`tasks`, `stages`, `jobs`, `sql`, `executors`, `config`, ...) with DuckDB |
160
+ | `sentinel apps` | List ingested apps |
161
+ | `sentinel rules` | List rules and their thresholds |
162
+ | `sentinel inspect PATH` | Show how a log is stored and count its events |
163
+
164
+ ## How it works
165
+
166
+ ```
167
+ event log ─▶ reader ─▶ parser ─▶ Parquet tables ─▶ DuckDB SQL ─▶ rules ─▶ report
168
+ (plain, (streams (tasks, stages, (parse once, (one SQL query (text, md,
169
+ zstd, gzip, lines) jobs, sql plans, query many + diagnosis html, json)
170
+ rolled) executors, ...) times) per rule)
171
+ ```
172
+
173
+ Every slow task can be traced through its stage and job to the SQL query and physical plan that
174
+ produced it, which is how findings name the join key, the UDF or the `repartition(500)` behind a
175
+ problem.
176
+
177
+ ## Limitations (v0.1)
178
+
179
+ - Reads local files. Copy logs from S3, HDFS or DBFS first.
180
+ - Logs compressed with Spark's `lz4`, `lzf` or `snappy` codecs aren't supported yet (`zstd`,
181
+ Spark's default, and `gzip` are).
182
+ - Per-operator SQL metrics (rows per plan node, files read) aren't parsed yet; the rules that
183
+ need them are [planned](https://github.com/r4otxrhs3/spark-sentinel/blob/main/docs/rule-catalog.md).
184
+ - Thresholds default to production-sized jobs; use `--profile laptop` for small runs.
185
+
186
+ ## Contributing
187
+
188
+ New rules are welcome. [CONTRIBUTING.md](https://github.com/r4otxrhs3/spark-sentinel/blob/main/CONTRIBUTING.md)
189
+ walks through adding one, from the gallery job that reproduces the problem to the tests that
190
+ keep it free of false alarms.
191
+
192
+ ## License
193
+
194
+ [Apache License 2.0](https://github.com/r4otxrhs3/spark-sentinel/blob/main/LICENSE)