Skip to content

Commit bdf1d59

Browse files
committed
feat: custom rules
1 parent 3d6ee61 commit bdf1d59

File tree

8 files changed

+924
-19
lines changed

8 files changed

+924
-19
lines changed

pincode.vtb-hack.fe/openapi.json

Lines changed: 224 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@
13751375
"tags": [
13761376
"QueryAnalysis"
13771377
],
1378-
"summary": "Анализирует запрос алгоритмически + по флагу useLlm может выдать рекомендации от LLM и оптимизированный запрос",
1378+
"summary": "Анализирует запрос\n1 - системными правилами для sql и explain\n2 - по флагу useLlm может выдать проблемы и рекомендации от LLM а также сравнение двух запросов\n3 - по ruleIds может проверять запрос по кастомным правилам, если ruleIds не передали, будет проверять по всем правилам",
13791379
"parameters": [
13801380
{
13811381
"name": "queryId",
@@ -1435,6 +1435,7 @@
14351435
"tags": [
14361436
"SqlAnalyzeRule"
14371437
],
1438+
"summary": "Ищет все кастомные правила для аналища SQL",
14381439
"parameters": [
14391440
{
14401441
"name": "skip",
@@ -1502,6 +1503,7 @@
15021503
"tags": [
15031504
"SqlAnalyzeRule"
15041505
],
1506+
"summary": "Создает новое кастомное правило для анализа SQL",
15051507
"requestBody": {
15061508
"content": {
15071509
"application/json": {
@@ -1532,6 +1534,7 @@
15321534
"tags": [
15331535
"SqlAnalyzeRule"
15341536
],
1537+
"summary": "Обновляет кастомное правило",
15351538
"requestBody": {
15361539
"content": {
15371540
"application/json": {
@@ -1564,6 +1567,7 @@
15641567
"tags": [
15651568
"SqlAnalyzeRule"
15661569
],
1570+
"summary": "Удаляет кастомное правило",
15671571
"parameters": [
15681572
{
15691573
"name": "id",
@@ -2103,6 +2107,43 @@
21032107
"additionalProperties": false,
21042108
"description": "Статистика автовакуума PostgreSQL\nСодержит метрики для мониторинга и анализа процесса автоматической очистки базы данных\nАвтовакуум удаляет \"мертвые\" tuple'ы и обновляет статистику для оптимизатора запросов"
21052109
},
2110+
"BufferStats": {
2111+
"type": "object",
2112+
"properties": {
2113+
"sharedHit": {
2114+
"type": "integer",
2115+
"description": "Shared buffer hits.",
2116+
"format": "int64"
2117+
},
2118+
"sharedRead": {
2119+
"type": "integer",
2120+
"description": "Shared buffer reads (from disk).",
2121+
"format": "int64"
2122+
},
2123+
"localHit": {
2124+
"type": "integer",
2125+
"description": "Local buffer hits.",
2126+
"format": "int64"
2127+
},
2128+
"localRead": {
2129+
"type": "integer",
2130+
"description": "Local buffer reads.",
2131+
"format": "int64"
2132+
},
2133+
"tempRead": {
2134+
"type": "integer",
2135+
"description": "Temp blocks read (from temp files).",
2136+
"format": "int64"
2137+
},
2138+
"tempWritten": {
2139+
"type": "integer",
2140+
"description": "Temp blocks written (to temp files).",
2141+
"format": "int64"
2142+
}
2143+
},
2144+
"additionalProperties": false,
2145+
"description": "Метрики буферов, агрегированные для узла."
2146+
},
21062147
"CacheAnalysisResponse": {
21072148
"type": "object",
21082149
"properties": {
@@ -2452,6 +2493,39 @@
24522493
"additionalProperties": false,
24532494
"description": "Описание результата разбора EXPLAIN (FORMAT JSON)."
24542495
},
2496+
"ExplainRootPlan": {
2497+
"type": "object",
2498+
"properties": {
2499+
"commandType": {
2500+
"type": "string",
2501+
"description": "Команда: SELECT/UPDATE/INSERT/DELETE и т.д., если доступно.",
2502+
"nullable": true
2503+
},
2504+
"rootNode": {
2505+
"$ref": "#/components/schemas/PlanNode"
2506+
},
2507+
"planningTimeMs": {
2508+
"type": "number",
2509+
"description": "Время планирования в миллисекундах (если предоставлено).",
2510+
"format": "double",
2511+
"nullable": true
2512+
},
2513+
"executionTimeMs": {
2514+
"type": "number",
2515+
"description": "Время выполнения в миллисекундах (если предоставлено).",
2516+
"format": "double",
2517+
"nullable": true
2518+
},
2519+
"settings": {
2520+
"type": "object",
2521+
"additionalProperties": {},
2522+
"description": "Дополнительные настройки/параметры из EXPLAIN.",
2523+
"nullable": true
2524+
}
2525+
},
2526+
"additionalProperties": false,
2527+
"description": "Корневой план EXPLAIN, содержит метрики времени и общий узел плана."
2528+
},
24552529
"GuidSimpleDto": {
24562530
"type": "object",
24572531
"properties": {
@@ -2928,6 +3002,35 @@
29283002
"additionalProperties": false,
29293003
"description": "Модель для хранения информации о заблокированных lock'ах PostgreSQL"
29303004
},
3005+
"PlanComparisonDto": {
3006+
"type": "object",
3007+
"properties": {
3008+
"cost": {
3009+
"$ref": "#/components/schemas/PlanPointComparsionResult"
3010+
},
3011+
"rows": {
3012+
"$ref": "#/components/schemas/PlanPointComparsionResult"
3013+
},
3014+
"width": {
3015+
"$ref": "#/components/schemas/PlanPointComparsionResult"
3016+
},
3017+
"seqScanCount": {
3018+
"$ref": "#/components/schemas/PlanPointComparsionResult"
3019+
},
3020+
"nodeCount": {
3021+
"$ref": "#/components/schemas/PlanPointComparsionResult"
3022+
},
3023+
"oldJoinTypes": {
3024+
"type": "string",
3025+
"nullable": true
3026+
},
3027+
"newJoinTypes": {
3028+
"type": "string",
3029+
"nullable": true
3030+
}
3031+
},
3032+
"additionalProperties": false
3033+
},
29313034
"PlanFinding": {
29323035
"type": "object",
29333036
"properties": {
@@ -3003,6 +3106,107 @@
30033106
"additionalProperties": false,
30043107
"description": "Описание одного найденного \"находки\" (issue) по плану."
30053108
},
3109+
"PlanNode": {
3110+
"type": "object",
3111+
"properties": {
3112+
"nodeType": {
3113+
"type": "string",
3114+
"description": "Node Type, как указан в JSON (например, \"Seq Scan\", \"Hash Join\").",
3115+
"nullable": true
3116+
},
3117+
"shortNodeType": {
3118+
"type": "string",
3119+
"description": "Маппинг NodeType на enum, если возможно.",
3120+
"nullable": true
3121+
},
3122+
"startupCost": {
3123+
"type": "number",
3124+
"description": "Оценочная startup cost.",
3125+
"format": "double",
3126+
"nullable": true
3127+
},
3128+
"totalCost": {
3129+
"type": "number",
3130+
"description": "Оценочная total cost.",
3131+
"format": "double",
3132+
"nullable": true
3133+
},
3134+
"planRows": {
3135+
"type": "number",
3136+
"description": "Оценка планировщика: планируемое количество строк.",
3137+
"format": "double",
3138+
"nullable": true
3139+
},
3140+
"planWidth": {
3141+
"type": "number",
3142+
"description": "Оценочная ширина строки (в байтах).",
3143+
"format": "double",
3144+
"nullable": true
3145+
},
3146+
"actualStartupTimeMs": {
3147+
"type": "number",
3148+
"description": "Фактическое стартовое время в миллисекундах (ANALYZE).",
3149+
"format": "double",
3150+
"nullable": true
3151+
},
3152+
"actualTotalTimeMs": {
3153+
"type": "number",
3154+
"description": "Фактическое суммарное время в миллисекундах (ANALYZE).",
3155+
"format": "double",
3156+
"nullable": true
3157+
},
3158+
"actualRows": {
3159+
"type": "number",
3160+
"description": "Фактическое количество строк (single loop).",
3161+
"format": "double",
3162+
"nullable": true
3163+
},
3164+
"actualLoops": {
3165+
"type": "integer",
3166+
"description": "Количество выполнений узла (loops).",
3167+
"format": "int32",
3168+
"nullable": true
3169+
},
3170+
"buffers": {
3171+
"$ref": "#/components/schemas/BufferStats"
3172+
},
3173+
"nodeSpecific": {
3174+
"type": "object",
3175+
"additionalProperties": {},
3176+
"description": "Словарь с произвольными свойствами узла (Index Name, Index Cond, Sort Method, Batches, Disk Usage и т.д.).",
3177+
"nullable": true
3178+
},
3179+
"children": {
3180+
"type": "array",
3181+
"items": {
3182+
"$ref": "#/components/schemas/PlanNode"
3183+
},
3184+
"description": "Дочерние узлы плана.",
3185+
"nullable": true
3186+
}
3187+
},
3188+
"additionalProperties": false,
3189+
"description": "Узел плана EXPLAIN. NodeSpecific содержит все детальные поля, которые не попали в стандартные свойства."
3190+
},
3191+
"PlanPointComparsionResult": {
3192+
"type": "object",
3193+
"properties": {
3194+
"old": {
3195+
"type": "number",
3196+
"format": "double"
3197+
},
3198+
"new": {
3199+
"type": "number",
3200+
"format": "double"
3201+
},
3202+
"differencePercent": {
3203+
"type": "number",
3204+
"format": "double",
3205+
"nullable": true
3206+
}
3207+
},
3208+
"additionalProperties": false
3209+
},
30063210
"ProblematicTable": {
30073211
"type": "object",
30083212
"properties": {
@@ -3085,23 +3289,16 @@
30853289
"nullable": true
30863290
},
30873291
"explainResult": {
3088-
"type": "string",
3089-
"description": "Результат выполнения EXPLAIN для запроса",
3090-
"nullable": true
3292+
"$ref": "#/components/schemas/ExplainRootPlan"
30913293
},
30923294
"algorithmRecommendation": {
30933295
"$ref": "#/components/schemas/SqlAlgorithmAnalysisResult"
30943296
},
30953297
"llmRecommendations": {
3096-
"$ref": "#/components/schemas/LlmAnswer"
3298+
"$ref": "#/components/schemas/SqlLlmAnalysisResult"
30973299
},
3098-
"findindCustomRules": {
3099-
"type": "array",
3100-
"items": {
3101-
"type": "string",
3102-
"format": "uuid"
3103-
},
3104-
"nullable": true
3300+
"explainComparisonDto": {
3301+
"$ref": "#/components/schemas/PlanComparisonDto"
31053302
}
31063303
},
31073304
"additionalProperties": false,
@@ -3149,9 +3346,7 @@
31493346
"nullable": true
31503347
},
31513348
"explainResult": {
3152-
"type": "string",
3153-
"description": "Резульатат выполнения EXPLAIN для запроса",
3154-
"nullable": true
3349+
"$ref": "#/components/schemas/ExplainRootPlan"
31553350
},
31563351
"dbConnectionId": {
31573352
"type": "string",
@@ -3390,6 +3585,18 @@
33903585
},
33913586
"additionalProperties": false
33923587
},
3588+
"SqlLlmAnalysisResult": {
3589+
"type": "object",
3590+
"properties": {
3591+
"llmAnswer": {
3592+
"$ref": "#/components/schemas/LlmAnswer"
3593+
},
3594+
"explainResult": {
3595+
"$ref": "#/components/schemas/ExplainRootPlan"
3596+
}
3597+
},
3598+
"additionalProperties": false
3599+
},
33933600
"StaticAnalysisPoint": {
33943601
"type": "object",
33953602
"properties": {
@@ -3438,7 +3645,8 @@
34383645
40,
34393646
41,
34403647
42,
3441-
43
3648+
43,
3649+
44
34423650
],
34433651
"type": "integer",
34443652
"description": "Коды статических правил анализа SQL.",

pincode.vtb-hack.fe/src/app/documentation/page.tsx renamed to pincode.vtb-hack.fe/src/app/(docs)/documentation/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
AlertCircle,
1515
Info,
1616
} from "lucide-react";
17-
import { type CollapsibleListItemType, CollapsibleList } from "@/components/ui/collapsible-list";
17+
import { type CollapsibleListItemType, CollapsibleList } from "@components/ui/collapsible-list.tsx";
1818
import {
1919
autovacuumMetrics,
2020
cacheMetrics,
@@ -24,7 +24,7 @@ import {
2424
lockMetrics,
2525
sqlRules,
2626
tempFilesMetrics,
27-
} from "@/components/documentation";
27+
} from "@components/documentation";
2828

2929
/**
3030
* Получает иконку в зависимости от уровня серьезности

0 commit comments

Comments
 (0)