Skip to content

Commit 4ff84aa

Browse files
committed
changing alert names, adding support for throughput scaling, skeleton for shard scaling
1 parent d8eacb9 commit 4ff84aa

27 files changed

+170
-129
lines changed

autoscaler/src/main/java/com/redis/autoscaler/Constants.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import java.util.List;
66

77
public class Constants {
8-
public static final String HighMemoryUsageAlert = "HighMemoryUsage";
9-
public static final String HighCpuUsageAlert = "HighCpu";
10-
public static final String HighThroughputAlert = "HighThroughput";
11-
public static final String HighLatencyAlert = "HighLatency";
128
public static final String REDIS_CLOUD_URI_BASE = "https://api.redislabs.com/v1";
139
public static final List<TaskStatus> CURRENTLY_ACTIVE_TASK_STATUSES = List.of(TaskStatus.received, TaskStatus.initialized, TaskStatus.processingInProgress);
1410
}

autoscaler/src/main/java/com/redis/autoscaler/ScaleRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@Builder
1111
@Data
1212
public class ScaleRequest {
13-
private double datasetSizeInGb;
13+
private Double datasetSizeInGb;
1414
private ThroughputMeasurement throughputMeasurement;
1515

1616
@Override

autoscaler/src/main/java/com/redis/autoscaler/controllers/AlertController.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public ResponseEntity<Map<String,Task>> inboundAlert(@RequestBody String jsonBod
6363

6464
// 1. Extract alert type and dbId
6565
String dbId = alert.getLabels().getDbId();
66-
AlertName alertName = alert.getLabels().getAlertName();
66+
RuleType ruleType = alert.getLabels().getRuleType();
6767

6868
if(taskMap.containsKey(dbId)){
6969
LOG.info("Scaling task already in progress for dbId: {}", dbId);
70-
silencerService.silenceAlert(alert.getLabels().getInstance(), alertName, SILENCE_DURATION);
70+
silencerService.silenceAlert(alert.getLabels().getInstance(), ruleType, SILENCE_DURATION);
7171
continue; // move onto next alert
7272
}
7373

@@ -76,26 +76,26 @@ public ResponseEntity<Map<String,Task>> inboundAlert(@RequestBody String jsonBod
7676
if(pendingTaskOption.isPresent() && pendingTaskOption.get().getCurrentStatus() == TaskStatus.processingInProgress){
7777
LOG.info("Scaling task already in progress for dbId: {}", dbId);
7878
taskMap.put(dbId, pendingTaskOption.get());
79-
silencerService.silenceAlert(alert.getLabels().getInstance(), alertName, SILENCE_DURATION);
79+
silencerService.silenceAlert(alert.getLabels().getInstance(), ruleType, SILENCE_DURATION);
8080
continue; // move onto next alert
8181
}
8282

8383
// 3. Find Rules associated alert type and DB ID
84-
Iterable<Rule> rules = ruleRepository.findByDbIdAndRuleType(dbId, alertName);
84+
Iterable<Rule> rules = ruleRepository.findByDbIdAndRuleType(dbId, ruleType);
8585
if(!rules.iterator().hasNext()){
86-
LOG.info("No rule found for dbId: {} and alertName: {} JSON Body: {}", dbId, alertName, jsonBody);
86+
LOG.info("No rule found for dbId: {} and alertName: {} JSON Body: {}", dbId, ruleType, jsonBody);
8787
continue; // move onto next alert
8888
}
8989

9090
// 4. If not, run scaling
9191
Rule rule = rules.iterator().next();
9292
Optional<Task> res = redisCloudDatabaseService.applyRule(rule, dbId);
9393
if(res.isEmpty()){
94-
LOG.info("Failed to apply rule for dbId: {} and alertName: {}", dbId, alertName);
94+
LOG.info("Failed to apply rule for dbId: {} and alertName: {}", dbId, ruleType);
9595
continue;
9696
}
9797

98-
silencerService.silenceAlert(alert.getLabels().getInstance(), alertName, SILENCE_DURATION);
98+
silencerService.silenceAlert(alert.getLabels().getInstance(), ruleType, SILENCE_DURATION);
9999

100100

101101
// 5. Save task data structure along with other metadata while pending

autoscaler/src/main/java/com/redis/autoscaler/controllers/RulesController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.redis.autoscaler.controllers;
22

3-
import com.redis.autoscaler.documents.AlertName;
3+
import com.redis.autoscaler.documents.RuleType;
44
import com.redis.autoscaler.documents.RuleRepository;
55
import com.redis.autoscaler.documents.Rule;
6-
import com.redis.autoscaler.documents.ScaleType;
76
import org.slf4j.Logger;
87
import org.springframework.http.HttpEntity;
98
import org.springframework.http.HttpStatus;
@@ -26,7 +25,7 @@ public RulesController(RuleRepository ruleRepository) {
2625
public HttpEntity<Rule> createRule(@RequestBody Rule rule) {
2726
LOG.info("Received request to create rule: {}", rule);
2827

29-
if(rule.getRuleType() == AlertName.HighMemory || rule.getRuleType() == AlertName.LowMemory) {
28+
if(rule.getRuleType() == RuleType.IncreaseMemory || rule.getRuleType() == RuleType.DecreaseMemory) {
3029
if(!rule.isValid()) {
3130
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
3231
}

autoscaler/src/main/java/com/redis/autoscaler/documents/AlertLabels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@JsonIgnoreProperties(ignoreUnknown = true)
1010
public class AlertLabels {
1111
@JsonProperty("alertname")
12-
private AlertName alertName;
12+
private RuleType ruleType;
1313
private String cluster;
1414
@JsonProperty("db")
1515
private String dbId;
Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
package com.redis.autoscaler.documents;
22

3-
import com.fasterxml.jackson.annotation.JsonSubTypes;
4-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
53
import com.redis.om.spring.annotations.Document;
64
import com.redis.om.spring.annotations.Indexed;
75
import lombok.Data;
86
import org.springframework.data.annotation.Id;
97

108
@Document
119
@Data
12-
//@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "ruleType", visible = true)
13-
//@JsonSubTypes(
14-
// {
15-
// @JsonSubTypes.Type(value = HighMemoryRule.class, name = "HighMemory"),
16-
// @JsonSubTypes.Type(value = LowMemoryRule.class, name = "LowMemory")
17-
// }
18-
//)
1910
public class Rule {
2011
@Indexed
2112
protected String dbId;
@@ -25,7 +16,7 @@ public class Rule {
2516
protected String ruleId;
2617

2718
@Indexed
28-
protected AlertName ruleType;
19+
protected RuleType ruleType;
2920

3021
@Indexed
3122
protected ScaleType scaleType;
@@ -42,7 +33,7 @@ public String toString(){
4233

4334

4435
public boolean isValid(){
45-
if(this.ruleType == AlertName.HighMemory){
36+
if(this.ruleType == RuleType.IncreaseMemory){
4637
if(scaleType == ScaleType.Deterministic || scaleType == ScaleType.Step){
4738
if(scaleValue > scaleCeiling){
4839
return false;
@@ -57,7 +48,7 @@ public boolean isValid(){
5748
}
5849
}
5950

60-
if(this.ruleType == AlertName.LowMemory){
51+
if(this.ruleType == RuleType.DecreaseMemory){
6152
if(scaleType == ScaleType.Deterministic){
6253
if(scaleValue < scaleFloor){
6354
return false;
@@ -79,25 +70,4 @@ protected boolean isMultipleOfPointOne() {
7970
double epsilon = 1e-9; // Small tolerance for floating-point precision
8071
return Math.abs(compValue % 0.1) < epsilon;
8172
}
82-
83-
// public boolean isRuleValid(){
84-
// if(ruleType == AlertName.HighMemory){
85-
// if(scaleType == ScaleType.Deterministic || scaleType == ScaleType.Step){
86-
// if(scaleValue > scaleCeiling){
87-
// return false;
88-
// }
89-
// }
90-
// }
91-
//
92-
// if (ruleType == AlertName.LowMemory){
93-
// if(scaleType == ScaleType.Deterministic){
94-
// if(scaleValue < scaleFloor){
95-
// return false;
96-
// }
97-
// }
98-
// }
99-
//
100-
// return true;
101-
//
102-
// }
10373
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.redis.autoscaler.documents;
22

3-
import com.redis.autoscaler.documents.Rule;
43
import com.redis.om.spring.repository.RedisDocumentRepository;
54

65
public interface RuleRepository extends RedisDocumentRepository<Rule, String> {
7-
Iterable<Rule> findByDbIdAndRuleType(String dbId, AlertName ruleType);
6+
Iterable<Rule> findByDbIdAndRuleType(String dbId, RuleType ruleType);
87
Iterable<Rule> findByDbId(String dbId);
98
}

autoscaler/src/main/java/com/redis/autoscaler/documents/AlertName.java renamed to autoscaler/src/main/java/com/redis/autoscaler/documents/RuleType.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
import com.fasterxml.jackson.annotation.JsonValue;
44

5-
public enum AlertName {
6-
HighMemory("HighMemory"),
7-
LowMemory("LowMemory"),
8-
HighLatency("HighLatency"),
9-
LowLatency("LowLatency"),
10-
HighThroughput("HighThroughput"),
11-
LowThroughput("LowThroughput");
5+
public enum RuleType {
6+
IncreaseMemory("IncreaseMemory"),
7+
DecreaseMemory("DecreaseMemory"),
8+
IncreaseShards("IncreaseShards"),
9+
DecreaseShards("DecreaseShards"),
10+
IncreaseThroughput("IncreaseThroughput"),
11+
DecreaseThroughput("DecreaseThroughput");
1212

1313
private final String value;
1414

15-
AlertName(String alertName) {
15+
RuleType(String alertName) {
1616
this.value = alertName;
1717
}
1818

autoscaler/src/main/java/com/redis/autoscaler/documents/Task.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public class Task {
2020
@Indexed private Instant initialTimeStamp;
2121
@Indexed private Instant lastObservedTimestamp;
2222
private ScaleRequest scaleRequest;
23+
private TaskResponse Response;
2324
}

autoscaler/src/main/java/com/redis/autoscaler/documents/TaskResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class TaskResponse {
1313
private TaskStatus status;
1414
private String description;
1515
private Instant timestamp;
16+
private TaskResponse response;
1617

1718

1819
public Task toTask(){
@@ -24,7 +25,16 @@ public Task toTask(){
2425
taskDocument.setInitialTimeStamp(this.timestamp);
2526
taskDocument.setCurrentStatus(this.status);
2627
taskDocument.setLastObservedTimestamp(this.timestamp);
28+
taskDocument.setResponse(this.response);
2729
return taskDocument;
2830
}
2931

32+
@Data
33+
public static class Response{
34+
private int resourceId;
35+
private int additionalResourceId;
36+
private String error;
37+
private String additionalInfo;
38+
}
39+
3040
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.redis.autoscaler.documents;
2+
3+
import com.fasterxml.jackson.annotation.JsonValue;
4+
5+
public enum TriggerType {
6+
Webhook("webhook"),
7+
Schedule("schedule");
8+
9+
private final String value;
10+
TriggerType(String value){
11+
this.value = value;
12+
}
13+
14+
@JsonValue
15+
public String getValue(){
16+
return value;
17+
}
18+
19+
@Override
20+
public String toString(){
21+
return value;
22+
}
23+
}

autoscaler/src/main/java/com/redis/autoscaler/poller/PrometheusExtrasPoller.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ public PrometheusExtrasPoller(PrometheusMetrics prometheusMetrics, RedisCloudDat
3838
public void pollDbConfiguredThroughput(){
3939
try{
4040
List<Single<List<String>>> dbIdsRes = entityStream.of(Rule.class).groupBy().reduce(ReducerFunction.TOLIST, Rule$.DB_ID).toList(String.class);
41-
// LOG.info(dbIds.toString());
41+
if(dbIdsRes.size() == 0 || ((List<String>)dbIdsRes.get(0).get(0)).size() == 0){
42+
return;
43+
}
44+
4245
List<String> dbIds = (List<String>)dbIdsRes.get(0).get(0);
4346
for (String dbId: dbIds){
44-
// String dbId = (String)dbIdTup.get(0);
4547
RedisCloudDatabase db = redisCloudDatabaseService.getDatabase(dbId);
4648
prometheusMetrics.addConfiguredThroughput(dbId, db.getPrivateEndpoint(), db.getThroughputMeasurement().getValue());
4749
}

autoscaler/src/main/java/com/redis/autoscaler/requests/SilenceMatcher.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.redis.autoscaler.requests;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4-
import com.redis.autoscaler.documents.AlertName;
54
import lombok.Data;
65

76
@Data

autoscaler/src/main/java/com/redis/autoscaler/requests/SilenceRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.redis.autoscaler.requests;
22

3-
import com.redis.autoscaler.documents.AlertName;
3+
import com.redis.autoscaler.documents.RuleType;
44
import lombok.Data;
55

66
import java.time.Instant;
@@ -15,8 +15,8 @@ public class SilenceRequest {
1515
private final String comment = "Silence created by Redis Autoscaler";
1616

1717

18-
public SilenceRequest(String instance, AlertName alertName, int durationMin){
19-
this.matchers = List.of(new SilenceMatcher(MatchType.Instance, instance), new SilenceMatcher(MatchType.AlertName, alertName.getValue()));
18+
public SilenceRequest(String instance, RuleType ruleType, int durationMin){
19+
this.matchers = List.of(new SilenceMatcher(MatchType.Instance, instance), new SilenceMatcher(MatchType.AlertName, ruleType.getValue()));
2020
this.startsAt = Instant.now().toString();
2121
this.endsAt = Instant.now().plusSeconds(durationMin * 60L).toString();
2222
}

0 commit comments

Comments
 (0)