5
5
6
6
package org .opensearch .knn .plugin .stats ;
7
7
8
+ import org .opensearch .Version ;
8
9
import org .opensearch .core .action .ActionListener ;
10
+ import org .opensearch .knn .index .KNNSettings ;
9
11
import org .opensearch .knn .plugin .transport .KNNCircuitBreakerTrippedAction ;
10
12
import org .opensearch .knn .plugin .transport .KNNCircuitBreakerTrippedRequest ;
11
13
import org .opensearch .transport .client .Client ;
12
14
13
15
import java .util .Map ;
14
16
import java .util .function .Function ;
17
+ import java .util .function .Supplier ;
18
+
19
+ import static org .opensearch .knn .index .KNNSettings .KNN_CIRCUIT_BREAKER_TRIGGERED ;
15
20
16
21
public class CircuitBreakerStat extends KNNStat <Boolean > {
17
22
@@ -25,14 +30,26 @@ public class CircuitBreakerStat extends KNNStat<Boolean> {
25
30
};
26
31
27
32
private final Client client ;
33
+ private final Supplier <Version > minVersionSupplier ;
28
34
29
- public CircuitBreakerStat (Client client ) {
35
+ public CircuitBreakerStat (Client client , Supplier < Version > minVersionSupplier ) {
30
36
super (true , FETCHER );
31
37
this .client = client ;
38
+ this .minVersionSupplier = minVersionSupplier ;
32
39
}
33
40
34
41
@ Override
35
42
public ActionListener <Void > setupContext (KNNStatFetchContext knnStatFetchContext , ActionListener <Void > actionListener ) {
43
+ // If there are any nodes in the cluster before 3.0, then we need to fall back to checking the CB
44
+ if (minVersionSupplier .get ().compareTo (Version .V_3_0_0 ) < 0 ) {
45
+ return ActionListener .wrap (knnCircuitBreakerTrippedResponse -> {
46
+ knnStatFetchContext .addContext (
47
+ StatNames .CIRCUIT_BREAKER_TRIGGERED .getName (),
48
+ Map .of (CONTEXT_CB_TRIPPED , KNNSettings .state ().getSettingValue (KNN_CIRCUIT_BREAKER_TRIGGERED ))
49
+ );
50
+ actionListener .onResponse (null );
51
+ }, actionListener ::onFailure );
52
+ }
36
53
return ActionListener .wrap (
37
54
response -> client .execute (
38
55
KNNCircuitBreakerTrippedAction .INSTANCE ,
0 commit comments