detectkit 0.2.4__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.
Files changed (51) hide show
  1. detectkit/__init__.py +17 -0
  2. detectkit/alerting/__init__.py +13 -0
  3. detectkit/alerting/channels/__init__.py +21 -0
  4. detectkit/alerting/channels/base.py +193 -0
  5. detectkit/alerting/channels/email.py +146 -0
  6. detectkit/alerting/channels/factory.py +193 -0
  7. detectkit/alerting/channels/mattermost.py +53 -0
  8. detectkit/alerting/channels/slack.py +55 -0
  9. detectkit/alerting/channels/telegram.py +110 -0
  10. detectkit/alerting/channels/webhook.py +139 -0
  11. detectkit/alerting/orchestrator.py +369 -0
  12. detectkit/cli/__init__.py +1 -0
  13. detectkit/cli/commands/__init__.py +1 -0
  14. detectkit/cli/commands/init.py +282 -0
  15. detectkit/cli/commands/run.py +486 -0
  16. detectkit/cli/commands/test_alert.py +184 -0
  17. detectkit/cli/main.py +186 -0
  18. detectkit/config/__init__.py +30 -0
  19. detectkit/config/metric_config.py +499 -0
  20. detectkit/config/profile.py +285 -0
  21. detectkit/config/project_config.py +164 -0
  22. detectkit/config/validator.py +124 -0
  23. detectkit/core/__init__.py +6 -0
  24. detectkit/core/interval.py +132 -0
  25. detectkit/core/models.py +106 -0
  26. detectkit/database/__init__.py +27 -0
  27. detectkit/database/clickhouse_manager.py +393 -0
  28. detectkit/database/internal_tables.py +724 -0
  29. detectkit/database/manager.py +324 -0
  30. detectkit/database/tables.py +138 -0
  31. detectkit/detectors/__init__.py +6 -0
  32. detectkit/detectors/base.py +441 -0
  33. detectkit/detectors/factory.py +138 -0
  34. detectkit/detectors/statistical/__init__.py +8 -0
  35. detectkit/detectors/statistical/iqr.py +508 -0
  36. detectkit/detectors/statistical/mad.py +478 -0
  37. detectkit/detectors/statistical/manual_bounds.py +206 -0
  38. detectkit/detectors/statistical/zscore.py +491 -0
  39. detectkit/loaders/__init__.py +6 -0
  40. detectkit/loaders/metric_loader.py +470 -0
  41. detectkit/loaders/query_template.py +164 -0
  42. detectkit/orchestration/__init__.py +9 -0
  43. detectkit/orchestration/task_manager.py +746 -0
  44. detectkit/utils/__init__.py +17 -0
  45. detectkit/utils/stats.py +196 -0
  46. detectkit-0.2.4.dist-info/METADATA +237 -0
  47. detectkit-0.2.4.dist-info/RECORD +51 -0
  48. detectkit-0.2.4.dist-info/WHEEL +5 -0
  49. detectkit-0.2.4.dist-info/entry_points.txt +2 -0
  50. detectkit-0.2.4.dist-info/licenses/LICENSE +21 -0
  51. detectkit-0.2.4.dist-info/top_level.txt +1 -0
