detectkit 0.67.0__tar.gz → 0.67.2__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 (172) hide show
  1. {detectkit-0.67.0/detectkit.egg-info → detectkit-0.67.2}/PKG-INFO +1 -1
  2. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/__init__.py +1 -1
  3. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/_recovery.py +87 -25
  4. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/rules/alerting.md +5 -0
  5. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/rules/cli.md +7 -3
  6. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/rules/metrics.md +28 -1
  7. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/autotune.py +15 -3
  8. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/run.py +78 -1
  9. {detectkit-0.67.0 → detectkit-0.67.2/detectkit.egg-info}/PKG-INFO +1 -1
  10. {detectkit-0.67.0 → detectkit-0.67.2}/LICENSE +0 -0
  11. {detectkit-0.67.0 → detectkit-0.67.2}/MANIFEST.in +0 -0
  12. {detectkit-0.67.0 → detectkit-0.67.2}/README.md +0 -0
  13. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/__init__.py +0 -0
  14. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/__init__.py +0 -0
  15. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/base.py +0 -0
  16. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/branding.py +0 -0
  17. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/discord.py +0 -0
  18. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/email.py +0 -0
  19. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/factory.py +0 -0
  20. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/googlechat.py +0 -0
  21. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/mattermost.py +0 -0
  22. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/ntfy.py +0 -0
  23. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/slack.py +0 -0
  24. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/teams.py +0 -0
  25. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/telegram.py +0 -0
  26. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/channels/webhook.py +0 -0
  27. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/__init__.py +0 -0
  28. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/_base.py +0 -0
  29. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/_cooldown.py +0 -0
  30. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/_decision.py +0 -0
  31. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/_dispatch.py +0 -0
  32. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/_replay.py +0 -0
  33. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/_types.py +0 -0
  34. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/alerting/orchestrator/orchestrator.py +0 -0
  35. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/__init__.py +0 -0
  36. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/_base.py +0 -0
  37. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/_types.py +0 -0
  38. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/autotuner.py +0 -0
  39. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/axis_spec.py +0 -0
  40. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/config_emitter.py +0 -0
  41. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/crossval.py +0 -0
  42. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/detector_select.py +0 -0
  43. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/distribution.py +0 -0
  44. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/grid_search.py +0 -0
  45. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/labels.py +0 -0
  46. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/result.py +0 -0
  47. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/runner.py +0 -0
  48. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/scoring.py +0 -0
  49. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/seasonality_search.py +0 -0
  50. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/settings.py +0 -0
  51. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/autotune/window_select.py +0 -0
  52. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/__init__.py +0 -0
  53. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/_output.py +0 -0
  54. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/CLAUDE.section.md +0 -0
  55. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/rules/autotune.md +0 -0
  56. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/rules/detectors.md +0 -0
  57. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/rules/overview.md +0 -0
  58. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/rules/project.md +0 -0
  59. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/skills/dtk-autotune/SKILL.md +0 -0
  60. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/skills/dtk-feedback/SKILL.md +0 -0
  61. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/skills/dtk-new-metric/SKILL.md +0 -0
  62. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/skills/dtk-setup-project/SKILL.md +0 -0
  63. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/assets/claude/skills/dtk-tune/SKILL.md +0 -0
  64. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/__init__.py +0 -0
  65. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/clean.py +0 -0
  66. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/init.py +0 -0
  67. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/init_claude.py +0 -0
  68. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/mcp.py +0 -0
  69. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/osi.py +0 -0
  70. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/test_alert.py +0 -0
  71. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/tune.py +0 -0
  72. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/ui.py +0 -0
  73. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/commands/unlock.py +0 -0
  74. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/cli/main.py +0 -0
  75. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/config/__init__.py +0 -0
  76. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/config/metric_config.py +0 -0
  77. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/config/metric_io.py +0 -0
  78. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/config/profile.py +0 -0
  79. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/config/project_config.py +0 -0
  80. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/config/validator.py +0 -0
  81. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/core/__init__.py +0 -0
  82. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/core/interval.py +0 -0
  83. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/core/models.py +0 -0
  84. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/__init__.py +0 -0
  85. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/_sql_manager.py +0 -0
  86. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/bigquery_manager.py +0 -0
  87. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/clickhouse_manager.py +0 -0
  88. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/duckdb_manager.py +0 -0
  89. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/__init__.py +0 -0
  90. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_alert_states.py +0 -0
  91. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_autotune_runs.py +0 -0
  92. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_base.py +0 -0
  93. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_datapoints.py +0 -0
  94. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_detections.py +0 -0
  95. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_maintenance.py +0 -0
  96. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_metrics.py +0 -0
  97. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_schema.py +0 -0
  98. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/_tasks.py +0 -0
  99. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/internal_tables/manager.py +0 -0
  100. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/manager.py +0 -0
  101. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/mysql_manager.py +0 -0
  102. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/postgres_manager.py +0 -0
  103. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/snowflake_manager.py +0 -0
  104. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/source_manager.py +0 -0
  105. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/database/tables.py +0 -0
  106. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/__init__.py +0 -0
  107. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/base.py +0 -0
  108. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/factory.py +0 -0
  109. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/seasonality.py +0 -0
  110. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/statistical/__init__.py +0 -0
  111. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/statistical/_windowed.py +0 -0
  112. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/statistical/autoreg.py +0 -0
  113. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/statistical/iqr.py +0 -0
  114. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/statistical/mad.py +0 -0
  115. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/statistical/manual_bounds.py +0 -0
  116. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/detectors/statistical/zscore.py +0 -0
  117. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/loaders/__init__.py +0 -0
  118. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/loaders/errors.py +0 -0
  119. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/loaders/metric_loader.py +0 -0
  120. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/loaders/query_template.py +0 -0
  121. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/mcp/__init__.py +0 -0
  122. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/mcp/context.py +0 -0
  123. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/mcp/errors.py +0 -0
  124. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/mcp/serialize.py +0 -0
  125. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/mcp/server.py +0 -0
  126. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/mcp/tools.py +0 -0
  127. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/__init__.py +0 -0
  128. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/error_dispatch.py +0 -0
  129. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/task_manager/__init__.py +0 -0
  130. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/task_manager/_alert_step.py +0 -0
  131. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/task_manager/_base.py +0 -0
  132. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/task_manager/_detect_step.py +0 -0
  133. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/task_manager/_load_step.py +0 -0
  134. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/task_manager/_types.py +0 -0
  135. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/orchestration/task_manager/manager.py +0 -0
  136. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/reporting/__init__.py +0 -0
  137. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/reporting/assets/report.js +0 -0
  138. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/reporting/builder.py +0 -0
  139. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/reporting/html_report.py +0 -0
  140. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/semantic/__init__.py +0 -0
  141. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/semantic/errors.py +0 -0
  142. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/semantic/exporter.py +0 -0
  143. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/semantic/importer.py +0 -0
  144. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/semantic/osi_model.py +0 -0
  145. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/semantic/query_gen.py +0 -0
  146. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/tuning/__init__.py +0 -0
  147. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/tuning/assets/tune.js +0 -0
  148. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/tuning/config_writer.py +0 -0
  149. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/tuning/html.py +0 -0
  150. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/tuning/payload.py +0 -0
  151. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/tuning/server.py +0 -0
  152. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/ui/__init__.py +0 -0
  153. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/ui/assets/ui.js +0 -0
  154. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/ui/html.py +0 -0
  155. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/ui/jobs.py +0 -0
  156. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/ui/metric_files.py +0 -0
  157. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/ui/overview.py +0 -0
  158. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/ui/server.py +0 -0
  159. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/utils/__init__.py +0 -0
  160. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/utils/datetime_utils.py +0 -0
  161. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/utils/env_interpolation.py +0 -0
  162. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/utils/json_utils.py +0 -0
  163. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit/utils/stats.py +0 -0
  164. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit.egg-info/SOURCES.txt +0 -0
  165. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit.egg-info/dependency_links.txt +0 -0
  166. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit.egg-info/entry_points.txt +0 -0
  167. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit.egg-info/requires.txt +0 -0
  168. {detectkit-0.67.0 → detectkit-0.67.2}/detectkit.egg-info/top_level.txt +0 -0
  169. {detectkit-0.67.0 → detectkit-0.67.2}/pyproject.toml +0 -0
  170. {detectkit-0.67.0 → detectkit-0.67.2}/requirements.txt +0 -0
  171. {detectkit-0.67.0 → detectkit-0.67.2}/setup.cfg +0 -0
  172. {detectkit-0.67.0 → detectkit-0.67.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: detectkit
3
- Version: 0.67.0
3
+ Version: 0.67.2
4
4
  Summary: Metric monitoring with automatic anomaly detection
5
5
  Author: detectkit team
6
6
  License: MIT
@@ -4,7 +4,7 @@ detectk - Anomaly Detection for Time-Series Metrics
4
4
  A Python library for data analysts and engineers to monitor metrics with automatic anomaly detection.
5
5
  """
6
6
 
7
- __version__ = "0.67.0"
7
+ __version__ = "0.67.2"
8
8
 
9
9
  from detectkit.core.interval import Interval
10
10
  from detectkit.core.models import ColumnDefinition, TableModel
@@ -177,28 +177,48 @@ class _RecoveryMixin(_OrchestratorBase):
177
177
  # ``detections`` is oldest→newest, so the latest point lives at [-1].
178
178
  latest = detections[-1]
179
179
 
180
- # Prefer the latest CI so the message reflects the *current* interval.
181
- # Fall back to the last anomalous point only if the latest row has no
182
- # CI (e.g. missing-data / insufficient-data placeholders).
183
- recovery_ci_lower = latest.confidence_lower
184
- recovery_ci_upper = latest.confidence_upper
185
- recovery_detector_name = latest.detector_name
186
- recovery_detector_params = latest.detector_params
187
-
188
- if recovery_ci_lower is None or recovery_ci_upper is None:
189
- last_anomalous = next((d for d in reversed(detections) if d.is_anomaly), None)
190
- if last_anomalous:
191
- recovery_detector_name = last_anomalous.detector_name
192
- recovery_detector_params = last_anomalous.detector_params
193
- recovery_ci_lower = last_anomalous.confidence_lower
194
- recovery_ci_upper = last_anomalous.confidence_upper
195
-
196
180
  # Reconstruct the just-ended incident so the recovery message can say how
197
- # long it lasted (symmetric with the anomaly alert's onset/duration).
198
- incident_count, onset_ts, capped = self._resolve_incident(
181
+ # long it lasted (symmetric with the anomaly alert's onset/duration) and
182
+ # WHICH detector fired it.
183
+ incident_count, onset_ts, capped, firing = self._resolve_incident(
199
184
  latest.timestamp, records=incident_records
200
185
  )
201
186
 
187
+ # Render the band of the detector that actually fired. Using ``latest``
188
+ # verbatim picked whichever detector_id sorted last at the latest
189
+ # timestamp (``get_recent_detections`` orders by detector_id), so a
190
+ # multi-detector metric could clear with a band belonging to a detector
191
+ # that had nothing to do with the alert — e.g. a manual_bounds floor's
192
+ # ">= 30.00" where the MAD band that fired was "[249.34, 418.61]".
193
+ source = self._recovery_source(detections, firing)
194
+
195
+ recovery_ci_lower = source.confidence_lower
196
+ recovery_ci_upper = source.confidence_upper
197
+ recovery_detector_name = source.detector_name
198
+ recovery_detector_params = source.detector_params
199
+
200
+ if recovery_ci_lower is None and recovery_ci_upper is None:
201
+ # The chosen row carries no band at all (missing-data /
202
+ # insufficient-data placeholder): prefer the same detector's most
203
+ # recent banded row, then the last anomalous row of any detector.
204
+ # A ONE-SIDED band (manual_bounds with only ``lower_bound``) is not
205
+ # "no band" — ``expected_range`` renders it as ">= lo" — so it must
206
+ # not trip this fallback and inherit another detector's numbers.
207
+ fallback = next(
208
+ (
209
+ d
210
+ for d in reversed(detections)
211
+ if d.detector_id == source.detector_id
212
+ and (d.confidence_lower is not None or d.confidence_upper is not None)
213
+ ),
214
+ None,
215
+ ) or next((d for d in reversed(detections) if d.is_anomaly), None)
216
+ if fallback is not None:
217
+ recovery_detector_name = fallback.detector_name
218
+ recovery_detector_params = fallback.detector_params
219
+ recovery_ci_lower = fallback.confidence_lower
220
+ recovery_ci_upper = fallback.confidence_upper
221
+
202
222
  return AlertData(
203
223
  metric_name=self.metric_name,
204
224
  timestamp=latest.timestamp,
@@ -237,16 +257,52 @@ class _RecoveryMixin(_OrchestratorBase):
237
257
  loading_delay_seconds=self.loading_delay_seconds or None,
238
258
  )
239
259
 
260
+ @staticmethod
261
+ def _recovery_source(
262
+ detections: list[DetectionRecord],
263
+ firing: DetectionRecord | None,
264
+ ) -> DetectionRecord:
265
+ """Pick the record whose band/name/params the recovery message renders.
266
+
267
+ Resolves a target DETECTOR first, then renders that detector's freshest
268
+ row — so the message reads "the detector that fired is back inside its
269
+ band" with the band of the *current* interval:
270
+
271
+ 1. target = the incident's firing detector; with no incident to walk
272
+ (direct-API caller with no DB) = the newest anomalous record in the
273
+ window, which is the best available proxy for "what fired";
274
+ 2. render that detector's row at the latest (now-clean) point, else its
275
+ most recent row in the window, else the target row itself (a
276
+ retuned/removed detector id that no longer scores);
277
+ 3. ``detections[-1]`` verbatim when there is nothing to anchor on —
278
+ which is also what a single-detector metric resolves to, so those
279
+ render exactly as before.
280
+ """
281
+ latest = detections[-1]
282
+ target = firing or next((d for d in reversed(detections) if d.is_anomaly), None)
283
+ if target is None:
284
+ return latest
285
+ same = [d for d in detections if d.detector_id == target.detector_id]
286
+ if not same:
287
+ return target
288
+ at_latest = next((d for d in same if d.timestamp == latest.timestamp), None)
289
+ return at_latest if at_latest is not None else same[-1]
290
+
240
291
  def _resolve_incident(
241
292
  self, cleared_ts: Any, records: list[DetectionRecord] | None = None
242
- ) -> tuple[int, Any, bool]:
293
+ ) -> tuple[int, Any, bool, DetectionRecord | None]:
243
294
  """Find the anomalous run that just ended before the recovery point.
244
295
 
245
296
  Walks back from *cleared_ts* (the latest, now-clean point): skips the
246
297
  clean tail, then counts the contiguous direction-aware quorum run using
247
298
  the same logic that fired the alert. Returns ``(length, onset_timestamp,
248
- capped)`` — ``(0, None, False)`` when no run can be reconstructed, so the
249
- recovery message just omits the incident duration.
299
+ capped, firing_record)`` — ``(0, None, False, None)`` when no run can be
300
+ reconstructed, so the recovery message just omits the incident duration.
301
+
302
+ ``firing_record`` is the primary (highest-severity, deterministically
303
+ tie-broken) record of the quorum at the incident's LAST point — the
304
+ detector that was driving the alert when it cleared — so the recovery
305
+ message can name it instead of an unrelated detector.
250
306
  """
251
307
  step = np.timedelta64(self.interval.seconds, "s")
252
308
  # ``records`` lets a pure caller (alert replay) supply the in-memory
@@ -254,7 +310,7 @@ class _RecoveryMixin(_OrchestratorBase):
254
310
  # incident is resolved from ``_dtk_detections`` as before.
255
311
  if records is None:
256
312
  if not self.internal:
257
- return 0, None, False
313
+ return 0, None, False, None
258
314
  if isinstance(cleared_ts, np.datetime64):
259
315
  last_point = cleared_ts.astype("datetime64[ms]").astype(datetime)
260
316
  else:
@@ -266,7 +322,7 @@ class _RecoveryMixin(_OrchestratorBase):
266
322
  )
267
323
  records = hydrate_detection_records(rows)
268
324
  if not records:
269
- return 0, None, False
325
+ return 0, None, False, None
270
326
 
271
327
  by_time = self._group_by_timestamp(records)
272
328
  timestamps_sorted = sorted(by_time.keys(), reverse=True)
@@ -276,6 +332,7 @@ class _RecoveryMixin(_OrchestratorBase):
276
332
  count = 0
277
333
  onset: Any = None
278
334
  prev: np.datetime64 | None = None
335
+ firing: DetectionRecord | None = None
279
336
  for ts in timestamps_sorted:
280
337
  anomalies = [d for d in by_time[ts] if d.is_anomaly]
281
338
  # ``_quorum_at`` lives in _DecisionMixin; both mixins compose into
@@ -289,6 +346,11 @@ class _RecoveryMixin(_OrchestratorBase):
289
346
  started = True
290
347
  if self.conditions.direction == "same":
291
348
  locked = direction
349
+ # The incident's last point — its primary record is the detector
350
+ # that was driving the alert when it cleared. ``_primary_record``
351
+ # lives in _DecisionMixin; both mixins compose into
352
+ # AlertOrchestrator so the call resolves at runtime.
353
+ firing = self._primary_record(quorum)
292
354
  count = 1
293
355
  onset = ts
294
356
  prev = ts
@@ -302,6 +364,6 @@ class _RecoveryMixin(_OrchestratorBase):
302
364
  prev = ts
303
365
 
304
366
  if count == 0:
305
- return 0, None, False
367
+ return 0, None, False, None
306
368
  capped = count >= STREAK_LOOKBACK_POINTS
307
- return count, onset, capped
369
+ return count, onset, capped, firing
@@ -157,6 +157,11 @@ does not block recovery (the original condition no longer holds). Independent of
157
157
  `alert_cooldown` (recovery always sends once per incident). Default body is
158
158
  alert-centric (`🟢 Alert cleared: <metric>`).
159
159
 
160
+ On a **multi-detector** metric the recovery message reports the detector that
161
+ actually fired the incident — its name, params and `Expected` range at the
162
+ recovered point — so a metric pairing a MAD band with a `manual_bounds` floor
163
+ clears with the same detector's numbers it fired with.
164
+
160
165
  ## No-data alerts
161
166
 
162
167
  ```yaml
@@ -49,9 +49,13 @@ schedulers and CI to gate on:
49
49
  | `1` | Failure — any metric failed, the run aborted early, a startup/config/DB error occurred, or the selector matched no metrics. |
50
50
  | `2` | Usage error — bad CLI arguments. |
51
51
 
52
- On `dtk autotune`, a metric that's disabled in its config counts as **skipped**,
53
- not failed, and doesn't turn the exit code non-zero by itself. Other commands
54
- keep Click's default behavior (0 on success, non-zero on any exception).
52
+ A **skipped** metric never turns the exit code non-zero by itself — a skip is a
53
+ config choice, not a failure. Both switches skip: `enabled: false` on the metric
54
+ (skipped by `dtk run` *and* `dtk autotune` — no load, detect, alert or tuning) and
55
+ `autotune.enabled: false` (skipped by `dtk autotune` only). A run whose every
56
+ selected metric is disabled still exits `0`; only a selector matching **no metric
57
+ at all** is the exit-1 case. Other commands keep Click's default behavior (0 on
58
+ success, non-zero on any exception).
55
59
 
56
60
  ## `dtk run`
57
61
 
@@ -12,7 +12,7 @@ name: api_response_time # required, unique across the project
12
12
  description: API p95 latency # optional, shown in alerts
13
13
  profile: prod # optional, overrides project default_profile
14
14
  source_profile: warehouse # optional — hybrid mode: source-DB profile for THIS metric's SQL (see below)
15
- enabled: true # optional, false → skipped by `dtk run`
15
+ enabled: true # optional, false → whole metric skipped (see "Turning a metric off")
16
16
  tags: [critical, api] # optional, used by `--select tag:<t>`
17
17
  ai_context: # optional — OSI-compatible grounding (descriptive only)
18
18
  instructions: "p95 API latency, ms; user-facing"
@@ -166,6 +166,33 @@ columns and bakes the best grouping into the tuned config (see `autotune.md`).
166
166
  real-outage detection time, and it reduces but doesn't eliminate the race
167
167
  (repair a bucket that slipped through with `dtk run --from <date>`).
168
168
 
169
+ ## Turning a metric off
170
+
171
+ Three switches, from broadest to narrowest — pick by what you want to stop:
172
+
173
+ | Want to stop | Set | Effect |
174
+ |---|---|---|
175
+ | Everything | `enabled: false` (metric top level) | `dtk run` skips the metric: no load, no detect, no alert, no pipeline lock. `dtk autotune` skips it too. |
176
+ | Only notifications | `alerting.enabled: false` | Load + detect keep running (history stays continuous); nothing is sent. |
177
+ | Notifications, temporarily | `alerting.suppress_until: "2026-09-01"` | Same, until the deadline passes. |
178
+ | Only automatic tuning | `autotune.enabled: false` | Metric stays fully live; `dtk autotune` refuses it. |
179
+
180
+ `enabled: false` is visible, not silent — `dtk run` prints
181
+ `• <metric>: disabled in config (enabled: false) — skipped`, `dtk run --json`
182
+ reports the metric with `"status": "skipped"` and counts it in `totals.skipped`,
183
+ and the exit code stays **0** (a config choice is not a failure; a run whose every
184
+ selected metric is disabled still exits 0).
185
+
186
+ A disabled metric is **not** deleted: its stored history is untouched and
187
+ `dtk clean --orphaned-metrics` leaves it alone (it is still defined in YAML).
188
+ `dtk tune`, `dtk ui` (dimmed, sorted last) and `dtk mcp` still see it — that's how
189
+ you inspect a metric you just turned off before deciding to fix or delete it. Its
190
+ `_dtk_metrics` registry row is still refreshed, so that table's `enabled` column
191
+ tracks the YAML.
192
+
193
+ Prefer `enabled: false` over deleting the file when you may want the metric back:
194
+ deleting orphans every `_dtk_*` row under that name.
195
+
169
196
  ## Editing a metric that already has data
170
197
 
171
198
  - **Changing the `query`** changes what's loaded but not the stored history;
@@ -319,11 +319,23 @@ def _tune_one(
319
319
  """Tune one metric end to end.
