38
38
import java .util .SortedMap ;
39
39
40
40
import static org .apache .flink .autoscaler .config .AutoScalerOptions .SCALING_ENABLED ;
41
+ import static org .apache .flink .autoscaler .config .AutoScalerOptions .SCALING_EVENT_INTERVAL ;
41
42
import static org .apache .flink .autoscaler .metrics .ScalingHistoryUtils .addToScalingHistoryAndStore ;
42
43
import static org .apache .flink .autoscaler .metrics .ScalingHistoryUtils .getTrimmedScalingHistory ;
43
- import static org .apache .flink .autoscaler .metrics .ScalingMetric .EXPECTED_PROCESSING_RATE ;
44
44
import static org .apache .flink .autoscaler .metrics .ScalingMetric .SCALE_DOWN_RATE_THRESHOLD ;
45
45
import static org .apache .flink .autoscaler .metrics .ScalingMetric .SCALE_UP_RATE_THRESHOLD ;
46
- import static org .apache .flink .autoscaler .metrics .ScalingMetric .TARGET_DATA_RATE ;
47
46
import static org .apache .flink .autoscaler .metrics .ScalingMetric .TRUE_PROCESSING_RATE ;
48
47
49
48
/** Class responsible for executing scaling decisions. */
50
49
public class ScalingExecutor <KEY , Context extends JobAutoScalerContext <KEY >> {
51
- public static final String SCALING_SUMMARY_ENTRY =
52
- " Vertex ID %s | Parallelism %d -> %d | Processing capacity %.2f -> %.2f | Target data rate %.2f" ;
53
- public static final String SCALING_SUMMARY_HEADER_SCALING_DISABLED =
54
- "Recommended parallelism change:" ;
55
- public static final String SCALING_SUMMARY_HEADER_SCALING_ENABLED = "Scaling vertices:" ;
56
- @ VisibleForTesting static final String SCALING_REPORT_REASON = "ScalingReport" ;
57
-
58
50
private static final Logger LOG = LoggerFactory .getLogger (ScalingExecutor .class );
59
51
60
52
private final JobVertexScaler <KEY , Context > jobVertexScaler ;
@@ -100,18 +92,11 @@ public boolean scaleResource(
100
92
101
93
updateRecommendedParallelism (evaluatedMetrics , scalingSummaries );
102
94
103
- var scalingEnabled = conf .get (SCALING_ENABLED );
104
-
105
- var scalingReport = scalingReport (scalingSummaries , scalingEnabled );
106
- autoScalerEventHandler .handleEvent (
107
- context ,
108
- AutoScalerEventHandler .Type .Normal ,
109
- SCALING_REPORT_REASON ,
110
- scalingReport ,
111
- "ScalingExecutor" ,
112
- scalingEnabled ? null : conf .get (AutoScalerOptions .SCALING_REPORT_INTERVAL ));
95
+ var scaleEnabled = conf .get (SCALING_ENABLED );
96
+ autoScalerEventHandler .handleScalingEvent (
97
+ context , scalingSummaries , scaleEnabled , conf .get (SCALING_EVENT_INTERVAL ));
113
98
114
- if (!scalingEnabled ) {
99
+ if (!scaleEnabled ) {
115
100
return false ;
116
101
}
117
102
@@ -136,27 +121,6 @@ private void updateRecommendedParallelism(
136
121
scalingSummary .getNewParallelism ())));
137
122
}
138
123
139
- private static String scalingReport (
140
- Map <JobVertexID , ScalingSummary > scalingSummaries , boolean scalingEnabled ) {
141
- StringBuilder sb =
142
- new StringBuilder (
143
- scalingEnabled
144
- ? SCALING_SUMMARY_HEADER_SCALING_ENABLED
145
- : SCALING_SUMMARY_HEADER_SCALING_DISABLED );
146
- scalingSummaries .forEach (
147
- (v , s ) ->
148
- sb .append (
149
- String .format (
150
- SCALING_SUMMARY_ENTRY ,
151
- v ,
152
- s .getCurrentParallelism (),
153
- s .getNewParallelism (),
154
- s .getMetrics ().get (TRUE_PROCESSING_RATE ).getAverage (),
155
- s .getMetrics ().get (EXPECTED_PROCESSING_RATE ).getCurrent (),
156
- s .getMetrics ().get (TARGET_DATA_RATE ).getAverage ())));
157
- return sb .toString ();
158
- }
159
-
160
124
protected static boolean allVerticesWithinUtilizationTarget (
161
125
Map <JobVertexID , Map <ScalingMetric , EvaluatedScalingMetric >> evaluatedMetrics ,
162
126
Map <JobVertexID , ScalingSummary > scalingSummaries ) {
@@ -190,7 +154,8 @@ protected static boolean allVerticesWithinUtilizationTarget(
190
154
return true ;
191
155
}
192
156
193
- private Map <JobVertexID , ScalingSummary > computeScalingSummary (
157
+ @ VisibleForTesting
158
+ Map <JobVertexID , ScalingSummary > computeScalingSummary (
194
159
Context context ,
195
160
Map <JobVertexID , Map <ScalingMetric , EvaluatedScalingMetric >> evaluatedMetrics ,
196
161
Map <JobVertexID , SortedMap <Instant , ScalingSummary >> scalingHistory ) {
0 commit comments