detectkit 0.70.0__tar.gz → 0.72.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.
- {detectkit-0.70.0/detectkit.egg-info → detectkit-0.72.0}/PKG-INFO +1 -1
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/__init__.py +1 -1
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/rules/cli.md +8 -2
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/rules/metrics.md +17 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/rules/project.md +1 -0
- detectkit-0.72.0/detectkit/cli/commands/lineage.py +94 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/run.py +7 -1
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/main.py +27 -0
- detectkit-0.72.0/detectkit/config/lineage.py +312 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/config/metric_config.py +11 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/config/project_config.py +11 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/config/validator.py +5 -2
- detectkit-0.72.0/detectkit/control/events.py +335 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/queries.py +194 -0
- detectkit-0.72.0/detectkit/control/relations.py +111 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/mcp/__init__.py +1 -1
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/mcp/descriptions.py +50 -2
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/mcp/server.py +22 -2
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/mcp/tools.py +3 -0
- detectkit-0.72.0/detectkit/semantic/sources.py +78 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/api_v1.py +27 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/mcp_app.py +38 -2
- {detectkit-0.70.0 → detectkit-0.72.0/detectkit.egg-info}/PKG-INFO +1 -1
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit.egg-info/SOURCES.txt +5 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/LICENSE +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/MANIFEST.in +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/README.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/base.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/branding.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/discord.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/email.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/factory.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/googlechat.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/mattermost.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/ntfy.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/slack.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/teams.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/telegram.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/channels/webhook.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/_base.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/_cooldown.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/_decision.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/_dispatch.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/_recovery.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/_replay.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/_types.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/alerting/orchestrator/orchestrator.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/_base.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/_types.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/alert_sim.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/autotuner.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/axis_spec.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/config_emitter.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/crossval.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/detector_select.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/distribution.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/grid_search.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/key_select.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/labels.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/profile_engine.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/result.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/runner.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/scoring.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/seasonality_search.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/settings.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/autotune/window_select.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/_output.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/CLAUDE.section.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/rules/alerting.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/rules/autotune.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/rules/detectors.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/rules/overview.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/skills/dtk-autotune/SKILL.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/skills/dtk-feedback/SKILL.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/skills/dtk-new-metric/SKILL.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/skills/dtk-setup-project/SKILL.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/assets/claude/skills/dtk-tune/SKILL.md +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/autotune.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/clean.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/init.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/init_claude.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/mcp.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/osi.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/serve.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/test_alert.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/tune.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/ui.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/cli/commands/unlock.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/config/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/config/metric_io.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/config/profile.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/actions.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/actor.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/advise.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/commands.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/confirm.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/drafts.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/errors.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/health.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/jobs.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/metric_files.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/overview.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/project.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/proposals.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/registry.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/roles.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/serialize.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/control/yaml_patch.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/core/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/core/interval.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/core/models.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/_sql_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/bigquery_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/clickhouse_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/duckdb_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_alert_states.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_autotune_runs.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_base.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_datapoints.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_detections.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_maintenance.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_metrics.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_platform.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_schema.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/_tasks.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/internal_tables/manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/mysql_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/postgres_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/snowflake_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/source_manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/database/tables.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/base.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/factory.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/seasonality.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/_baseline.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/_windowed.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/autoreg.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/iqr.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/mad.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/manual_bounds.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/detectors/statistical/zscore.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/loaders/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/loaders/errors.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/loaders/metric_loader.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/loaders/query_template.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/mcp/context.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/mcp/errors.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/error_dispatch.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/task_manager/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/task_manager/_alert_step.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/task_manager/_base.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/task_manager/_detect_step.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/task_manager/_load_step.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/task_manager/_types.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/orchestration/task_manager/manager.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/reporting/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/reporting/assets/report.js +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/reporting/builder.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/reporting/html_report.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/semantic/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/semantic/errors.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/semantic/exporter.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/semantic/importer.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/semantic/osi_model.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/semantic/query_gen.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/app.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/errors.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/forge.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/platform.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/projects.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/server.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/settings.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/web.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/serve/write_tools.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/tuning/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/tuning/assets/tune.js +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/tuning/config_writer.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/tuning/html.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/tuning/payload.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/tuning/server.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/ui/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/ui/assets/ui.js +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/ui/html.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/ui/server.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/utils/__init__.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/utils/datetime_utils.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/utils/env_interpolation.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/utils/json_utils.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit/utils/stats.py +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit.egg-info/dependency_links.txt +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit.egg-info/entry_points.txt +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit.egg-info/requires.txt +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/detectkit.egg-info/top_level.txt +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/pyproject.toml +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/requirements.txt +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/setup.cfg +0 -0
- {detectkit-0.70.0 → detectkit-0.72.0}/setup.py +0 -0
|
@@ -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.
|
|
7
|
+
__version__ = "0.72.0"
|
|
8
8
|
|
|
9
9
|
from detectkit.core.interval import Interval
|
|
10
10
|
from detectkit.core.models import ColumnDefinition, TableModel
|
|
@@ -16,6 +16,7 @@ Run all commands from a project directory (the one containing
|
|
|
16
16
|
| `dtk test-alert <metric>` | Send a mock alert to the metric's channels |
|
|
17
17
|
| `dtk unlock --select <sel>` | Clear a stuck pipeline lock |
|
|
18
18
|
| `dtk clean --select <sel>` | Prune internal data that no longer matches the config |
|
|
19
|
+
| `dtk lineage [--json]` | Show the metric families (declared `lineage`) and validate them over the whole project; exit 1 on an error — the gate for generated metrics |
|
|
19
20
|
| `dtk osi import <model>` | Scaffold a native metric from an OSI semantic-model metric (see "OSI interop") |
|
|
20
21
|
| `dtk osi export` | Publish metrics into an OSI fragment (config in `custom_extensions[detectkit]`) |
|
|
21
22
|
| `dtk mcp` | Serve a **read-only** MCP server for an AI assistant (metrics, data, alerts, autotune history — no writes) |
|
|
@@ -403,11 +404,16 @@ server, exposing a project to *another* AI assistant (an MCP client — Claude
|
|
|
403
404
|
Code, Claude Desktop, an IDE extension) rather than being one itself. It is a
|
|
404
405
|
separate, additive command (needs `pip install 'detectkit[mcp]'`) that
|
|
405
406
|
contains **zero write paths**: no config edits, no label writes, no pipeline
|
|
406
|
-
runs, no schema creation.
|
|
407
|
+
runs, no schema creation. Thirteen tools: `list_metrics`, `get_metric`,
|
|
407
408
|
`get_metric_status`, `get_project_status`, `query_datapoints`,
|
|
408
409
|
`query_detections`, `replay_alerts` (reconstructs the alert timeline the same
|
|
409
410
|
way `dtk run --report` does — never reads `_dtk_alert_states`, never
|
|
410
|
-
dispatches), `get_autotune_history`, `get_incidents`, `
|
|
411
|
+
dispatches), `get_autotune_history`, `get_incidents`, `get_related_metrics`
|
|
412
|
+
(a metric's family by declared `lineage` + metrics reading the same table),
|
|
413
|
+
`list_anomaly_events` / `get_anomaly_event` (what broke, grouped into events
|
|
414
|
+
across metrics by `lineage` and shared source tables — metrics that only
|
|
415
|
+
overlapped in time are listed as `also_anomalous`, never merged),
|
|
416
|
+
`get_server_info`.
|
|
411
417
|
Channel connection details/secrets in `profiles.yml` are never exposed —
|
|
412
418
|
`get_metric` lists alerting channels by name only.
|
|
413
419
|
|
|
@@ -61,8 +61,25 @@ tables: # optional — per-metric internal table override
|
|
|
61
61
|
detections: _dtk_detections_api
|
|
62
62
|
|
|
63
63
|
false_alert_budget: 0.3 # optional — `dtk tune` target false-alert rate (0,1]; overrides project
|
|
64
|
+
|
|
65
|
+
lineage: # optional — what the metric counts (metadata, never in any id)
|
|
66
|
+
measure: api_requests # the measure, independent of slicing
|
|
67
|
+
slice: {status: error} # the part of it this metric is ({} = the total)
|
|
68
|
+
# or: lineage: {ratio: {numerator: api_errors, denominator: api_requests}}
|
|
64
69
|
```
|
|
65
70
|
|
|
71
|
+
`lineage` declares the metric's **structure**. Metrics sharing a `measure` form a
|
|
72
|
+
family (the total, its slices, the ratios built on it), and a slice moves with its
|
|
73
|
+
total **by construction**, so their alerts are one event, never independent evidence.
|
|
74
|
+
It is declared, never guessed: a minor slice correlates with its total no more than
|
|
75
|
+
genuinely different metrics do. Project load refuses two metrics with the same
|
|
76
|
+
`measure` + `slice` and a slice key or value spelled two ways in a family. With the
|
|
77
|
+
project's `lineage: required`, it refuses a metric without the block, which is the
|
|
78
|
+
guarantee for generated metrics. `dtk lineage` checks the whole project and prints
|
|
79
|
+
the families. The MCP tool `get_related_metrics` returns a metric's family plus the
|
|
80
|
+
metrics reading the same source table. Metadata only: no id changes, and the pipeline
|
|
81
|
+
never reads it. When the user generates metrics in bulk, write `lineage` on each one.
|
|
82
|
+
|
|
66
83
|
`false_alert_budget` is a per-metric **target false-alert rate** (a fraction in
|
|
67
84
|
`(0, 1]`) the `dtk tune` cockpit gently flags when exceeded. It overrides the
|
|
68
85
|
project-wide default; unset → project, then a built-in `0.5`. Tuning-only — it never
|
|
@@ -33,6 +33,7 @@ timeouts: # per-step, seconds
|
|
|
33
33
|
alert_help_url: null # optional, see below — "How to read this alert" link
|
|
34
34
|
false_alert_budget: null # optional — `dtk tune` target FDR (0,1]; per-metric override wins
|
|
35
35
|
loading_delay: null # optional — default data-maturity delay; per-metric override wins
|
|
36
|
+
lineage: optional # optional — `required`: every metric must declare `lineage` (see metrics.md)
|
|
36
37
|
source_profile: null # optional — hybrid mode: default source-DB profile; per-metric override wins
|
|
37
38
|
|
|
38
39
|
error_alerting: # optional, see below
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Implementation of ``dtk lineage``: the project's metric families, validated (RFC 0002).
|
|
2
|
+
|
|
3
|
+
Reads every metric under ``metrics/`` (never a subset: lineage is a property of the
|
|
4
|
+
whole pool), prints each family — a measure, its total and slices, the ratios built
|
|
5
|
+
on it — plus the metrics that declare nothing, and checks the lineage the same way
|
|
6
|
+
project load does. Exit code 0 when valid, 1 on an error (a duplicate definition, two
|
|
7
|
+
spellings of one slice key, a missing block under ``lineage: required``), 2 when not
|
|
8
|
+
in a project. An onboarding pipeline gates on it before merging generated metrics.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
import click
|
|
17
|
+
|
|
18
|
+
from detectkit.config.lineage import build_families, lineage_report, lineage_required
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _slice_text(sl: dict[str, str]) -> str:
|
|
22
|
+
return ", ".join(f"{k}={v}" for k, v in sorted(sl.items())) or "total"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def run_lineage(*, as_json: bool) -> int:
|
|
26
|
+
from detectkit.cli.commands.run import find_project_root # noqa: PLC0415
|
|
27
|
+
from detectkit.config.validator import ( # noqa: PLC0415
|
|
28
|
+
discover_metric_files,
|
|
29
|
+
validate_metric_uniqueness,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
root = find_project_root()
|
|
33
|
+
if not root:
|
|
34
|
+
click.echo("Error: Not in a detectkit project directory!", err=True)
|
|
35
|
+
return 2
|
|
36
|
+
metrics_dir = root / "metrics"
|
|
37
|
+
try:
|
|
38
|
+
pairs = validate_metric_uniqueness(
|
|
39
|
+
discover_metric_files(metrics_dir) if metrics_dir.exists() else []
|
|
40
|
+
)
|
|
41
|
+
except ValueError as exc:
|
|
42
|
+
click.echo(click.style(f"Error: {exc}", fg="red", bold=True), err=True)
|
|
43
|
+
return 1
|
|
44
|
+
required = lineage_required(root)
|
|
45
|
+
report = lineage_report(pairs, required=required)
|
|
46
|
+
families = build_families(config for _p, config in pairs)
|
|
47
|
+
undeclared = sorted(config.name for _p, config in pairs if config.lineage is None)
|
|
48
|
+
|
|
49
|
+
if as_json:
|
|
50
|
+
payload: dict[str, Any] = {
|
|
51
|
+
"lineage": "required" if required else "optional",
|
|
52
|
+
"metrics": len(pairs),
|
|
53
|
+
"families": [
|
|
54
|
+
{
|
|
55
|
+
"measure": fam.measure,
|
|
56
|
+
"members": [
|
|
57
|
+
{"metric": name, "slice": sl}
|
|
58
|
+
for name, sl in sorted(fam.members.items(), key=lambda kv: len(kv[1]))
|
|
59
|
+
],
|
|
60
|
+
"ratios": [{"metric": n, "role": r} for n, r in sorted(fam.ratios.items())],
|
|
61
|
+
}
|
|
62
|
+
for fam in families.values()
|
|
63
|
+
],
|
|
64
|
+
"undeclared": undeclared,
|
|
65
|
+
"errors": report.errors,
|
|
66
|
+
"warnings": report.warnings,
|
|
67
|
+
}
|
|
68
|
+
click.echo(json.dumps(payload, indent=2))
|
|
69
|
+
return 1 if report.errors else 0
|
|
70
|
+
|
|
71
|
+
click.echo(
|
|
72
|
+
f"Project root: {root}\n{len(pairs)} metric(s), lineage "
|
|
73
|
+
f"{'required' if required else 'optional'}\n"
|
|
74
|
+
)
|
|
75
|
+
for fam in families.values():
|
|
76
|
+
click.echo(click.style(f"measure {fam.measure}", bold=True))
|
|
77
|
+
for name, sl in sorted(fam.members.items(), key=lambda kv: (len(kv[1]), kv[0])):
|
|
78
|
+
indent = " " * (1 + len(sl))
|
|
79
|
+
click.echo(f"{indent}{name} [{_slice_text(sl)}]")
|
|
80
|
+
for name, role in sorted(fam.ratios.items()):
|
|
81
|
+
click.echo(f" {name} [ratio, {role}]")
|
|
82
|
+
if undeclared:
|
|
83
|
+
click.echo(click.style(f"\nno lineage declared ({len(undeclared)}):", fg="yellow"))
|
|
84
|
+
for name in undeclared:
|
|
85
|
+
click.echo(f" {name}")
|
|
86
|
+
for warning in report.warnings:
|
|
87
|
+
click.echo(click.style(f"\nwarning: {warning}", fg="yellow"))
|
|
88
|
+
if report.errors:
|
|
89
|
+
click.echo(click.style(f"\n{len(report.errors)} lineage error(s):", fg="red", bold=True))
|
|
90
|
+
for error in report.errors:
|
|
91
|
+
click.echo(click.style(f" - {error}", fg="red"))
|
|
92
|
+
return 1
|
|
93
|
+
click.echo(click.style("\nlineage OK", fg="green"))
|
|
94
|
+
return 0
|
|
@@ -14,6 +14,7 @@ from typing import Any
|
|
|
14
14
|
import click
|
|
15
15
|
|
|
16
16
|
from detectkit.cli._output import echo_noop
|
|
17
|
+
from detectkit.config.lineage import check_lineage, lineage_required
|
|
17
18
|
from detectkit.config.metric_config import MetricConfig, resolve_source_profile
|
|
18
19
|
from detectkit.config.profile import ProfilesConfig
|
|
19
20
|
from detectkit.config.project_config import ProjectConfig
|
|
@@ -853,7 +854,12 @@ def select_metrics(selector: str, project_root: Path) -> list[tuple[Path, Metric
|
|
|
853
854
|
|
|
854
855
|
# Validate uniqueness and load configs
|
|
855
856
|
# This will raise ValueError if duplicate metric names found
|
|
856
|
-
|
|
857
|
+
pairs = validate_metric_uniqueness(metric_paths)
|
|
858
|
+
# Lineage (RFC 0002) is checked over the metrics this command loads: duplicates
|
|
859
|
+
# and two spellings of a slice key always; a missing block under
|
|
860
|
+
# `lineage: required`.
|
|
861
|
+
check_lineage(pairs, required=lineage_required(project_root))
|
|
862
|
+
return pairs
|
|
857
863
|
|
|
858
864
|
|
|
859
865
|
def find_metrics_by_tag(metrics_dir: Path, tag: str) -> list[Path]:
|
|
@@ -533,6 +533,33 @@ def unlock(select: str, profile: str):
|
|
|
533
533
|
run_unlock(select=select, profile=profile)
|
|
534
534
|
|
|
535
535
|
|
|
536
|
+
@cli.command()
|
|
537
|
+
@click.option("--json", "as_json", is_flag=True, help="Print the families as JSON")
|
|
538
|
+
def lineage(as_json: bool):
|
|
539
|
+
"""
|
|
540
|
+
Show the project's metric families and validate their lineage.
|
|
541
|
+
|
|
542
|
+
A metric may declare what it counts (`lineage: {measure, slice}`) or how it is
|
|
543
|
+
derived (`lineage: {ratio: {numerator, denominator}}`). Metrics sharing a measure
|
|
544
|
+
form a family: the total, its slices, the ratios built on it. This command
|
|
545
|
+
reads every metric (never a subset), prints the families and the metrics that
|
|
546
|
+
declare nothing, and checks the lineage the way project load does.
|
|
547
|
+
|
|
548
|
+
Exit code: 0 valid, 1 a lineage error (a duplicate definition, two spellings
|
|
549
|
+
of one slice key, a missing block under `lineage: required`), 2 not in a
|
|
550
|
+
project. Gate automatic metric onboarding on it.
|
|
551
|
+
|
|
552
|
+
Examples:
|
|
553
|
+
dtk lineage
|
|
554
|
+
dtk lineage --json
|
|
555
|
+
"""
|
|
556
|
+
from detectkit.cli.commands.lineage import run_lineage
|
|
557
|
+
|
|
558
|
+
rc = run_lineage(as_json=as_json)
|
|
559
|
+
if rc:
|
|
560
|
+
raise SystemExit(rc)
|
|
561
|
+
|
|
562
|
+
|
|
536
563
|
@cli.command()
|
|
537
564
|
@click.option(
|
|
538
565
|
"--select",
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"""Metric lineage: what a metric counts and which part of it (RFC 0002 phase 1).
|
|
2
|
+
|
|
3
|
+
A metric may declare its **structure** so that the platform never has to guess it:
|
|
4
|
+
|
|
5
|
+
```yaml
|
|
6
|
+
lineage:
|
|
7
|
+
measure: purchases_completed # what is counted, independent of slicing
|
|
8
|
+
slice: {provider: a} # the filter that makes this metric a part of it
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```yaml
|
|
12
|
+
lineage:
|
|
13
|
+
ratio: {numerator: sessions_started, denominator: active_users}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Metrics that share a ``measure`` form a **family**: ``slice: {}`` is the total, a
|
|
17
|
+
slice whose filter strictly contains another's is its child, slices that neither
|
|
18
|
+
contain one another are siblings. A ratio joins the families of its numerator and
|
|
19
|
+
denominator as a *derived* member.
|
|
20
|
+
|
|
21
|
+
Lineage is declared, never inferred: a total and a minor slice of it correlate no
|
|
22
|
+
more than genuinely different measures do (Case C-003), so statistics can't be the
|
|
23
|
+
source of truth. It is **metadata** — never hashed into a detector or alert-config
|
|
24
|
+
id, never read by load/detect/alert. :func:`check_lineage` validates a set of
|
|
25
|
+
metrics at project load: duplicate definitions and two spellings of one slice key
|
|
26
|
+
are errors, and a project's ``lineage: required`` makes a metric without the block
|
|
27
|
+
an error too (the guarantee for generated metrics).
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import re
|
|
33
|
+
from collections.abc import Iterable
|
|
34
|
+
from dataclasses import dataclass, field
|
|
35
|
+
from pathlib import Path
|
|
36
|
+
from typing import TYPE_CHECKING, Any
|
|
37
|
+
|
|
38
|
+
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
39
|
+
|
|
40
|
+
if TYPE_CHECKING:
|
|
41
|
+
from detectkit.config.metric_config import MetricConfig
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _text(value: Any, what: str) -> str:
|
|
45
|
+
if isinstance(value, bool) or value is None or isinstance(value, (dict, list)):
|
|
46
|
+
raise ValueError(f"{what} must be a string")
|
|
47
|
+
text = str(value).strip()
|
|
48
|
+
if not text:
|
|
49
|
+
raise ValueError(f"{what} must not be empty")
|
|
50
|
+
return text
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class RatioLineage(BaseModel):
|
|
54
|
+
"""A ratio's parts, each named by its measure."""
|
|
55
|
+
|
|
56
|
+
model_config = ConfigDict(extra="forbid")
|
|
57
|
+
|
|
58
|
+
numerator: str = Field(description="The measure on top of the ratio")
|
|
59
|
+
denominator: str = Field(description="The measure below the ratio")
|
|
60
|
+
|
|
61
|
+
@field_validator("numerator", "denominator", mode="before")
|
|
62
|
+
@classmethod
|
|
63
|
+
def _non_empty(cls, v: Any) -> str:
|
|
64
|
+
return _text(v, "ratio numerator/denominator")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class LineageConfig(BaseModel):
|
|
68
|
+
"""What a metric counts (``measure`` + ``slice``) or how it is derived (``ratio``)."""
|
|
69
|
+
|
|
70
|
+
model_config = ConfigDict(extra="forbid")
|
|
71
|
+
|
|
72
|
+
measure: str | None = Field(
|
|
73
|
+
default=None, description="What is counted, independent of how it is sliced"
|
|
74
|
+
)
|
|
75
|
+
slice: dict[str, str] = Field(
|
|
76
|
+
default_factory=dict,
|
|
77
|
+
description="The filter that makes this metric a part of the measure ({} = the total)",
|
|
78
|
+
)
|
|
79
|
+
ratio: RatioLineage | None = Field(
|
|
80
|
+
default=None, description="A ratio of two measures (instead of measure + slice)"
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
@field_validator("measure", mode="before")
|
|
84
|
+
@classmethod
|
|
85
|
+
def _measure_text(cls, v: Any) -> str | None:
|
|
86
|
+
return None if v is None else _text(v, "lineage.measure")
|
|
87
|
+
|
|
88
|
+
@field_validator("slice", mode="before")
|
|
89
|
+
@classmethod
|
|
90
|
+
def _slice_text(cls, v: Any) -> dict[str, str]:
|
|
91
|
+
if v is None:
|
|
92
|
+
return {}
|
|
93
|
+
if not isinstance(v, dict):
|
|
94
|
+
raise ValueError("lineage.slice must be a mapping of dimension: value")
|
|
95
|
+
return {
|
|
96
|
+
_text(k, "a lineage.slice dimension"): _text(val, f"lineage.slice.{k}")
|
|
97
|
+
for k, val in v.items()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@model_validator(mode="after")
|
|
101
|
+
def _one_shape(self) -> LineageConfig:
|
|
102
|
+
if (self.measure is None) == (self.ratio is None):
|
|
103
|
+
raise ValueError("lineage needs exactly one of `measure` or `ratio`")
|
|
104
|
+
if self.ratio is not None and self.slice:
|
|
105
|
+
raise ValueError("lineage.slice applies to a `measure`, not to a `ratio`")
|
|
106
|
+
return self
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def family(self) -> str:
|
|
110
|
+
"""The family this metric belongs to (a ratio's: its numerator's)."""
|
|
111
|
+
if self.ratio is not None:
|
|
112
|
+
return self.ratio.numerator
|
|
113
|
+
assert self.measure is not None
|
|
114
|
+
return self.measure
|
|
115
|
+
|
|
116
|
+
def to_public(self) -> dict[str, Any]:
|
|
117
|
+
"""The JSON shape the read tools return."""
|
|
118
|
+
if self.ratio is not None:
|
|
119
|
+
return {
|
|
120
|
+
"ratio": {"numerator": self.ratio.numerator, "denominator": self.ratio.denominator}
|
|
121
|
+
}
|
|
122
|
+
return {"measure": self.measure, "slice": dict(self.slice)}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# ── families ────────────────────────────────────────────────────────────────
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _norm(text: str) -> str:
|
|
129
|
+
"""How two spellings of one slice key compare: case, `-`, `_` and spaces ignored."""
|
|
130
|
+
return re.sub(r"[\s_\-]+", "", text).lower()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@dataclass
|
|
134
|
+
class Family:
|
|
135
|
+
"""The metrics of one measure, plus the ratios built on it."""
|
|
136
|
+
|
|
137
|
+
measure: str
|
|
138
|
+
members: dict[str, dict[str, str]] = field(default_factory=dict) # metric -> slice
|
|
139
|
+
ratios: dict[str, str] = field(default_factory=dict) # ratio metric -> numerator|denominator
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def build_families(configs: Iterable[MetricConfig]) -> dict[str, Family]:
|
|
143
|
+
"""Every family declared by *configs*, keyed by measure (insertion-ordered)."""
|
|
144
|
+
families: dict[str, Family] = {}
|
|
145
|
+
for config in configs:
|
|
146
|
+
lin = config.lineage
|
|
147
|
+
if lin is None:
|
|
148
|
+
continue
|
|
149
|
+
if lin.ratio is not None:
|
|
150
|
+
for role, measure in (
|
|
151
|
+
("numerator", lin.ratio.numerator),
|
|
152
|
+
("denominator", lin.ratio.denominator),
|
|
153
|
+
):
|
|
154
|
+
families.setdefault(measure, Family(measure)).ratios[config.name] = role
|
|
155
|
+
else:
|
|
156
|
+
assert lin.measure is not None
|
|
157
|
+
families.setdefault(lin.measure, Family(lin.measure)).members[config.name] = dict(
|
|
158
|
+
lin.slice
|
|
159
|
+
)
|
|
160
|
+
return families
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@dataclass
|
|
164
|
+
class LineageReport:
|
|
165
|
+
errors: list[str] = field(default_factory=list)
|
|
166
|
+
warnings: list[str] = field(default_factory=list)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def lineage_report(
|
|
170
|
+
pairs: Iterable[tuple[Path, MetricConfig]], *, required: bool = False
|
|
171
|
+
) -> LineageReport:
|
|
172
|
+
"""Validate the lineage of a set of metrics; nothing is raised."""
|
|
173
|
+
report = LineageReport()
|
|
174
|
+
pairs = list(pairs)
|
|
175
|
+
where = {config.name: path for path, config in pairs}
|
|
176
|
+
|
|
177
|
+
if required:
|
|
178
|
+
for path, config in pairs:
|
|
179
|
+
if config.lineage is None:
|
|
180
|
+
report.errors.append(
|
|
181
|
+
f"metric '{config.name}' ({path}) has no `lineage` block, and the project "
|
|
182
|
+
"sets `lineage: required`. Declare what it counts "
|
|
183
|
+
"(`lineage: {measure: ..., slice: {...}}`, or `{measure: <its own name>}` "
|
|
184
|
+
"for a standalone metric)."
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
families = build_families(config for _p, config in pairs)
|
|
188
|
+
for family in families.values():
|
|
189
|
+
seen: dict[tuple[tuple[str, str], ...], str] = {}
|
|
190
|
+
for name, sl in family.members.items():
|
|
191
|
+
key = tuple(sorted(sl.items()))
|
|
192
|
+
if key in seen:
|
|
193
|
+
shown = ", ".join(f"{k}={v}" for k, v in key) or "the total"
|
|
194
|
+
report.errors.append(
|
|
195
|
+
f"duplicate lineage: '{seen[key]}' ({where[seen[key]]}) and '{name}' "
|
|
196
|
+
f"({where[name]}) both declare measure '{family.measure}', slice {shown}. "
|
|
197
|
+
"Two metrics counting the same thing would alert twice for one event."
|
|
198
|
+
)
|
|
199
|
+
else:
|
|
200
|
+
seen[key] = name
|
|
201
|
+
spellings: dict[str, set[str]] = {}
|
|
202
|
+
values: dict[tuple[str, str], set[str]] = {}
|
|
203
|
+
for sl in family.members.values():
|
|
204
|
+
for k, v in sl.items():
|
|
205
|
+
spellings.setdefault(_norm(k), set()).add(k)
|
|
206
|
+
values.setdefault((_norm(k), _norm(v)), set()).add(v)
|
|
207
|
+
for variants in spellings.values():
|
|
208
|
+
if len(variants) > 1:
|
|
209
|
+
report.errors.append(
|
|
210
|
+
f"measure '{family.measure}' spells one slice dimension "
|
|
211
|
+
f"{len(variants)} ways: {', '.join(sorted(variants))}. Use one spelling, "
|
|
212
|
+
"or the slices can't be compared."
|
|
213
|
+
)
|
|
214
|
+
for (kn, _vn), variants in values.items():
|
|
215
|
+
if len(variants) > 1:
|
|
216
|
+
key_name = sorted(spellings[kn])[0]
|
|
217
|
+
report.errors.append(
|
|
218
|
+
f"measure '{family.measure}', dimension '{key_name}': one value spelled "
|
|
219
|
+
f"{len(variants)} ways ({', '.join(sorted(variants))})."
|
|
220
|
+
)
|
|
221
|
+
if family.ratios and not family.members:
|
|
222
|
+
users = ", ".join(sorted(family.ratios))
|
|
223
|
+
report.warnings.append(
|
|
224
|
+
f"measure '{family.measure}' is used by the ratio(s) {users} but no metric "
|
|
225
|
+
"in this set declares it."
|
|
226
|
+
)
|
|
227
|
+
return report
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def check_lineage(pairs: Iterable[tuple[Path, MetricConfig]], *, required: bool = False) -> None:
|
|
231
|
+
"""Raise ``ValueError`` listing every lineage error in *pairs*."""
|
|
232
|
+
report = lineage_report(pairs, required=required)
|
|
233
|
+
if report.errors:
|
|
234
|
+
raise ValueError("Invalid metric lineage:\n - " + "\n - ".join(report.errors))
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def lineage_required(project_root: Path) -> bool:
|
|
238
|
+
"""Whether the project's ``detectkit_project.yml`` sets ``lineage: required``.
|
|
239
|
+
|
|
240
|
+
Read leniently and on its own (a missing or unreadable project file means
|
|
241
|
+
"optional"), so metric selection doesn't depend on the rest of the project config.
|
|
242
|
+
"""
|
|
243
|
+
import yaml # noqa: PLC0415
|
|
244
|
+
|
|
245
|
+
path = project_root / "detectkit_project.yml"
|
|
246
|
+
try:
|
|
247
|
+
data = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
|
|
248
|
+
except (OSError, yaml.YAMLError):
|
|
249
|
+
return False
|
|
250
|
+
return isinstance(data, dict) and data.get("lineage") == "required"
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
# ── relations of one metric ─────────────────────────────────────────────────
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _contains(coarse: dict[str, str], fine: dict[str, str]) -> bool:
|
|
257
|
+
"""True when every condition of *coarse* also holds in *fine* (fine is part of coarse)."""
|
|
258
|
+
return all(fine.get(k) == v for k, v in coarse.items())
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def structural_relations(name: str, configs: Iterable[MetricConfig]) -> list[dict[str, Any]]:
|
|
262
|
+
"""How every other metric in *configs* is related to *name* by declared lineage.
|
|
263
|
+
|
|
264
|
+
Each relation is ``{metric, relation, measure, slice?}`` where ``relation`` is one of
|
|
265
|
+
``total`` (the family's ``{}`` member), ``parent`` (a coarser slice that contains
|
|
266
|
+
this one), ``slice`` (a finer slice inside this one), ``sibling`` (same measure,
|
|
267
|
+
neither contains the other), ``ratio`` (a ratio built on this measure — ``role``
|
|
268
|
+
says numerator or denominator) or ``part`` (for a ratio: a metric of its
|
|
269
|
+
numerator's or denominator's measure).
|
|
270
|
+
"""
|
|
271
|
+
configs = list(configs)
|
|
272
|
+
by_name = {c.name: c for c in configs}
|
|
273
|
+
me = by_name.get(name)
|
|
274
|
+
if me is None or me.lineage is None:
|
|
275
|
+
return []
|
|
276
|
+
families = build_families(configs)
|
|
277
|
+
out: list[dict[str, Any]] = []
|
|
278
|
+
lin = me.lineage
|
|
279
|
+
if lin.ratio is not None:
|
|
280
|
+
for role, measure in (
|
|
281
|
+
("numerator", lin.ratio.numerator),
|
|
282
|
+
("denominator", lin.ratio.denominator),
|
|
283
|
+
):
|
|
284
|
+
fam = families.get(measure)
|
|
285
|
+
for other, sl in (fam.members.items() if fam else []):
|
|
286
|
+
out.append(
|
|
287
|
+
{
|
|
288
|
+
"metric": other,
|
|
289
|
+
"relation": "part",
|
|
290
|
+
"role": role,
|
|
291
|
+
"measure": measure,
|
|
292
|
+
"slice": sl,
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
return out
|
|
296
|
+
fam = families[lin.family]
|
|
297
|
+
mine = lin.slice
|
|
298
|
+
for other, sl in fam.members.items():
|
|
299
|
+
if other == name:
|
|
300
|
+
continue
|
|
301
|
+
if not sl:
|
|
302
|
+
relation = "total"
|
|
303
|
+
elif sl != mine and _contains(sl, mine):
|
|
304
|
+
relation = "parent"
|
|
305
|
+
elif sl != mine and _contains(mine, sl):
|
|
306
|
+
relation = "slice"
|
|
307
|
+
else:
|
|
308
|
+
relation = "sibling"
|
|
309
|
+
out.append({"metric": other, "relation": relation, "measure": fam.measure, "slice": sl})
|
|
310
|
+
for other, role in fam.ratios.items():
|
|
311
|
+
out.append({"metric": other, "relation": "ratio", "role": role, "measure": fam.measure})
|
|
312
|
+
return out
|
|
@@ -11,6 +11,7 @@ from typing import Any
|
|
|
11
11
|
|
|
12
12
|
from pydantic import BaseModel, Field, field_validator, model_validator
|
|
13
13
|
|
|
14
|
+
from detectkit.config.lineage import LineageConfig
|
|
14
15
|
from detectkit.core.interval import Interval
|
|
15
16
|
|
|
16
17
|
|
|
@@ -849,6 +850,16 @@ class MetricConfig(BaseModel):
|
|
|
849
850
|
"default; unset → fall back to project, then a built-in default."
|
|
850
851
|
),
|
|
851
852
|
)
|
|
853
|
+
# What the metric counts (measure + slice) or how it is derived (ratio) — RFC 0002.
|
|
854
|
+
# Metadata only: never hashed into an id, never read by load/detect/alert.
|
|
855
|
+
lineage: LineageConfig | None = Field(
|
|
856
|
+
default=None,
|
|
857
|
+
description=(
|
|
858
|
+
"Optional metric lineage: `{measure, slice}` or `{ratio: {numerator, "
|
|
859
|
+
"denominator}}`. Groups a total with its slices so related alerts are never "
|
|
860
|
+
"mistaken for independent evidence. Metadata only."
|
|
861
|
+
),
|
|
862
|
+
)
|
|
852
863
|
enabled: bool = Field(default=True, description="Whether metric is enabled")
|
|
853
864
|
|
|
854
865
|
@field_validator("false_alert_budget")
|
|
@@ -5,6 +5,7 @@ Defines configuration structure for detectkit_project.yml.
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
from typing import Literal
|
|
8
9
|
|
|
9
10
|
from pydantic import BaseModel, Field, field_validator
|
|
10
11
|
|
|
@@ -212,6 +213,16 @@ class ProjectConfig(BaseModel):
|
|
|
212
213
|
"`false_alert_budget` takes priority; unset → a built-in default."
|
|
213
214
|
),
|
|
214
215
|
)
|
|
216
|
+
# Metric lineage policy (RFC 0002). ``required`` makes a metric without a
|
|
217
|
+
# ``lineage`` block fail to load — the guarantee for generated metrics, whose
|
|
218
|
+
# generator knows the measure and the slice it built the SQL from.
|
|
219
|
+
lineage: Literal["optional", "required"] = Field(
|
|
220
|
+
default="optional",
|
|
221
|
+
description=(
|
|
222
|
+
"`required`: every metric must declare `lineage` (what it counts), or the "
|
|
223
|
+
"project fails to load. Default `optional`."
|
|
224
|
+
),
|
|
225
|
+
)
|
|
215
226
|
# Project-wide default data-maturity delay. Useful when every metric reads
|
|
216
227
|
# from the same upstream pipeline (e.g. one dbt project that finishes a few
|
|
217
228
|
# minutes after each interval closes). A per-metric ``loading_delay``
|
|
@@ -7,6 +7,7 @@ ensuring data integrity and preventing configuration errors.
|
|
|
7
7
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
|
+
from detectkit.config.lineage import check_lineage, lineage_required
|
|
10
11
|
from detectkit.config.metric_config import MetricConfig
|
|
11
12
|
|
|
12
13
|
|
|
@@ -153,5 +154,7 @@ def validate_project_metrics(project_root: Path) -> list[tuple[Path, MetricConfi
|
|
|
153
154
|
f"Expected at least one *.yml or *.yaml file."
|
|
154
155
|
)
|
|
155
156
|
|
|
156
|
-
# Validate uniqueness
|
|
157
|
-
|
|
157
|
+
# Validate uniqueness, then lineage (RFC 0002) over the whole project
|
|
158
|
+
pairs = validate_metric_uniqueness(metric_paths)
|
|
159
|
+
check_lineage(pairs, required=lineage_required(project_root))
|
|
160
|
+
return pairs
|