-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SWC-7044 - Handle error when fetching feature flag configuration #5587
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package org.sagebionetworks.web.server.servlet; | ||
|
||
import com.amazonaws.services.appconfigdata.AWSAppConfigData; | ||
import com.amazonaws.services.appconfigdata.model.BadRequestException; | ||
import com.amazonaws.services.appconfigdata.model.GetLatestConfigurationRequest; | ||
import com.amazonaws.services.appconfigdata.model.GetLatestConfigurationResult; | ||
import com.amazonaws.services.appconfigdata.model.InternalServerException; | ||
import com.amazonaws.services.appconfigdata.model.StartConfigurationSessionRequest; | ||
import com.amazonaws.services.appconfigdata.model.StartConfigurationSessionResult; | ||
import com.google.gwt.thirdparty.guava.common.base.Supplier; | ||
|
@@ -95,11 +97,31 @@ public void initializeConfigSupplier() { | |
); | ||
} | ||
|
||
public JSONObjectAdapter getLastConfigValueOrDefault() { | ||
if (lastConfigValue != null) { | ||
return lastConfigValue; | ||
} | ||
try { | ||
return new JSONObjectAdapterImpl(DEFAULT_CONFIG_VALUE); | ||
} catch (JSONObjectAdapterException e) { | ||
logger.log( | ||
Level.SEVERE, | ||
"JSONObjectAdapterException occurred in default configuration", | ||
e | ||
); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public JSONObjectAdapter getLatestConfiguration() { | ||
try { | ||
if (configurationToken == null) { | ||
logger.log(Level.SEVERE, "returning default config"); | ||
return new JSONObjectAdapterImpl(DEFAULT_CONFIG_VALUE); | ||
logger.log( | ||
Level.SEVERE, | ||
"The configuration token is null, the last config value will be returned." + | ||
" This usually means that the initial call to initialize the configuration session failed." | ||
); | ||
return getLastConfigValueOrDefault(); | ||
} | ||
Comment on lines
118
to
125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this error case will only happen when initialization failed, so I updated the log message to give context. |
||
GetLatestConfigurationRequest latestConfigRequest = | ||
new GetLatestConfigurationRequest() | ||
|
@@ -116,21 +138,22 @@ public JSONObjectAdapter getLatestConfiguration() { | |
if (!newConfigString.isEmpty()) { | ||
lastConfigValue = new JSONObjectAdapterImpl(newConfigString); | ||
} | ||
} catch (BadRequestException | InternalServerException e) { | ||
// Invalid token or server error, re-initialize the session to try to recover. | ||
logger.log( | ||
Level.SEVERE, | ||
"Failed to get latest configuration, returning last or default configuration and attempting to re-initialize the session.", | ||
e | ||
); | ||
initializeAppConfigClient(); | ||
return getLastConfigValueOrDefault(); | ||
Comment on lines
+141
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the logs, a |
||
} catch (Exception e) { | ||
try { | ||
logger.log( | ||
Level.SEVERE, | ||
"Failed to get or parse latest configuration, returning default configuration", | ||
e | ||
); | ||
return new JSONObjectAdapterImpl(DEFAULT_CONFIG_VALUE); | ||
} catch (JSONObjectAdapterException exception) { | ||
logger.log( | ||
Level.SEVERE, | ||
"JSONObjectAdapterException occurred in default configuration", | ||
exception | ||
); | ||
} | ||
logger.log( | ||
Level.SEVERE, | ||
"Failed to get or parse latest configuration, returning last or default configuration.", | ||
e | ||
); | ||
return getLastConfigValueOrDefault(); | ||
} | ||
return lastConfigValue; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't serialize a constant string
"{}"
, we have bigger problems