Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
86 changes: 55 additions & 31 deletions lib/reporting/api_transaction_count_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,26 @@ class ApiTransactionCountReport
attr_reader :time_range

# @param [Range<Time>] time_range
def initialize(time_range:)
@time_range = time_range || previous_week_range
def initialize(
time_range:,
verbose: false,
progress: false,
slice: 6.hours,
threads: 1
)
@time_range = time_range
@verbose = verbose
@progress = progress
@slice = slice
@threads = threads
end

def verbose?
@verbose
end

def progress?
@progress
end

def as_tables
Expand Down Expand Up @@ -55,7 +73,8 @@ def api_transaction_count
'Instant verify',
'Phone Finder',
'Socure (DocV)',
'Socure (KYC)',
'Socure (KYC) - Shadow',
'Socure (KYC) - Non-Shadow',
'Fraud Score and Attribute',
'Threat Metrix',
],
Expand All @@ -65,7 +84,8 @@ def api_transaction_count
instant_verify_table.first,
phone_finder_table.first,
socure_table.first,
socure_kyc_table.first,
socure_kyc_non_shadow_table.first,
socure_kyc_shadow_table.first,
fraud_score_and_attribute_table.first,
threat_metrix_table.first,
],
Expand Down Expand Up @@ -100,8 +120,14 @@ def socure_table
[socure_table_count, result]
end

def socure_kyc_table
result = fetch_results(query: socure_kyc_query)
def socure_kyc_non_shadow_table
result = fetch_results(query: socure_kyc_non_shadow_query)
socure_table_count = result.count
[socure_table_count, result]
end

def socure_kyc_shadow_table
result = fetch_results(query: socure_kyc_shadow_query)
socure_table_count = result.count
[socure_table_count, result]
end
Expand Down Expand Up @@ -147,8 +173,11 @@ def column_labels(row)

def cloudwatch_client
@cloudwatch_client ||= Reporting::CloudwatchClient.new(
progress: false,
ensure_complete_logs: false,
num_threads: @threads,
ensure_complete_logs: true,
slice_interval: @slice,
progress: progress?,
logger: verbose? ? Logger.new(STDERR) : nil,
)
end

Expand Down Expand Up @@ -248,28 +277,13 @@ def instant_verify_query
def threat_metrix_query
<<~QUERY
filter name = "IdV: doc auth verify proofing results"
| fields properties.user_id as uuid, id, @timestamp as timestamp,
properties.sp_request.app_differentiator as dol_state, properties.service_provider as sp,

#OVERALL
properties.event_properties.proofing_results.timed_out as overall_process_timed_out_flag,
properties.event_properties.success as overall_process_success,
properties.event_properties.proofing_components.document_check as document_check_vendor,
properties.event_properties.proofing_results.context.stages.residential_address.vendor_name as address_vendor_name,


#TMX --> threatmetrix
properties.event_properties.proofing_results.context.stages.threatmetrix.review_status as tmx_review_status,
properties.event_properties.proofing_results.context.stages.threatmetrix.session_id as tmx_sessionID,
properties.event_properties.proofing_results.context.stages.threatmetrix.success as tmx_success,
properties.event_properties.proofing_results.context.stages.threatmetrix.timed_out as tmx_timed_out_flag,
properties.event_properties.proofing_results.context.stages.threatmetrix.transaction_id as tmx_transactionID

| display uuid, id, timestamp, sp, dol_state,
overall_process_timed_out_flag,
overall_process_success,
document_check_vendor,
address_vendor_name
| fields
properties.user_id as uuid,
@timestamp as timestamp,
properties.event_properties.proofing_results.context.stages.threatmetrix.success as tmx_success

| stats max(tmx_success) as max_tmx_success by uuid

QUERY
end

Expand All @@ -290,7 +304,7 @@ def fraud_score_and_attribute_query
QUERY
end

def socure_kyc_query
def socure_kyc_shadow_query
<<~QUERY
fields
properties.event_properties.socure_result.success as success,
Expand All @@ -313,6 +327,16 @@ def socure_kyc_query
| stats count(*) as c
QUERY
end

def socure_kyc_non_shadow_query
<<~QUERY
fields @timestamp, @message, @logStream, @log
| filter name='IdV: doc auth verify proofing results'
and properties.event_properties.proofing_results.context.stages.resolution.vendor_name='socure_kyc'
| sort @timestamp desc
| stats count(*) as c
QUERY
end
end
end

Expand Down
19 changes: 11 additions & 8 deletions spec/lib/reporting/api_transaction_count_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
let(:expected_api_transaction_count_table) do
[
['Week', 'True ID', 'Instant verify', 'Phone Finder', 'Socure (DocV)',
'Socure (KYC)', 'Fraud Score and Attribute', 'Threat Metrix'],
'Socure (KYC) - Shadow', 'Socure (KYC) - Non-Shadow',
'Fraud Score and Attribute', 'Threat Metrix'],
["#{time_range.begin.to_date} - #{time_range.end.to_date}", 10, 15, 20, 25, 30, 35, 40],
]
end
Expand All @@ -26,9 +27,10 @@
allow(report).to receive(:instant_verify_table).and_return([15, mock_results])
allow(report).to receive(:phone_finder_table).and_return([20, mock_results])
allow(report).to receive(:socure_table).and_return([25, mock_results])
allow(report).to receive(:socure_kyc_table).and_return([30, mock_results])
allow(report).to receive(:fraud_score_and_attribute_table).and_return([35, mock_results])
allow(report).to receive(:threat_metrix_table).and_return([40, mock_results])
allow(report).to receive(:socure_kyc_non_shadow_table).and_return([30, mock_results])
allow(report).to receive(:socure_kyc_shadow_table).and_return([35, mock_results])
allow(report).to receive(:fraud_score_and_attribute_table).and_return([40, mock_results])
allow(report).to receive(:threat_metrix_table).and_return([45, mock_results])
end

describe '#api_transaction_count' do
Expand All @@ -42,11 +44,12 @@
data_row = table.last

expect(header_row).to eq(
['Week', 'True ID', 'Instant verify', 'Phone Finder', 'Socure (DocV)', 'Socure (KYC)',
['Week', 'True ID', 'Instant verify', 'Phone Finder', 'Socure (DocV)',
'Socure (KYC) - Shadow', 'Socure (KYC) - Non-Shadow',
'Fraud Score and Attribute', 'Threat Metrix'],
)
expect(data_row.first).to eq("#{time_range.begin.to_date} - #{time_range.end.to_date}")
expect(data_row[1..]).to eq([10, 15, 20, 25, 30, 35, 40])
expect(data_row[1..]).to eq([10, 15, 20, 25, 30, 35, 40, 45])
end
end

Expand All @@ -61,8 +64,8 @@
expect(csv).to match(
/
Week,True\ ID,Instant\ verify,Phone\ Finder,
Socure\ \(DocV\), Socure\ \(KYC\), Fraud\ Score\ and\ Attribute,
Threat\ Metrix
Socure\ \(DocV\),Socure\ \(KYC\)\s-\sShadow,Socure\ \(KYC\)\s-\sNon-Shadow,
Fraud\ Score\ and\ Attribute,Threat\ Metrix
/x,
)
expect(csv).to include("#{time_range.begin.to_date} - #{time_range.end.to_date}")
Expand Down