Skip to content

Commit

Permalink
Set variable eval status
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSinn committed Jun 18, 2024
1 parent f4fc363 commit c56e769
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ private ProjectConfig getResponseWithRetries(Call<ProjectConfig> call, int maxRe

private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DevCycleException {
ErrorResponse errorResponse = ErrorResponse.builder().build();
Response<ProjectConfig> response;
Response<ProjectConfig> response = null;

try {
response = call.execute();

} catch (JsonParseException badJsonExc) {
// Got a valid status code but the response body was not valid json,
// need to ignore this attempt and let the polling retry
Expand All @@ -125,11 +126,16 @@ private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DevCycl
} catch (IOException e) {
errorResponse.setMessage(e.getMessage());
throw new DevCycleException(HttpResponseCode.byCode(500), errorResponse);
} finally {
try {
this.eventQueueManager.queueSDKConfigEvent(call.request(), response, errorResponse);
} catch (Exception e) {
// Explicitly ignore - best effort.
}
}

HttpResponseCode httpResponseCode = HttpResponseCode.byCode(response.code());
errorResponse.setMessage("Unknown error");

if (response.isSuccessful()) {
String currentETag = response.headers().get("ETag");
String lastModified = response.headers().get("Last-Modified");
Expand All @@ -149,21 +155,12 @@ private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DevCycl
}
this.configETag = currentETag;
this.configLastModified = lastModified;
try {
this.eventQueueManager.queueSDKConfigEvent(call.request(), response);
} catch (Exception e) {
// Explicitly ignore - best effort.
}

return response.body();
} else if (httpResponseCode == HttpResponseCode.NOT_MODIFIED) {
DevCycleLogger.debug("Config not modified, using cache, etag: " + this.configETag);
return this.config;
} else {
try {
this.eventQueueManager.queueSDKConfigEvent(call.request(), response);
} catch (Exception e) {
// Explicitly ignore - best effort.
}
if (response.errorBody() != null) {
try {
errorResponse = OBJECT_MAPPER.readValue(response.errorBody().string(), ErrorResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.devcycle.sdk.server.common.api.IDevCycleApi;
import com.devcycle.sdk.server.common.logging.DevCycleLogger;
import com.devcycle.sdk.server.common.model.DevCycleEvent;
import com.devcycle.sdk.server.common.model.DevCycleResponse;
import com.devcycle.sdk.server.common.model.DevCycleUser;
import com.devcycle.sdk.server.common.model.ProjectConfig;
import com.devcycle.sdk.server.common.model.*;
import com.devcycle.sdk.server.local.api.DevCycleLocalEventsApiClient;
import com.devcycle.sdk.server.local.bucketing.LocalBucketing;
import com.devcycle.sdk.server.local.model.BucketedUserConfig;
Expand Down Expand Up @@ -111,27 +108,37 @@ public void queueEvent(DevCycleUser user, DevCycleEvent event) throws Exception
this.localBucketing.queueEvent(this.sdkKey, OBJECT_MAPPER.writeValueAsString(user), OBJECT_MAPPER.writeValueAsString(event));
}

public void queueSDKConfigEvent(Request req, Response<ProjectConfig> response) throws Exception {
public void queueSDKConfigEvent(Request req, Response<ProjectConfig> response, ErrorResponse errorResponse) throws Exception {
DevCycleUser user = new DevCycleUser();
user.setUserId(localBucketing.getClientUUID() + "@" + InetAddress.getLocalHost().getHostName());
DevCycleEvent event = new DevCycleEvent();
event.setType("sdkConfig");
event.setTarget(req.url().toString());

try (okhttp3.Response res = response.raw().networkResponse()) {
event.setValue(BigDecimal.valueOf(res.receivedResponseAtMillis() - res.sentRequestAtMillis()));
} catch (Exception e) {
if (response != null) {
try (okhttp3.Response res = response.raw().networkResponse()) {
event.setValue(BigDecimal.valueOf(res.receivedResponseAtMillis() - res.sentRequestAtMillis()));
} catch (Exception e) {
event.setValue(BigDecimal.valueOf(-1));
}
} else {
event.setValue(BigDecimal.valueOf(-1));
}
HashMap<String, Object> metaData = new HashMap<>();
metaData.put("clientUUID", localBucketing.getClientUUID());
metaData.put("reqEtag", req.header("If-None-Match"));
metaData.put("reqLastModified", req.header("If-Modified-Since"));
metaData.put("resEtag", response.headers().get("etag"));
metaData.put("resLastModified", response.headers().get("Last-Modified"));
metaData.put("resRayId", response.headers().get("cf-ray"));
metaData.put("resStatus", response.code());
metaData.put("errMsg", response.code() != 200 && response.code() != 304 ? response.message() : null);
if (response != null) {
metaData.put("resEtag", response.headers().get("etag"));
metaData.put("resLastModified", response.headers().get("Last-Modified"));
metaData.put("resRayId", response.headers().get("cf-ray"));
metaData.put("resStatus", response.code());
metaData.put("errMsg", response.code() != 200 && response.code() != 304 ? response.message() : null);
} else if (errorResponse != null) {
metaData.put("resStatus", errorResponse.getStatusCode());
metaData.put("errMsg", errorResponse.getMessage());
}

metaData.put("sseConnected", null);
event.setMetaData(metaData);
queueEvent(user, event);
Expand Down

0 comments on commit c56e769

Please sign in to comment.