File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
main/java/com/netflix/zuul/context
test/java/com/netflix/zuul/context Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ public class CommonContextKeys {
4848 public static final SessionContext .Key <RequestAttempts > REQUEST_ATTEMPTS =
4949 SessionContext .newKey ("request_attempts" );
5050
51+ public static final SessionContext .Key <String > BROWNOUT_REASON = SessionContext .newKey ("brownout_reason" );
52+
5153 public static final SessionContext .Key <IClientConfig > REST_CLIENT_CONFIG =
5254 SessionContext .newKey ("rest_client_config" );
5355
Original file line number Diff line number Diff line change 1919import com .netflix .config .DynamicPropertyFactory ;
2020import com .netflix .zuul .filters .FilterError ;
2121import com .netflix .zuul .message .http .HttpResponseMessage ;
22+ import jakarta .annotation .Nullable ;
2223import java .net .URL ;
2324import java .util .ArrayList ;
2425import java .util .Collections ;
3031import java .util .Objects ;
3132import java .util .Set ;
3233import java .util .function .Supplier ;
33- import javax .annotation .Nullable ;
3434import lombok .NonNull ;
3535
3636/**
@@ -475,10 +475,24 @@ public boolean isInBrownoutMode() {
475475 return brownoutMode ;
476476 }
477477
478+ /**
479+ * Flag the server is getting overloaded.
480+ * @deprecated use setInBrownoutMode(String reason)
481+ */
482+ @ Deprecated
478483 public void setInBrownoutMode () {
479484 this .brownoutMode = true ;
480485 }
481486
487+ public void setInBrownoutMode (@ NonNull String reason ) {
488+ this .brownoutMode = true ;
489+ put (CommonContextKeys .BROWNOUT_REASON , reason );
490+ }
491+
492+ public @ Nullable String getBrownoutReason () {
493+ return get (CommonContextKeys .BROWNOUT_REASON );
494+ }
495+
482496 /**
483497 * This is typically set by a filter when wanting to reject a request, and also reduce load on the server
484498 * by not processing any subsequent filters for this request.
Original file line number Diff line number Diff line change @@ -139,4 +139,14 @@ void containsKey() {
139139
140140 assertThat (context .containsKey (key )).isFalse ();
141141 }
142+
143+ @ Test
144+ void setInBrownoutModeWithReason () {
145+ SessionContext context = new SessionContext ();
146+ assertThat (context .getBrownoutReason ()).isNull ();
147+ context .setInBrownoutMode ("High CPU usage" );
148+
149+ assertThat (context .isInBrownoutMode ()).isTrue ();
150+ assertThat (context .getBrownoutReason ()).isEqualTo ("High CPU usage" );
151+ }
142152}
You can’t perform that action at this time.
0 commit comments