Commit 9701ef6
authored
✨ qontract-api: events framework (#5420)
* ✨ qontract-api: events framework
* replace DIY event framework with faststream
* feat(01-foundation-configuration-02): extend SlackSettings with notification fields
- Add notification_channel field (str | None, default None)
- Add notification_workspace field (str | None, default None)
- Add secret_path field (str, default 'app-sre/slack/bot-token')
- Add 5 comprehensive tests for new fields
- Maintain backwards compatibility with existing deployments
* test(01-01): add failing tests for chat_post_message
- Add ChatPostMessageResponse model to models.py with ts, channel, thread_ts fields
- Add 7 test functions covering success, thread reply, auto-join, error handling, truncation, and hooks
- All tests fail as expected (RED state) because chat_post_message method does not exist yet
* feat(01-01): implement chat_post_message
- Add chat_post_message method to SlackApi with @invoke_with_hooks decorator
- Auto-join logic handles not_in_channel error with conversations_join + retry
- channel_not_found logged at ERROR level and re-raised
- Other errors logged at WARNING level and re-raised
- Text truncation at 10,000 characters with "... [truncated]" suffix
- Export ChatPostMessageResponse from __init__.py
- All tests pass (7 new + 23 existing)
* refactor(01-01): clean up chat_post_message
- Extract magic value 10000 to MAX_MESSAGE_LENGTH constant
- Use logger.exception instead of logger.error when re-raising
- Add type checking for response.data to satisfy mypy
- Fix exception chaining with 'from None'
- Update test to check logger.exception instead of logger.error
- All tests pass, ruff check/format pass, mypy passes
* feat(02-01): create shared slack module with workspace client and factory function
- Relocate SlackWorkspaceClient to qontract_api/slack/
- Add chat_post_message method to SlackWorkspaceClient
- Create create_slack_workspace_client factory function following PagerDuty pattern
- Factory resolves Secret via SecretManager
* feat(02-01): migrate imports and add tests for shared slack module
- Convert old modules to re-export shims for backward compatibility
- Update service.py to use create_slack_workspace_client function
- Update tasks.py to pass cache directly to service
- Migrate test imports to new location
- Add new tests for factory function and chat_post_message
- Use lazy imports to avoid circular dependencies
- All 43 tests passing
* feat(03-01): add POST /api/v1/external/slack/chat endpoint
- Create frozen Pydantic request/response models with Secret, icon, and username fields
- Implement POST /chat router with ValueError (404) and SlackApiError (502) handling
- Add channel name → ID resolution with # prefix stripping in SlackWorkspaceClient
- Rename SlackApi.chat_post_message channel → channel_id for type clarity
- Add icon_emoji, icon_url, username params through the full call chain
- Replace msg_kwargs dict with explicit typed parameters for mypy safety
- Improve general_exception_handler to preserve HTTPException status/detail
- Register slack router in api_v1
- Add 5 endpoint tests + 2 workspace client tests (channel resolution, hash prefix)
* fixup! feat(02-01): create shared slack module with workspace client and factory function
* feat(04-01): add SubscriberSettings to config and clean up old SlackSettings fields
- Add SubscriberSettings model with required slack_channel, slack_workspace, slack_token_path
- Add optional qontract_api_url (defaults to http://localhost:8000) and qontract_api_token_path
- Add Settings.subscriber field (defaults to None for backward compatibility)
- Remove deprecated notification_channel, notification_workspace, secret_path from SlackSettings
- Add comprehensive tests for SubscriberSettings and Settings.subscriber
* feat(04-01): create event formatter registry with generic formatter, metrics, and tests
- Add EventFormatter protocol for type-safe formatter registration
- Implement GenericEventFormatter with emoji mapping (error, fail, create, update, delete)
- Format events as human-readable Slack messages with emoji, type, source, and JSON data dump
- Create formatter registry with format_event and register_formatter functions
- Add Prometheus metrics: events_received, events_posted, events_failed counters and event_processing_duration histogram
- Add comprehensive tests for formatter registry and generic formatter with complex data
- Fix ClassVar annotation for EMOJI_MAP to satisfy ruff linter
* feat(04-02): create qontract-api client and subscriber handler
- Add qontract_api_token field to SubscriberSettings for direct token auth
- Create _client.py with _get_client() and post_to_slack() functions
- Rewrite _subscriptions.py event_handler with per-event error isolation
- Increment Prometheus metrics for received, posted, failed events
- Record event processing duration in histogram
* test(04-02): add comprehensive subscriber handler tests
- Create conftest.py with sample_event and error_event fixtures
- Add test_subscriptions.py with 8 test cases covering:
* Event processing flow (format + post)
* Per-event error isolation (SUB-02)
* Prometheus metrics (received, posted, failed, duration)
* Exception handling in both format and post stages
- All 16 subscriber tests pass
* subscriber: slack username and emoji
* delete unused event_sink integration
* subscriber: prometheus
* subscriber: logging
* subscriber: openshift template
* fixup! delete unused event_sink integration
* fixup! subscriber: logging
* fix tests1 parent 2e11083 commit 9701ef6
72 files changed
Lines changed: 3450 additions & 252 deletions
File tree
- docs/adr
- openshift
- qontract_api_client/qontract_api_client
- api/external
- models
- qontract_api
- qontract_api
- cache
- event_manager
- external/slack
- integrations/slack_usergroups
- routers
- secret_manager
- slack
- subscriber
- tests
- external
- slack
- integrations/slack_usergroups
- slack
- subscriber
- tasks
- qontract_utils
- qontract_utils
- events
- slack_api
- tests
- events
- reconcile
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
163 | 292 | | |
164 | 293 | | |
165 | 294 | | |
| |||
365 | 494 | | |
366 | 495 | | |
367 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
368 | 524 | | |
369 | 525 | | |
370 | 526 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
0 commit comments