-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add config metadata parsing through wasm #182
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
Merged
suthar26
merged 5 commits into
main
from
parthsuthar/cor-3493-add-config-metadata-to-java-sdk
Aug 5, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
da7f221
feat: add config metadata parsing through wasm
suthar26 b9121c3
fix tests
suthar26 00bc37a
update the metadata classes to have proper decorators
suthar26 2cbdef5
remove no args decorator
suthar26 9e9b1f0
update the metadata classes to have NoArgConstructor for parsing
suthar26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,8 @@ public final class EnvironmentConfigManager { | |
| private final DevCycleLocalOptions options; | ||
|
|
||
| private ProjectConfig config; | ||
| private ConfigMetadata configMetadata; | ||
| private String configETag = ""; | ||
| private String configLastModified = ""; | ||
|
|
||
| private final String sdkKey; | ||
| private final int pollingIntervalMS; | ||
|
|
@@ -73,9 +74,7 @@ public void run() { | |
| } | ||
| } catch (DevCycleException e) { | ||
| DevCycleLogger.error("Failed to load config: " + e.getMessage(), e); | ||
| } catch (Exception e) { | ||
|
Contributor
Author
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. removed as it was added through cursor while fixing an error |
||
| DevCycleLogger.error("Unexpected error during config fetch: " + e.getMessage(), e); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -84,15 +83,7 @@ public boolean isConfigInitialized() { | |
| } | ||
|
|
||
| private ProjectConfig getConfig() throws DevCycleException { | ||
| // Handle initial request where configMetadata might be null | ||
| String etag = null; | ||
| String lastModified = null; | ||
| if (this.configMetadata != null) { | ||
| etag = this.configMetadata.configETag; | ||
| lastModified = this.configMetadata.configLastModified; | ||
| } | ||
|
|
||
| Call<ProjectConfig> config = this.configApiClient.getConfig(this.sdkKey, etag, lastModified); | ||
| Call<ProjectConfig> config = this.configApiClient.getConfig(this.sdkKey, this.configETag, this.configLastModified); | ||
| ProjectConfig fetchedConfig = getResponseWithRetries(config, 1); | ||
| this.config = fetchedConfig; | ||
|
|
||
|
|
@@ -204,16 +195,13 @@ private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DevCycl | |
| String currentETag = response.headers().get("ETag"); | ||
| String headerLastModified = response.headers().get("Last-Modified"); | ||
|
|
||
| // Check if we should skip this config due to older timestamp (only if configMetadata exists) | ||
| if (this.configMetadata != null && | ||
| !this.configMetadata.configLastModified.isEmpty() && | ||
| headerLastModified != null && !headerLastModified.isEmpty()) { | ||
| if (!this.configLastModified.isEmpty() && headerLastModified != null && !headerLastModified.isEmpty()) { | ||
| ZonedDateTime parsedLastModified = ZonedDateTime.parse( | ||
| headerLastModified, | ||
| DateTimeFormatter.RFC_1123_DATE_TIME | ||
| ); | ||
| ZonedDateTime configLastModified = ZonedDateTime.parse( | ||
| this.configMetadata.configLastModified, | ||
| this.configLastModified, | ||
| DateTimeFormatter.RFC_1123_DATE_TIME | ||
| ); | ||
|
|
||
|
|
@@ -229,23 +217,18 @@ private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DevCycl | |
| localBucketing.storeConfig(sdkKey, mapper.writeValueAsString(config)); | ||
| } catch (JsonProcessingException e) { | ||
| if (this.config != null) { | ||
| String currentConfigInfo = (this.configMetadata != null) ? | ||
| " etag " + this.configMetadata.configETag + " last-modified: " + this.configMetadata.configLastModified : | ||
| ""; | ||
| DevCycleLogger.error("Unable to parse config with etag: " + currentETag + ". Using cache," + currentConfigInfo); | ||
| DevCycleLogger.error("Unable to parse config with etag: " + currentETag + ". Using cache, etag " + this.configETag + " last-modified: " + this.configLastModified); | ||
| return this.config; | ||
| } else { | ||
| errorResponse.setMessage(e.getMessage()); | ||
| throw new DevCycleException(HttpResponseCode.SERVER_ERROR, errorResponse); | ||
| } | ||
| } | ||
| this.configMetadata = new ConfigMetadata(currentETag, headerLastModified, config.getProject(), config.getEnvironment()); | ||
| this.configETag = currentETag; | ||
| this.configLastModified = headerLastModified; | ||
| return response.body(); | ||
| } else if (httpResponseCode == HttpResponseCode.NOT_MODIFIED) { | ||
| String cacheInfo = (this.configMetadata != null) ? | ||
| " etag: " + this.configMetadata.configETag + " last-modified: " + this.configMetadata.configLastModified : | ||
| " (no metadata available)"; | ||
| DevCycleLogger.debug("Config not modified, using cache," + cacheInfo); | ||
| DevCycleLogger.debug("Config not modified, using cache, etag: " + this.configETag + " last-modified: " + this.configLastModified); | ||
| return this.config; | ||
| } else { | ||
| if (response.errorBody() != null) { | ||
|
|
@@ -291,6 +274,12 @@ public void cleanup() { | |
| } | ||
|
|
||
| public ConfigMetadata getConfigMetadata() { | ||
| return configMetadata; | ||
| String configMetadata = localBucketing.getConfigMetadata(this.sdkKey); | ||
| try { | ||
| return OBJECT_MAPPER.readValue(configMetadata, ConfigMetadata.class); | ||
| } catch (JsonProcessingException e) { | ||
| DevCycleLogger.warning("Unable to parse config metadata: " + e.getMessage()); | ||
| return new ConfigMetadata(); | ||
| } | ||
| } | ||
| } | ||
19 changes: 9 additions & 10 deletions
19
src/main/java/com/devcycle/sdk/server/local/model/ConfigMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,15 @@ | ||
| package com.devcycle.sdk.server.local.model; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.NoArgsConstructor; | ||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class ConfigMetadata { | ||
|
|
||
| public final String configETag; | ||
| public final String configLastModified; | ||
| public final ProjectMetadata project; | ||
| public final EnvironmentMetadata environment; | ||
| public ProjectMetadata project; | ||
| public EnvironmentMetadata environment; | ||
|
|
||
| public ConfigMetadata(String currentETag, String headerLastModified, Project project, Environment environment) { | ||
| this.configETag = currentETag; | ||
| this.configLastModified = headerLastModified; | ||
| this.project = new ProjectMetadata(project._id, project.key); | ||
| this.environment = new EnvironmentMetadata(environment._id, environment.key); | ||
| } | ||
| } |
19 changes: 12 additions & 7 deletions
19
src/main/java/com/devcycle/sdk/server/local/model/EnvironmentMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| package com.devcycle.sdk.server.local.model; | ||
|
|
||
| public class EnvironmentMetadata { | ||
| public final String id; | ||
| public final String key; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.NoArgsConstructor; | ||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
|
||
| public EnvironmentMetadata(String id, String key) { | ||
| this.id = id; | ||
| this.key = key; | ||
| } | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class EnvironmentMetadata { | ||
| @JsonProperty("id") | ||
| public String id; | ||
| @JsonProperty("key") | ||
| public String key; | ||
| } |
19 changes: 12 additions & 7 deletions
19
src/main/java/com/devcycle/sdk/server/local/model/ProjectMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| package com.devcycle.sdk.server.local.model; | ||
|
|
||
| public class ProjectMetadata { | ||
| public final String id; | ||
| public final String key; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.NoArgsConstructor; | ||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| public ProjectMetadata(String id, String key) { | ||
| this.id = id; | ||
| this.key = key; | ||
| } | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class ProjectMetadata { | ||
| @JsonProperty("id") | ||
| public String id; | ||
| @JsonProperty("key") | ||
| public String key; | ||
| } |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
mostly reverting back to the code from before config metadata was added