-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndexAdvisorController.java
More file actions
122 lines (105 loc) · 4.79 KB
/
Copy pathIndexAdvisorController.java
File metadata and controls
122 lines (105 loc) · 4.79 KB
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
package com.dbaagent.controller;
import com.dbaagent.service.IndexAdvisorService;
import com.dbaagent.service.PerformanceMonitoringService;
import com.dbaagent.service.security.AccessControlService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* REST API for enhanced index advisor functionality
*
* <p><b>Authorization:</b> every endpoint here takes a caller-supplied connection id, so
* each one asserts access itself ({@code assertCanReadConnectionContent} for reads,
* {@code assertCanManageConnectionContent} for writes). {@code SecurityConfig} only
* requires an authenticated principal — nothing upstream inspects a connection id. See
* {@code ConnectionScopedAuthorizationSafetyTest}.
*/
@RestController
@RequestMapping("/index-advisor")
@RequiredArgsConstructor
@Slf4j
public class IndexAdvisorController {
private final IndexAdvisorService indexAdvisorService;
private final PerformanceMonitoringService performanceMonitoringService;
private final AccessControlService accessControlService;
/**
* Get comprehensive index health report
*/
@GetMapping("/{connectionId}/health-report")
public ResponseEntity<Map<String, Object>> getHealthReport(@PathVariable String connectionId) {
accessControlService.assertCanReadConnectionContent(connectionId);
return ResponseEntity.ok(indexAdvisorService.getIndexHealthReport(connectionId));
}
/**
* Get unused indexes
*/
@GetMapping("/{connectionId}/unused")
public ResponseEntity<List<Map<String, Object>>> getUnusedIndexes(@PathVariable String connectionId) {
accessControlService.assertCanReadConnectionContent(connectionId);
return ResponseEntity.ok(performanceMonitoringService.getUnusedIndexes(connectionId));
}
/**
* Get duplicate/redundant indexes
*/
@GetMapping("/{connectionId}/duplicates")
public ResponseEntity<List<Map<String, Object>>> getDuplicateIndexes(@PathVariable String connectionId) {
accessControlService.assertCanReadConnectionContent(connectionId);
return ResponseEntity.ok(performanceMonitoringService.getDuplicateIndexes(connectionId));
}
/**
* Estimate index creation impact
*/
@PostMapping("/{connectionId}/estimate-create")
public ResponseEntity<Map<String, Object>> estimateIndexCreation(
@PathVariable String connectionId,
@RequestBody Map<String, Object> request) {
accessControlService.assertCanReadConnectionContent(connectionId);
String tableName = (String) request.get("tableName");
@SuppressWarnings("unchecked")
List<String> columnsList = (List<String>) request.get("columns");
String[] columns = columnsList != null ? columnsList.toArray(new String[0]) : new String[0];
boolean unique = Boolean.TRUE.equals(request.get("unique"));
if (tableName == null || columns.length == 0) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(indexAdvisorService.estimateIndexCreationImpact(
connectionId, tableName, columns, unique));
}
/**
* Estimate index drop impact
*/
@PostMapping("/{connectionId}/estimate-drop")
public ResponseEntity<Map<String, Object>> estimateIndexDrop(
@PathVariable String connectionId,
@RequestBody Map<String, Object> request) {
accessControlService.assertCanReadConnectionContent(connectionId);
String tableName = (String) request.get("tableName");
String indexName = (String) request.get("indexName");
if (tableName == null || indexName == null) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(indexAdvisorService.estimateIndexDropImpact(
connectionId, tableName, indexName));
}
/**
* Get index usage statistics for a table
*/
@GetMapping("/{connectionId}/usage/{tableName}")
public ResponseEntity<List<Map<String, Object>>> getIndexUsageStats(
@PathVariable String connectionId,
@PathVariable String tableName) {
accessControlService.assertCanReadConnectionContent(connectionId);
return ResponseEntity.ok(performanceMonitoringService.getIndexUsageStats(connectionId, tableName));
}
/**
* Get cache hit ratios (includes index cache)
*/
@GetMapping("/{connectionId}/cache-stats")
public ResponseEntity<Map<String, Double>> getCacheStats(@PathVariable String connectionId) {
accessControlService.assertCanReadConnectionContent(connectionId);
return ResponseEntity.ok(performanceMonitoringService.getCacheHitRatios(connectionId));
}
}