Skip to content

Commit

Permalink
Merge pull request #3581 from Thushani-Jayasekera/ws-analytics
Browse files Browse the repository at this point in the history
[Choreo] Add analytics for websocket APIs
  • Loading branch information
renuka-fernando authored Sep 11, 2024
2 parents 9353d79 + f019655 commit e8f7a30
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.wso2.choreo.connect.discovery.api.Scopes;
import org.wso2.choreo.connect.discovery.api.SecurityList;
import org.wso2.choreo.connect.discovery.api.SecurityScheme;
import org.wso2.choreo.connect.enforcer.analytics.AnalyticsFilter;
import org.wso2.choreo.connect.enforcer.commons.Filter;
import org.wso2.choreo.connect.enforcer.commons.model.APIConfig;
import org.wso2.choreo.connect.enforcer.commons.model.BackendJWTConfiguration;
Expand All @@ -39,6 +40,7 @@
import org.wso2.choreo.connect.enforcer.security.AuthFilter;
import org.wso2.choreo.connect.enforcer.throttle.ThrottleConstants;
import org.wso2.choreo.connect.enforcer.throttle.ThrottleFilter;
import org.wso2.choreo.connect.enforcer.util.FilterUtils;
import org.wso2.choreo.connect.enforcer.websocket.WebSocketMetaDataFilter;
import org.wso2.choreo.connect.enforcer.websocket.WebSocketThrottleFilter;
import org.wso2.choreo.connect.enforcer.websocket.WebSocketThrottleResponse;
Expand Down Expand Up @@ -165,11 +167,18 @@ public String init(Api api) {
public ResponseObject process(RequestContext requestContext) {
ResponseObject responseObject = new ResponseObject();
responseObject.setRequestPath(requestContext.getRequestPath());
boolean analyticsEnabled = ConfigHolder.getInstance().getConfig().getAnalyticsConfig().isEnabled();

responseObject.setApiUuid(apiConfig.getUuid());

Utils.populateRemoveAndProtectedHeaders(requestContext);

if (executeFilterChain(requestContext)) {

if (analyticsEnabled) {
AnalyticsFilter.getInstance().handleSuccessRequest(requestContext);
}

responseObject.setRemoveHeaderMap(requestContext.getRemoveHeaders());
responseObject.setQueryParamsToRemove(requestContext.getQueryParamsToRemove());
responseObject.setQueryParamMap(requestContext.getQueryParameters());
Expand Down Expand Up @@ -203,6 +212,11 @@ public ResponseObject process(RequestContext requestContext) {
if (requestContext.getAddHeaders() != null && requestContext.getAddHeaders().size() > 0) {
responseObject.setHeaderMap(requestContext.getAddHeaders());
}

if (analyticsEnabled && !FilterUtils.isSkippedAnalyticsFaultEvent(responseObject.getErrorCode())) {
AnalyticsFilter.getInstance().handleFailureRequest(requestContext);
responseObject.setMetaDataMap(new HashMap<>(0));
}
}
return responseObject;
}
Expand Down

0 comments on commit e8f7a30

Please sign in to comment.