320
320
 
321
321
  Returns:
322
- ``"ok"`` on success, ``"skipped"`` when autotune is disabled for this
323
- metric (an explicit config choice, not a failure), or ``"failed"``
324
- (no datapoints, a validation/engine error, or an unexpected exception).
322
+ ``"ok"`` on success, ``"skipped"`` when the metric itself is disabled
323
+ (``enabled: false``) or autotuning is refused for it
324
+ (``autotune.enabled: false``) — both explicit config choices, not
325
+ failures — or ``"failed"`` (no datapoints, a validation/engine error,
326
+ or an unexpected exception).
325
327
  """
326
328
  name = config.name
329
+ # Two independent switches, checked broadest-first. `enabled: false` retires
330
+ # the whole metric (`dtk run` skips it too), so tuning it would persist
331
+ # detections and emit a `__tuned_<id>.yml` for something deliberately taken
332
+ # out of production. `autotune.enabled: false` keeps the metric live but
333
+ # opts it out of automatic tuning. Either way it counts as skipped, not
334
+ # failed — the exit code stays 0. `dtk tune` is deliberately NOT gated: the
335
+ # interactive cockpit is how you inspect a disabled metric to decide its fate.
336
+ if not config.enabled:
337
+ echo_noop(name, "metric disabled in config (enabled: false)")
338
+ return "skipped"
327
339
  autotune_cfg = config.autotune or AutoTuneConfig()
328
340
  if not autotune_cfg.enabled:
329
341
  echo_noop(name, "autotune disabled in config")
@@ -13,6 +13,7 @@ from typing import Any
13
13
 
14
14
  import click
15
15
 
16
+ from detectkit.cli._output import echo_noop
16
17
  from detectkit.config.metric_config import MetricConfig, resolve_source_profile
17
18
  from detectkit.config.profile import ProfilesConfig
18
19
  from detectkit.config.project_config import ProjectConfig
@@ -169,6 +170,59 @@ def _status_str(status: Any) -> str:
169
170
  return status.value if isinstance(status, TaskStatus) else str(status)
170
171
 
171
172
 
173
+ def _skipped_metric_entry(name: str) -> dict[str, Any]:
174
+ """A JSON-summary entry for a metric the run did not process.
175
+
176
+ Shaped exactly like a processed metric's entry (the key set is part of the
177
+ ``schema_version: 1`` contract) with every counter at zero and no error —
178
+ a skip is a deliberate outcome, not a failure.
179
+ """
180
+ return {
181
+ "name": name,
182
+ "status": "skipped",
183
+ "steps_completed": [],
184
+ "datapoints_loaded": 0,
185
+ "anomalies_detected": 0,
186
+ "alerts_sent": 0,
187
+ "error": None,
188
+ }
189
+
190
+
191
+ def _refresh_disabled_registry(
192
+ internal_manager: InternalTablesManager,
193
+ project_config: ProjectConfig,
194
+ disabled_metrics: list[tuple[Path, MetricConfig]],
195
+ ) -> None:
196
+ """Refresh ``_dtk_metrics`` for the metrics this run skipped.
197
+
198
+ ``_dtk_metrics`` is the informational mirror of each metric's config and
199
+ carries an ``enabled`` column, so a skipped metric must still refresh its
200
+ row — otherwise the registry (and any dashboard built on it) would keep
201
+ reporting a just-disabled metric as enabled forever. This is the *only*
202
+ database write a disabled metric gets: no lock, no datapoints, no
203
+ detections, no alerts. Informational, so a failure here is a warning and
204
+ never the run's exit code.
205
+ """
206
+ table_override = None
207
+ if project_config is not None and hasattr(project_config, "tables"):
208
+ table_override = project_config.tables.metrics
209
+
210
+ for metric_path, config in disabled_metrics:
211
+ try:
212
+ internal_manager.upsert_metric_config(
213
+ metric_config=config,
214
+ file_path=str(metric_path),
215
+ table_name_override=table_override,
216
+ )
217
+ except Exception as exc: # never fail a run over the informational mirror
218
+ click.echo(
219
+ click.style(
220
+ f" │ Registry refresh skipped for {config.name}: {exc}",
221
+ fg="yellow",
222
+ )
223
+ )
224
+
225
+
172
226
  def _finish_summary(summary: dict[str, Any], started_at: datetime, rc: int) -> None:
173
227
  """Fill in totals, timing and the final status, keyed off the per-metric entries."""
174
228
  finished_at = now_utc_naive()
@@ -296,6 +350,23 @@ def _run_impl(
296
350
  summary["error"] = f"No metrics found matching selector: {select}"
297
351
  return 1
298
352
 
353
+ # `enabled: false` takes the metric out of the pipeline entirely — no load,
354
+ # no detect, no alert, no lock. The skip happens HERE, in the runner, not in
355
+ # discovery/`select_metrics`, for two reasons: (1) observability — a disabled
356
+ # metric stays visible as one `•` line in the log and a `skipped` entry in
357
+ # the --json summary instead of silently vanishing; (2) every other command
358
+ # shares `select_metrics`, and they must keep seeing it — `dtk tune`/`dtk ui`
359
+ # are exactly how you inspect a disabled metric to decide its fate, and its
360
+ # `_dtk_*` rows must not read as orphaned to `dtk clean --orphaned-metrics`.
361
+ # A skip is a config choice, never a failure: it does not affect the exit
362
+ # code (a run whose every selected metric is disabled still exits 0).
363
+ disabled_metrics = [(path, cfg) for path, cfg in metrics if not cfg.enabled]
364
+ if disabled_metrics:
365
+ metrics = [(path, cfg) for path, cfg in metrics if cfg.enabled]
366
+ for _path, disabled_config in disabled_metrics:
367
+ echo_noop(disabled_config.name, "disabled in config (enabled: false) — skipped")
368
+ summary["metrics"].append(_skipped_metric_entry(disabled_config.name))
369
+
299
370
  click.echo(f"Found {len(metrics)} metric(s) to process")
300
371
  click.echo()
301
372
 
@@ -330,7 +401,8 @@ def _run_impl(
330
401
  # mode) must name a real profile. This is a cheap name check — no
331
402
  # connections opened — so a typo'd source_profile fails the whole run
332
403
  # up front instead of surfacing deep inside whichever metric's LOAD step
333
- # happens to hit it first.
404
+ # happens to hit it first. Disabled metrics are already out of `metrics`,
405
+ # so a typo in one of them can't fail a run that would never have used it.
334
406
  source_profile_error = _validate_source_profiles(metrics, project_config, profiles_config)
335
407
  if source_profile_error:
336
408
  # A config typo, not an outage: exit 1 without paging error_alerting,
@@ -397,6 +469,11 @@ def _run_impl(
397
469
  summary["error"] = f"Error initializing internal tables: {e}"
398
470
  return 1
399
471
 
472
+ # Disabled metrics run no pipeline step, but their config mirror stays
473
+ # truthful so `_dtk_metrics.enabled` reflects the YAML that was just read.
474
+ if disabled_metrics:
475
+ _refresh_disabled_registry(internal_manager, project_config, disabled_metrics)
476
+
400
477
  # The active STATE profile's actual name (mirrors ProfilesConfig.get_profile's
401
478
  # own None -> default_profile resolution) — lets the task manager recognize
402
479
  # a metric's source_profile that happens to name the state profile itself,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: detectkit
3
- Version: 0.67.0
3
+ Version: 0.67.2
4
4
  Summary: Metric monitoring with automatic anomaly detection
5
5
  Author: detectkit team
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes