@@ -70,6 +70,7 @@ public static Spawner createSpawner(FunctionConfig fnConfig,
70
70
private MetricsSink metricsSink ;
71
71
private int metricsCollectionInterval ;
72
72
private Timer metricsCollectionTimer ;
73
+ private int numRestarts ;
73
74
74
75
private Spawner (LimitsConfig limitsConfig ,
75
76
AssignmentInfo assignmentInfo ,
@@ -83,12 +84,14 @@ private Spawner(LimitsConfig limitsConfig,
83
84
this .codeFile = codeFile ;
84
85
this .metricsSink = metricsSink ;
85
86
this .metricsCollectionInterval = metricsCollectionInterval ;
87
+ this .numRestarts = 0 ;
86
88
}
87
89
88
90
public void start () throws Exception {
89
91
log .info ("Spawner starting function {}" , this .assignmentInfo .getFunctionConfig ().getName ());
90
92
functionContainer = functionContainerFactory .createContainer (createJavaInstanceConfig (), codeFile );
91
93
functionContainer .start ();
94
+ numRestarts ++;
92
95
if (metricsSink != null ) {
93
96
log .info ("Scheduling Metrics Collection every " + metricsCollectionInterval + " secs for " + FunctionConfigUtils .getFullyQualifiedName (assignmentInfo .getFunctionConfig ()));
94
97
metricsCollectionTimer = new Timer ();
@@ -107,6 +110,7 @@ public void run() {
107
110
log .error ("Function Container is dead with exception" , functionContainer .getDeathException ());
108
111
log .error ("Restarting..." );
109
112
functionContainer .start ();
113
+ numRestarts ++;
110
114
}
111
115
}
112
116
}, metricsCollectionInterval * 1000 , metricsCollectionInterval * 1000 );
@@ -120,7 +124,14 @@ public void join() throws Exception {
120
124
}
121
125
122
126
public CompletableFuture <FunctionStatus > getFunctionStatus () {
123
- return functionContainer .getFunctionStatus ();
127
+ return functionContainer .getFunctionStatus ().thenApply (f -> {
128
+ FunctionStatus .Builder builder = FunctionStatus .newBuilder ();
129
+ builder .mergeFrom (f ).setNumRestarts (numRestarts );
130
+ if (functionContainer .getDeathException () != null ) {
131
+ builder .setFailureException (functionContainer .getDeathException ().getMessage ());
132
+ }
133
+ return builder .build ();
134
+ });
124
135
}
125
136
126
137
@ Override
0 commit comments