dash-observe 0.1.2__py3-none-any.whl
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.
- dash_observe-0.1.2.dist-info/METADATA +118 -0
- dash_observe-0.1.2.dist-info/RECORD +9 -0
- dash_observe-0.1.2.dist-info/WHEEL +4 -0
- dash_observe-0.1.2.dist-info/licenses/LICENSE +201 -0
- dashobserve/__init__.py +21 -0
- dashobserve/monitors.py +81 -0
- dashobserve/py.typed +0 -0
- dashobserve/runner.py +150 -0
- dashobserve/ui.py +110 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dash-observe
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Data observability for Databricks — freshness, volume, and schema-change monitoring
|
|
5
|
+
Project-URL: Homepage, https://github.com/dash-libs/dash-observe
|
|
6
|
+
Project-URL: Repository, https://github.com/dash-libs/dash-observe
|
|
7
|
+
Project-URL: Issues, https://github.com/dash-libs/dash-observe/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/dash-libs/dash-observe/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Darshan Shah <darshan.innovation@icloud.com>
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: data-observability,databricks,delta,monitoring,pyspark
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Framework :: Jupyter
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
17
|
+
Classifier: Intended Audience :: Information Technology
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Requires-Dist: dash-uis>=0.1.0
|
|
29
|
+
Requires-Dist: ipywidgets>=8.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: hatch; extra == 'dev'
|
|
32
|
+
Requires-Dist: pandas; extra == 'dev'
|
|
33
|
+
Requires-Dist: pdoc; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
36
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# DashObserve — Databricks Library
|
|
40
|
+
|
|
41
|
+
[](https://github.com/dash-libs/dash-observe/actions)
|
|
42
|
+
[](https://pypi.org/project/dash-observe/)
|
|
43
|
+
[](LICENSE)
|
|
44
|
+
|
|
45
|
+
Part of the **[Dashlibs](https://github.com/dash-libs)** suite — Databricks libraries built for business users.
|
|
46
|
+
|
|
47
|
+
Monte Carlo-style data observability that runs natively in a Databricks notebook —
|
|
48
|
+
no external service, no agent to deploy. v1 covers:
|
|
49
|
+
|
|
50
|
+
- **Freshness monitoring** — alert when a table's most recent timestamp value is older than expected
|
|
51
|
+
- **Volume monitoring** — alert on row-count bounds, or on deviation from a rolling historical baseline
|
|
52
|
+
- **Schema-change detection** — alert when columns are added, removed, or change type since the last run
|
|
53
|
+
|
|
54
|
+
All monitor results are appended to a Delta history table, which also feeds the volume
|
|
55
|
+
baseline and schema-diff comparisons for future runs.
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
%pip install dash-observe
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import dashobserve
|
|
67
|
+
dashobserve.launch() # Opens interactive UI in your Databricks notebook
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## What it looks like
|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
74
|
+
## Python API
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from dashobserve import MonitorConfig, run_monitors
|
|
78
|
+
|
|
79
|
+
cfg = MonitorConfig(
|
|
80
|
+
table="catalog.schema.orders",
|
|
81
|
+
freshness_column="updated_at", max_staleness_minutes=60,
|
|
82
|
+
min_rows=1000, volume_tolerance_pct=20,
|
|
83
|
+
track_schema=True,
|
|
84
|
+
)
|
|
85
|
+
report = run_monitors(cfg, history_table="catalog.schema.observe_history")
|
|
86
|
+
report.display()
|
|
87
|
+
print(report.summary())
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Part of Dashlibs
|
|
91
|
+
|
|
92
|
+
| Library | Purpose |
|
|
93
|
+
|---|---|
|
|
94
|
+
| dash-dq | Data Quality |
|
|
95
|
+
| dash-synthetic | Synthetic Data Generation |
|
|
96
|
+
| dash-observe | Data Observability (freshness, volume, schema) |
|
|
97
|
+
| dash-ml | ML Model Monitoring |
|
|
98
|
+
| dash-ingest | Data Ingestion |
|
|
99
|
+
| dash-gov | Data Governance |
|
|
100
|
+
| dash-relate | Ontology & Lineage for AI |
|
|
101
|
+
| dash-ui | Shared UI components (PyPI: `dash-uis`) |
|
|
102
|
+
|
|
103
|
+
## Quality & Contributing
|
|
104
|
+
|
|
105
|
+
- 25 unit tests, zero Spark dependency to run them — `pytest tests/ -v`
|
|
106
|
+
(freshness/volume/schema-diff checks are pure Python and fully covered;
|
|
107
|
+
only the Spark/Delta glue in `runner.py` needs a live cluster)
|
|
108
|
+
- Lint-clean (`ruff check dashobserve/`), PEP 561 typed (`py.typed`)
|
|
109
|
+
- Every change ships through a reviewed pull request; CI (lint → test on
|
|
110
|
+
Python 3.9–3.12 → build) gates every PR and every release
|
|
111
|
+
- See [CONTRIBUTING.md](CONTRIBUTING.md) for dev setup,
|
|
112
|
+
[CHANGELOG.md](CHANGELOG.md) for release history,
|
|
113
|
+
[SECURITY.md](SECURITY.md) to report a vulnerability, and
|
|
114
|
+
[CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
Apache 2.0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
dashobserve/__init__.py,sha256=1j6JGNwgSmmb0p_glZzOOTw3-31a4LS4FCxQQjUcbNQ,607
|
|
2
|
+
dashobserve/monitors.py,sha256=3ZdK5aSFirR-eApRm1ip8r7BFZAe8dosQqdNW0BTtlQ,3781
|
|
3
|
+
dashobserve/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
dashobserve/runner.py,sha256=U1rDpjBxhuCyi1tT6DztDBqgEeA3t6gL41aiwtaatn4,5337
|
|
5
|
+
dashobserve/ui.py,sha256=xK9q_y8yWu6l-SijuoC9Dlsa1Bzz_gS8d7SW75w8Sfw,4615
|
|
6
|
+
dash_observe-0.1.2.dist-info/METADATA,sha256=wnnRm2qB3m_GRbEdpBg2MGdeMlplNrHGWPnP9TNgOrQ,4487
|
|
7
|
+
dash_observe-0.1.2.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
8
|
+
dash_observe-0.1.2.dist-info/licenses/LICENSE,sha256=c28WHQZJ-cmeyAGcLW2azQqfzdx9BMVTwrG7NhPII34,11342
|
|
9
|
+
dash_observe-0.1.2.dist-info/RECORD,,
|
|
@@ -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 2026 Darshan Shah
|
|
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.
|
dashobserve/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DashObserve — Data observability for Databricks: freshness, volume, and
|
|
3
|
+
schema-change monitoring. Launch the UI with dashobserve.launch() inside
|
|
4
|
+
a Databricks notebook.
|
|
5
|
+
"""
|
|
6
|
+
from dashobserve.monitors import MonitorResult, check_freshness, check_schema, check_volume, diff_schema
|
|
7
|
+
from dashobserve.runner import MonitorConfig, MonitorReport, run_monitors
|
|
8
|
+
from dashobserve.ui import launch
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.2"
|
|
11
|
+
__all__ = [
|
|
12
|
+
"MonitorConfig",
|
|
13
|
+
"MonitorReport",
|
|
14
|
+
"MonitorResult",
|
|
15
|
+
"run_monitors",
|
|
16
|
+
"check_freshness",
|
|
17
|
+
"check_volume",
|
|
18
|
+
"check_schema",
|
|
19
|
+
"diff_schema",
|
|
20
|
+
"launch",
|
|
21
|
+
]
|
dashobserve/monitors.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pure-logic monitor checks — freshness, volume, and schema-change detection.
|
|
3
|
+
No Spark/datetime-now dependency baked in, so every function here is testable
|
|
4
|
+
with plain Python values; the Spark-touching glue lives in runner.py.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from datetime import datetime, timezone
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class MonitorResult:
|
|
13
|
+
table_name: str
|
|
14
|
+
monitor_type: str # freshness | volume | schema
|
|
15
|
+
monitor_name: str
|
|
16
|
+
status: str # PASS | FAIL | ERROR
|
|
17
|
+
message: str
|
|
18
|
+
run_timestamp: str = ""
|
|
19
|
+
details: str = "{}" # json-encoded dict of monitor-specific details
|
|
20
|
+
|
|
21
|
+
def to_dict(self) -> dict:
|
|
22
|
+
return dict(self.__dict__)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def check_freshness(latest_timestamp, max_staleness_minutes: float, now: datetime = None) -> tuple[bool, str]:
|
|
26
|
+
"""Most recent value in the freshness column must be within max_staleness_minutes of now."""
|
|
27
|
+
if latest_timestamp is None:
|
|
28
|
+
return False, "No timestamp values found — table may be empty"
|
|
29
|
+
now = now or datetime.now(timezone.utc).replace(tzinfo=None)
|
|
30
|
+
if getattr(latest_timestamp, "tzinfo", None) is not None:
|
|
31
|
+
latest_timestamp = latest_timestamp.replace(tzinfo=None)
|
|
32
|
+
staleness_minutes = (now - latest_timestamp).total_seconds() / 60
|
|
33
|
+
ok = staleness_minutes <= max_staleness_minutes
|
|
34
|
+
msg = f"Data is {staleness_minutes:.1f} min old (threshold {max_staleness_minutes} min)"
|
|
35
|
+
return ok, msg
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def check_volume(row_count: int, min_rows: int = None, max_rows: int = None,
|
|
39
|
+
baseline_avg: float = None, tolerance_pct: float = None) -> tuple[bool, str]:
|
|
40
|
+
"""Row count must satisfy absolute bounds and/or stay within tolerance_pct of a historical baseline."""
|
|
41
|
+
if min_rows is not None and row_count < min_rows:
|
|
42
|
+
return False, f"Row count {row_count} below min_rows {min_rows}"
|
|
43
|
+
if max_rows is not None and row_count > max_rows:
|
|
44
|
+
return False, f"Row count {row_count} above max_rows {max_rows}"
|
|
45
|
+
if baseline_avg is not None and tolerance_pct is not None and baseline_avg > 0:
|
|
46
|
+
deviation_pct = abs(row_count - baseline_avg) / baseline_avg * 100
|
|
47
|
+
if deviation_pct > tolerance_pct:
|
|
48
|
+
return False, (
|
|
49
|
+
f"Row count {row_count} deviates {deviation_pct:.1f}% from baseline "
|
|
50
|
+
f"{baseline_avg:.0f} (tolerance {tolerance_pct}%)"
|
|
51
|
+
)
|
|
52
|
+
return True, f"Row count {row_count} within expected bounds"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def diff_schema(old_schema: dict, new_schema: dict) -> dict:
|
|
56
|
+
"""Compare two {column_name: dtype_string} schemas. Pure set/dict logic, no I/O."""
|
|
57
|
+
old_cols, new_cols = set(old_schema), set(new_schema)
|
|
58
|
+
added = sorted(new_cols - old_cols)
|
|
59
|
+
removed = sorted(old_cols - new_cols)
|
|
60
|
+
type_changed = sorted(c for c in (old_cols & new_cols) if old_schema[c] != new_schema[c])
|
|
61
|
+
return {"added": added, "removed": removed, "type_changed": type_changed}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def check_schema(old_schema: dict, new_schema: dict) -> tuple[bool, str, dict]:
|
|
65
|
+
"""old_schema=None means no prior snapshot exists yet — treated as a baseline, not a failure."""
|
|
66
|
+
if old_schema is None:
|
|
67
|
+
return True, "Initial schema snapshot recorded", {"added": [], "removed": [], "type_changed": []}
|
|
68
|
+
|
|
69
|
+
diff = diff_schema(old_schema, new_schema)
|
|
70
|
+
changed = diff["added"] or diff["removed"] or diff["type_changed"]
|
|
71
|
+
if not changed:
|
|
72
|
+
return True, "No schema changes detected", diff
|
|
73
|
+
|
|
74
|
+
parts = []
|
|
75
|
+
if diff["added"]:
|
|
76
|
+
parts.append(f"added: {', '.join(diff['added'])}")
|
|
77
|
+
if diff["removed"]:
|
|
78
|
+
parts.append(f"removed: {', '.join(diff['removed'])}")
|
|
79
|
+
if diff["type_changed"]:
|
|
80
|
+
parts.append(f"type changed: {', '.join(diff['type_changed'])}")
|
|
81
|
+
return False, "Schema changed — " + "; ".join(parts), diff
|
dashobserve/py.typed
ADDED
|
File without changes
|
dashobserve/runner.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MonitorConfig + run_monitors() — the Spark-touching glue around the pure
|
|
3
|
+
checks in monitors.py. Reads/writes a Delta "history" table so volume
|
|
4
|
+
baselines and schema snapshots can be compared run over run.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
import json
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
|
|
11
|
+
from dashobserve.monitors import MonitorResult, check_freshness, check_schema, check_volume
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class MonitorConfig:
|
|
16
|
+
table: str
|
|
17
|
+
freshness_column: str = None
|
|
18
|
+
max_staleness_minutes: float = None
|
|
19
|
+
min_rows: int = None
|
|
20
|
+
max_rows: int = None
|
|
21
|
+
volume_tolerance_pct: float = None
|
|
22
|
+
track_schema: bool = False
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class MonitorReport:
|
|
26
|
+
def __init__(self, results: list):
|
|
27
|
+
self.results = results
|
|
28
|
+
|
|
29
|
+
def to_dict(self) -> list:
|
|
30
|
+
return [r.to_dict() for r in self.results]
|
|
31
|
+
|
|
32
|
+
def to_pandas(self):
|
|
33
|
+
import pandas as pd
|
|
34
|
+
return pd.DataFrame(self.to_dict())
|
|
35
|
+
|
|
36
|
+
def summary(self) -> dict:
|
|
37
|
+
total = len(self.results)
|
|
38
|
+
passed = sum(1 for r in self.results if r.status == "PASS")
|
|
39
|
+
return {
|
|
40
|
+
"total_monitors": total,
|
|
41
|
+
"passed": passed,
|
|
42
|
+
"failed": total - passed,
|
|
43
|
+
"pass_rate_pct": round(passed / total * 100, 1) if total else 0,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
def display(self):
|
|
47
|
+
for r in self.results:
|
|
48
|
+
icon = "✅" if r.status == "PASS" else "❌"
|
|
49
|
+
print(f"{icon} [{r.monitor_type}] {r.table_name} — {r.message}")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def run_monitors(config: MonitorConfig, history_table: str = None, spark=None) -> MonitorReport:
|
|
53
|
+
"""Run every monitor configured on config.table and return a MonitorReport."""
|
|
54
|
+
if spark is None:
|
|
55
|
+
from pyspark.sql import SparkSession
|
|
56
|
+
spark = SparkSession.getActiveSession()
|
|
57
|
+
from pyspark.sql import functions as F
|
|
58
|
+
|
|
59
|
+
df = spark.table(config.table)
|
|
60
|
+
run_ts = datetime.now().isoformat(timespec="seconds")
|
|
61
|
+
results = []
|
|
62
|
+
|
|
63
|
+
if config.freshness_column and config.max_staleness_minutes is not None:
|
|
64
|
+
latest = df.agg(F.max(config.freshness_column)).collect()[0][0]
|
|
65
|
+
ok, msg = check_freshness(latest, config.max_staleness_minutes)
|
|
66
|
+
results.append(MonitorResult(
|
|
67
|
+
config.table, "freshness", "data_freshness",
|
|
68
|
+
"PASS" if ok else "FAIL", msg, run_ts,
|
|
69
|
+
))
|
|
70
|
+
|
|
71
|
+
if config.min_rows is not None or config.max_rows is not None or config.volume_tolerance_pct is not None:
|
|
72
|
+
row_count = df.count()
|
|
73
|
+
baseline_avg = None
|
|
74
|
+
if config.volume_tolerance_pct is not None and history_table:
|
|
75
|
+
baseline_avg = _read_volume_baseline(spark, history_table, config.table)
|
|
76
|
+
ok, msg = check_volume(row_count, config.min_rows, config.max_rows, baseline_avg, config.volume_tolerance_pct)
|
|
77
|
+
results.append(MonitorResult(
|
|
78
|
+
config.table, "volume", "row_count",
|
|
79
|
+
"PASS" if ok else "FAIL", msg, run_ts,
|
|
80
|
+
details=json.dumps({"row_count": row_count}),
|
|
81
|
+
))
|
|
82
|
+
|
|
83
|
+
if config.track_schema:
|
|
84
|
+
new_schema = {f.name: str(f.dataType) for f in df.schema.fields}
|
|
85
|
+
old_schema = _read_last_schema(spark, history_table, config.table) if history_table else None
|
|
86
|
+
ok, msg, diff = check_schema(old_schema, new_schema)
|
|
87
|
+
results.append(MonitorResult(
|
|
88
|
+
config.table, "schema", "schema_change",
|
|
89
|
+
"PASS" if ok else "FAIL", msg, run_ts,
|
|
90
|
+
details=json.dumps({"schema": new_schema, "diff": diff}),
|
|
91
|
+
))
|
|
92
|
+
|
|
93
|
+
if history_table and results:
|
|
94
|
+
_save_results(spark, history_table, results)
|
|
95
|
+
|
|
96
|
+
return MonitorReport(results)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _read_volume_baseline(spark, history_table: str, table: str, window: int = 7):
|
|
100
|
+
"""Average row_count from the last `window` volume monitor runs for this table."""
|
|
101
|
+
from pyspark.sql import functions as F
|
|
102
|
+
try:
|
|
103
|
+
rows = (
|
|
104
|
+
spark.table(history_table)
|
|
105
|
+
.filter((F.col("table_name") == table) & (F.col("monitor_type") == "volume"))
|
|
106
|
+
.orderBy(F.col("run_timestamp").desc())
|
|
107
|
+
.limit(window)
|
|
108
|
+
.select("details")
|
|
109
|
+
.collect()
|
|
110
|
+
)
|
|
111
|
+
except Exception:
|
|
112
|
+
return None
|
|
113
|
+
counts = []
|
|
114
|
+
for r in rows:
|
|
115
|
+
try:
|
|
116
|
+
counts.append(json.loads(r["details"])["row_count"])
|
|
117
|
+
except Exception:
|
|
118
|
+
continue
|
|
119
|
+
return sum(counts) / len(counts) if counts else None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _read_last_schema(spark, history_table: str, table: str):
|
|
123
|
+
"""The most recently saved schema snapshot for this table, or None if there isn't one."""
|
|
124
|
+
from pyspark.sql import functions as F
|
|
125
|
+
try:
|
|
126
|
+
row = (
|
|
127
|
+
spark.table(history_table)
|
|
128
|
+
.filter((F.col("table_name") == table) & (F.col("monitor_type") == "schema"))
|
|
129
|
+
.orderBy(F.col("run_timestamp").desc())
|
|
130
|
+
.limit(1)
|
|
131
|
+
.select("details")
|
|
132
|
+
.collect()
|
|
133
|
+
)
|
|
134
|
+
except Exception:
|
|
135
|
+
return None
|
|
136
|
+
if not row:
|
|
137
|
+
return None
|
|
138
|
+
try:
|
|
139
|
+
return json.loads(row[0]["details"])["schema"]
|
|
140
|
+
except Exception:
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _save_results(spark, history_table: str, results: list):
|
|
145
|
+
rows = [r.to_dict() for r in results]
|
|
146
|
+
(spark.createDataFrame(rows)
|
|
147
|
+
.write.format("delta")
|
|
148
|
+
.mode("append")
|
|
149
|
+
.option("mergeSchema", "true")
|
|
150
|
+
.saveAsTable(history_table))
|
dashobserve/ui.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""DashObserve interactive UI for Databricks notebooks."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def launch():
|
|
6
|
+
try:
|
|
7
|
+
import ipywidgets as w
|
|
8
|
+
from IPython.display import display
|
|
9
|
+
except ImportError:
|
|
10
|
+
raise RuntimeError("ipywidgets required. Run: %pip install ipywidgets")
|
|
11
|
+
|
|
12
|
+
import dashui
|
|
13
|
+
|
|
14
|
+
monitors: list[dict] = []
|
|
15
|
+
|
|
16
|
+
# ── Add monitor ───────────────────────────────────────────────────────
|
|
17
|
+
m_table = w.Text(description="UC Table:", placeholder="catalog.schema.table")
|
|
18
|
+
|
|
19
|
+
m_freshness_col = w.Text(description="Freshness col:", placeholder="updated_at (optional)")
|
|
20
|
+
m_max_staleness = w.IntText(description="Max staleness (min):", value=1440)
|
|
21
|
+
|
|
22
|
+
m_min_rows = w.Text(description="Min rows:", placeholder="optional")
|
|
23
|
+
m_max_rows = w.Text(description="Max rows:", placeholder="optional")
|
|
24
|
+
m_tolerance = w.Text(description="Baseline tolerance %:", placeholder="optional, e.g. 20")
|
|
25
|
+
|
|
26
|
+
m_track_schema = w.Checkbox(value=True, description="Track schema changes")
|
|
27
|
+
|
|
28
|
+
add_btn = dashui.action_button("Add Monitor", style="info", emoji="+")
|
|
29
|
+
monitors_output, render_monitors = dashui.running_list(
|
|
30
|
+
lambda i, m: (
|
|
31
|
+
f" {i}. {m['table']} — "
|
|
32
|
+
f"freshness:{'on' if m['freshness_column'] else 'off'}, "
|
|
33
|
+
f"volume:{'on' if (m['min_rows'] or m['max_rows'] or m['volume_tolerance_pct']) else 'off'}, "
|
|
34
|
+
f"schema:{'on' if m['track_schema'] else 'off'}"
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def _parse_int(text):
|
|
39
|
+
text = text.strip()
|
|
40
|
+
return int(text) if text else None
|
|
41
|
+
|
|
42
|
+
def _parse_float(text):
|
|
43
|
+
text = text.strip()
|
|
44
|
+
return float(text) if text else None
|
|
45
|
+
|
|
46
|
+
def on_add(b):
|
|
47
|
+
table = m_table.value.strip()
|
|
48
|
+
if not table:
|
|
49
|
+
return
|
|
50
|
+
monitors.append({
|
|
51
|
+
"table": table,
|
|
52
|
+
"freshness_column": m_freshness_col.value.strip() or None,
|
|
53
|
+
"max_staleness_minutes": m_max_staleness.value,
|
|
54
|
+
"min_rows": _parse_int(m_min_rows.value),
|
|
55
|
+
"max_rows": _parse_int(m_max_rows.value),
|
|
56
|
+
"volume_tolerance_pct": _parse_float(m_tolerance.value),
|
|
57
|
+
"track_schema": m_track_schema.value,
|
|
58
|
+
})
|
|
59
|
+
render_monitors(monitors)
|
|
60
|
+
m_table.value = m_freshness_col.value = m_min_rows.value = m_max_rows.value = m_tolerance.value = ""
|
|
61
|
+
|
|
62
|
+
add_btn.on_click(on_add)
|
|
63
|
+
|
|
64
|
+
# ── Run ──────────────────────────────────────────────────────────────
|
|
65
|
+
history_table = w.Text(description="History table:", placeholder="catalog.schema.observe_history (optional)")
|
|
66
|
+
run_btn = dashui.action_button("Run All Monitors", style="success", emoji="▶")
|
|
67
|
+
output = dashui.output_panel()
|
|
68
|
+
|
|
69
|
+
def on_run(b):
|
|
70
|
+
with output:
|
|
71
|
+
output.clear_output()
|
|
72
|
+
if not monitors:
|
|
73
|
+
print("⚠️ No monitors configured — add at least one above")
|
|
74
|
+
return
|
|
75
|
+
try:
|
|
76
|
+
from dashobserve.runner import MonitorConfig, run_monitors
|
|
77
|
+
hist = history_table.value.strip() or None
|
|
78
|
+
for m in monitors:
|
|
79
|
+
cfg = MonitorConfig(
|
|
80
|
+
table=m["table"],
|
|
81
|
+
freshness_column=m["freshness_column"],
|
|
82
|
+
max_staleness_minutes=m["max_staleness_minutes"] if m["freshness_column"] else None,
|
|
83
|
+
min_rows=m["min_rows"],
|
|
84
|
+
max_rows=m["max_rows"],
|
|
85
|
+
volume_tolerance_pct=m["volume_tolerance_pct"],
|
|
86
|
+
track_schema=m["track_schema"],
|
|
87
|
+
)
|
|
88
|
+
report = run_monitors(cfg, history_table=hist)
|
|
89
|
+
report.display()
|
|
90
|
+
s = report.summary()
|
|
91
|
+
print(f" → {s['passed']}/{s['total_monitors']} passed\n")
|
|
92
|
+
except Exception as e:
|
|
93
|
+
print(f"❌ {e}")
|
|
94
|
+
|
|
95
|
+
run_btn.on_click(on_run)
|
|
96
|
+
|
|
97
|
+
ui = dashui.card([
|
|
98
|
+
dashui.header("DashObserve — Data Observability", library="dashobserve", emoji="👁️"),
|
|
99
|
+
dashui.section("Step 1: Configure a monitor"),
|
|
100
|
+
m_table,
|
|
101
|
+
w.HBox([m_freshness_col, m_max_staleness]),
|
|
102
|
+
w.HBox([m_min_rows, m_max_rows, m_tolerance]),
|
|
103
|
+
m_track_schema,
|
|
104
|
+
add_btn, monitors_output,
|
|
105
|
+
dashui.section("Step 2: Run"),
|
|
106
|
+
history_table,
|
|
107
|
+
run_btn,
|
|
108
|
+
output,
|
|
109
|
+
])
|
|
110
|
+
display(ui)
|