Skip to content
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

Publish STATUS_MESSAGE & add GetInvocationData siddhi app #5

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class CDSErrorHandler implements OpenBankingGatewayExecutor {

private static Log log = LogFactory.getLog(CDSErrorHandler.class);
private static final String STATUS_CODE = "statusCode";
private static final String STATUS_MESSAGE = "statusMessage";
private static final String RESPONSE_PAYLOAD_SIZE = "responsePayloadSize";
public static final String X_FAPI_INTERACTION_ID = "x-fapi-interaction-id";

Expand Down Expand Up @@ -110,9 +111,11 @@ protected void handleRequestError(OBAPIRequestContext obapiRequestContext) {

ArrayList<OpenBankingExecutorError> errors = obapiRequestContext.getErrors();
HashSet<String> statusCodes = new HashSet<>();
HashMap<String, String> statusMessages = new HashMap<>();

for (OpenBankingExecutorError error : errors) {
statusCodes.add(error.getHttpStatusCode());
statusMessages.put(error.getHttpStatusCode(), error.getCode());
}

// handle DCR and Unauthorized errors according to oAuth2 format
Expand Down Expand Up @@ -161,6 +164,11 @@ protected void handleRequestError(OBAPIRequestContext obapiRequestContext) {
// Add error data to analytics map
Map<String, Object> analyticsData = obapiRequestContext.getAnalyticsData();
analyticsData.put(STATUS_CODE, statusCode);

String statusMessage = statusMessages.get(String.valueOf(statusCode));
if (statusMessage != null) {
analyticsData.put(STATUS_MESSAGE, statusMessage);
}
analyticsData.put(RESPONSE_PAYLOAD_SIZE, (long) obapiRequestContext.getModifiedPayload().length());
obapiRequestContext.setAnalyticsData(analyticsData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
CLIENT_ID string,
USER_AGENT string,
STATUS_CODE int,
STATUS_MESSAGE string,
HTTP_METHOD string,
RESPONSE_PAYLOAD_SIZE long,
ELECTED_RESOURCE string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,36 +641,40 @@ priority=6
required=true
type="int"
[[open_banking.data_publishing.thrift.stream.attributes]]
name="httpMethod"
name="statusMessage"
priority=7
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="responsePayloadSize"
name="httpMethod"
priority=8
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="responsePayloadSize"
priority=9
required=true
type="long"
[[open_banking.data_publishing.thrift.stream.attributes]]
name="electedResource"
priority=9
priority=10
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="apiName"
priority=10
priority=11
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="apiSpecVersion"
priority=11
priority=12
[[open_banking.data_publishing.thrift.stream.attributes]]
name="timestamp"
priority=12
priority=13
required=true
type="long"
[[open_banking.data_publishing.thrift.stream.attributes]]
name="customerStatus"
priority=13
priority=14
[[open_banking.data_publishing.thrift.stream.attributes]]
name="accessTokenID"
priority=14
priority=15

[[open_banking.data_publishing.thrift.stream]]
name="APILatencyInputStream"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@source(type='wso2event', @map(type='wso2event'))
define stream APIInputStream(MESSAGE_ID string, CONSENT_ID string, CONSUMER_ID string, CLIENT_ID string,
USER_AGENT string, STATUS_CODE int, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long,
USER_AGENT string, STATUS_CODE int, STATUS_MESSAGE string, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long,
ELECTED_RESOURCE string, API_NAME string, API_SPEC_VERSION string, TIMESTAMP long,
CUSTOMER_STATUS string, ACCESS_TOKEN_ID string);

Expand All @@ -32,7 +32,7 @@ define stream CDSMetricsRawStream(id string, statusCode int, respTime long, elec
@store(type='rdbms', datasource='OB_REPORTING_DB')
@Index('TIMESTAMP')
define table API_INVOCATION_RAW_DATA(ID string, MESSAGE_ID string, CONSENT_ID string, CONSUMER_ID string,
CLIENT_ID string, USER_AGENT string, STATUS_CODE int, HTTP_METHOD string,
CLIENT_ID string, USER_AGENT string, STATUS_CODE int, STATUS_MESSAGE string, HTTP_METHOD string,
RESPONSE_PAYLOAD_SIZE long, ELECTED_RESOURCE string, API_NAME string, API_SPEC_VERSION string,
TIMESTAMP long, CUSTOMER_STATUS string, ACCESS_TOKEN_ID string, SESSION_TYPE string);

Expand All @@ -42,13 +42,13 @@ define table API_LATENCY_RAW_DATA(ID string, MESSAGE_ID string, REQUEST_TIMESTAM
REQUEST_MEDIATION_LATENCY long, RESPONSE_LATENCY long, RESPONSE_MEDIATION_LATENCY long);

define window APIInputStreamDelayWindow(MESSAGE_ID string, CONSENT_ID string, CONSUMER_ID string, CLIENT_ID string,
USER_AGENT string, STATUS_CODE int, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long,
USER_AGENT string, STATUS_CODE int, STATUS_MESSAGE string, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long,
ELECTED_RESOURCE string, API_NAME string, API_SPEC_VERSION string, TIMESTAMP long,
CUSTOMER_STATUS string, ACCESS_TOKEN_ID string) delay(1sec);

--Persist API Invocation Data
from APIInputStream
select UUID() as ID, MESSAGE_ID, CONSENT_ID, CONSUMER_ID, CLIENT_ID, USER_AGENT, STATUS_CODE, HTTP_METHOD,
select UUID() as ID, MESSAGE_ID, CONSENT_ID, CONSUMER_ID, CLIENT_ID, USER_AGENT, STATUS_CODE, STATUS_MESSAGE, HTTP_METHOD,
RESPONSE_PAYLOAD_SIZE, ELECTED_RESOURCE, API_NAME, API_SPEC_VERSION, TIMESTAMP, CUSTOMER_STATUS,
ACCESS_TOKEN_ID, ifThenElse(CUSTOMER_STATUS == 'customer-present', 'attended', 'unattended') as
SESSION_TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ define function getAspect[JavaScript] return string {
@store(type='rdbms', datasource='OB_REPORTING_DB')
@Index('TIMESTAMP')
define table API_INVOCATION_RAW_DATA(ID string, MESSAGE_ID string, CONSENT_ID string, CONSUMER_ID string,
CLIENT_ID string, USER_AGENT string, STATUS_CODE int, HTTP_METHOD string,
CLIENT_ID string, USER_AGENT string, STATUS_CODE int, STATUS_MESSAGE string, HTTP_METHOD string,
RESPONSE_PAYLOAD_SIZE long, ELECTED_RESOURCE string, API_NAME string, API_SPEC_VERSION string,
TIMESTAMP long, CUSTOMER_STATUS string, ACCESS_TOKEN_ID string, SESSION_TYPE string);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@source(type='wso2event', @map(type='wso2event'))
define stream APIInputStream(MESSAGE_ID string, CONSENT_ID string, CONSUMER_ID string, CLIENT_ID string,
USER_AGENT string, STATUS_CODE int, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long,
USER_AGENT string, STATUS_CODE int, STATUS_MESSAGE string, HTTP_METHOD string, RESPONSE_PAYLOAD_SIZE long,
ELECTED_RESOURCE string, API_NAME string, API_SPEC_VERSION string, TIMESTAMP long,
CUSTOMER_STATUS string, ACCESS_TOKEN_ID string);

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -599,37 +599,41 @@ priority=6
required=true
type="int"
[[open_banking.data_publishing.thrift.stream.attributes]]
name="httpMethod"
name="statusMessage"
priority=7
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="responsePayloadSize"
name="httpMethod"
priority=8
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="responsePayloadSize"
priority=9
required=true
type="long"
[[open_banking.data_publishing.thrift.stream.attributes]]
name="electedResource"
priority=9
priority=10
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="apiName"
priority=10
priority=11
required=true
[[open_banking.data_publishing.thrift.stream.attributes]]
name="apiSpecVersion"
priority=11
priority=12
required=false
[[open_banking.data_publishing.thrift.stream.attributes]]
name="timestamp"
priority=12
priority=13
required=true
type="long"
[[open_banking.data_publishing.thrift.stream.attributes]]
name="customerStatus"
priority=13
priority=14
[[open_banking.data_publishing.thrift.stream.attributes]]
name="accessTokenID"
priority=14
priority=15

[[open_banking.data_publishing.thrift.stream]]
name="AccessTokenInputStream"
Expand Down