detectkit/cli/main.py ADDED
@@ -0,0 +1,186 @@
1
+ """
2
+ Main CLI entry point for detectkit.
3
+
4
+ Provides dbt-like commands:
5
+ - dtk init <project_name>
6
+ - dtk run --select <selector>
7
+ """
8
+
9
+ import click
10
+
11
+
12
+ @click.group()
13
+ @click.version_option(version="0.1.0", prog_name="detectkit")
14
+ def cli():
15
+ """
16
+ detectkit - Metric monitoring with automatic anomaly detection.
17
+
18
+ A dbt-like tool for monitoring time-series metrics with anomaly detection
19
+ and alerting.
20
+
21
+ Examples:
22
+ dtk init my_project
23
+ dtk run --select cpu_usage
24
+ dtk run --select tag:critical --steps load,detect
25
+ """
26
+ pass
27
+
28
+
29
+ @cli.command()
30
+ @click.argument("project_name")
31
+ @click.option(
32
+ "--target-dir",
33
+ "-d",
34
+ default=".",
35
+ help="Directory to create project in (default: current directory)",
36
+ )
37
+ def init(project_name: str, target_dir: str):
38
+ """
39
+ Initialize a new detectkit project.
40
+
41
+ Creates project structure with configuration files and directories:
42
+ - detectkit_project.yml (project config)
43
+ - profiles.yml (database connections)
44
+ - metrics/ (metric definitions)
45
+ - sql/ (SQL queries)
46
+
47
+ Example:
48
+ dtk init my_monitoring_project
49
+ dtk init analytics --target-dir /opt/projects
50
+ """
51
+ from detectkit.cli.commands.init import run_init
52
+
53
+ run_init(project_name, target_dir)
54
+
55
+
56
+ @cli.command()
57
+ @click.option(
58
+ "--select",
59
+ "-s",
60
+ help="Selector for metrics to run (metric name, path, or tag)",
61
+ required=True,
62
+ )
63
+ @click.option(
64
+ "--exclude",
65
+ "-e",
66
+ help="Selector for metrics to exclude (metric name, path, or tag)",
67
+ )
68
+ @click.option(
69
+ "--steps",
70
+ default="load,detect,alert",
71
+ help="Pipeline steps to execute (default: load,detect,alert)",
72
+ )
73
+ @click.option(
74
+ "--from",
75
+ "from_date",
76
+ help="Start date for data loading (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS)",
77
+ )
78
+ @click.option(
79
+ "--to",
80
+ "to_date",
81
+ help="End date for data loading (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS)",
82
+ )
83
+ @click.option(
84
+ "--full-refresh",
85
+ is_flag=True,
86
+ help="Delete all existing data and reload from scratch",
87
+ )
88
+ @click.option(
89
+ "--force",
90
+ is_flag=True,
91
+ help="Ignore task locks (use with caution)",
92
+ )
93
+ @click.option(
94
+ "--profile",
95
+ help="Profile to use (default: from project config)",
96
+ )
97
+ def run(
98
+ select: str,
99
+ exclude: str,
100
+ steps: str,
101
+ from_date: str,
102
+ to_date: str,
103
+ full_refresh: bool,
104
+ force: bool,
105
+ profile: str,
106
+ ):
107
+ """
108
+ Run metric processing pipeline.
109
+
110
+ Select metrics to process using --select:
111
+ - Metric name: --select cpu_usage
112
+ - Path pattern: --select metrics/critical/*.yml
113
+ - Tag: --select tag:critical
114
+
115
+ Control pipeline steps with --steps:
116
+ - All steps: --steps load,detect,alert (default)
117
+ - Load only: --steps load
118
+ - Detect and alert: --steps detect,alert
119
+
120
+ Examples:
121
+ # Run all steps for single metric
122
+ dtk run --select cpu_usage
123
+
124
+ # Load data only for multiple metrics
125
+ dtk run --select "tag:critical" --steps load
126
+
127
+ # Reload data from specific date
128
+ dtk run --select cpu_usage --from 2024-01-01
129
+
130
+ # Full refresh (delete and reload all data)
131
+ dtk run --select cpu_usage --full-refresh
132
+
133
+ # Force run (ignore locks)
134
+ dtk run --select cpu_usage --force
135
+ """
136
+ from detectkit.cli.commands.run import run_command
137
+
138
+ run_command(
139
+ select=select,
140
+ exclude=exclude,
141
+ steps=steps,
142
+ from_date=from_date,
143
+ to_date=to_date,
144
+ full_refresh=full_refresh,
145
+ force=force,
146
+ profile=profile,
147
+ )
148
+
149
+
150
+ @cli.command()
151
+ @click.argument("metric_name")
152
+ @click.option(
153
+ "--profile",
154
+ help="Profile to use (default: from project config)",
155
+ )
156
+ def test_alert(metric_name: str, profile: str):
157
+ """
158
+ Send test alert for a metric.
159
+
160
+ Sends a test alert with mock anomaly data to all configured channels
161
+ for the specified metric. Useful for:
162
+ - Testing alert channel connectivity
163
+ - Verifying message formatting and rendering
164
+ - Previewing custom alert templates
165
+
166
+ The test alert uses realistic mock data:
167
+ - Current timestamp
168
+ - Mock anomaly value (0.8532)
169
+ - Mock confidence interval [0.4521, 0.6234]
170
+ - Mock severity (4.52)
171
+ - 3 consecutive anomalies
172
+
173
+ Examples:
174
+ # Test alert for single metric
175
+ dtk test-alert cpu_usage
176
+
177
+ # Test with specific profile
178
+ dtk test-alert cpu_usage --profile production
179
+ """
180
+ from detectkit.cli.commands.test_alert import run_test_alert
181
+
182
+ run_test_alert(metric_name=metric_name, profile=profile)
183
+
184
+
185
+ if __name__ == "__main__":
186
+ cli()
@@ -0,0 +1,30 @@
1
+ """Configuration management for detectkit."""
2
+
3
+ from detectkit.config.profile import ProfileConfig, ProfilesConfig
4
+ from detectkit.config.metric_config import (
5
+ MetricConfig,
6
+ DetectorConfig,
7
+ AlertConfig,
8
+ QueryColumnsConfig,
9
+ TablesConfig,
10
+ )
11
+ from detectkit.config.project_config import (
12
+ ProjectConfig,
13
+ ProjectPathsConfig,
14
+ ProjectTablesConfig,
15
+ ProjectTimeoutsConfig,
16
+ )
17
+
18
+ __all__ = [
19
+ "ProfileConfig",
20
+ "ProfilesConfig",
21
+ "MetricConfig",
22
+ "DetectorConfig",
23
+ "AlertConfig",
24
+ "QueryColumnsConfig",
25
+ "TablesConfig",
26
+ "ProjectConfig",
27
+ "ProjectPathsConfig",
28
+ "ProjectTablesConfig",
29
+ "ProjectTimeoutsConfig",
30
+ ]