Skip to content

Commit

Permalink
chore(CE): add request response log for Zendesk
Browse files Browse the repository at this point in the history
  • Loading branch information
TivonB-AI2 committed Aug 12, 2024
1 parent 8222794 commit ac81d9b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion integrations/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
multiwoven-integrations (0.7.1)
multiwoven-integrations (0.7.6)
activesupport
async-websocket
aws-sdk-athena
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,24 @@ def authenticate_client
end

def process_records(records, stream)
log_message_array = []
write_success = 0
write_failure = 0

records.each do |record|
zendesk_data = prepare_record_data(record, stream.name)
plural_stream_name = pluralize_stream_name(stream.name.downcase)
args = [plural_stream_name, @action, zendesk_data]

if @action == "create"
@client.send(plural_stream_name).create!(zendesk_data)
response = @client.send(plural_stream_name).create!(zendesk_data)
else
existing_record = @client.send(plural_stream_name).find(id: record[:id])
existing_record.update!(zendesk_data)
response = existing_record.update!(zendesk_data)
end

write_success += 1
log_message_array << log_request_response("info", args, response)
rescue StandardError => e
handle_exception(e, {
context: "ZENDESK:WRITE:EXCEPTION",
Expand All @@ -87,9 +90,9 @@ def process_records(records, stream)
sync_run_id: @sync_config.sync_run_id
})
write_failure += 1
log_message_array << log_request_response("error", args, e.message)
end

tracking_message(write_success, write_failure)
tracking_message(write_success, write_failure, log_message_array)
end

def pluralize_stream_name(name)
Expand Down Expand Up @@ -122,12 +125,6 @@ def prepare_record_data(record, type)
def load_catalog
read_json(CATALOG_SPEC_PATH)
end

def tracking_message(success, failure)
Multiwoven::Integrations::Protocol::TrackingMessage.new(
success: success, failed: failure
).to_multiwoven_message
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion integrations/lib/multiwoven/integrations/rollout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Multiwoven
module Integrations
VERSION = "0.7.1"
VERSION = "0.7.6"

ENABLED_SOURCES = %w[
Snowflake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
result = client.write(sync_config, records)
expect(result.tracking.success).to eq(records.size)
expect(result.tracking.failed).to eq(0)
log_message = result.tracking.logs.first
expect(log_message).to be_a(Multiwoven::Integrations::Protocol::LogMessage)
expect(log_message.level).to eql("info")

expect(log_message.message).to include("request")
expect(log_message.message).to include("response")
end
end

Expand All @@ -172,6 +178,12 @@
result = client.write(sync_config, records)
expect(result.tracking.success).to eq(0)
expect(result.tracking.failed).to eq(records.size)
log_message = result.tracking.logs.first
expect(log_message).to be_a(Multiwoven::Integrations::Protocol::LogMessage)
expect(log_message.level).to eql("error")

expect(log_message.message).to include("request")
expect(log_message.message).to include("response")
end
end
end
Expand Down

0 comments on commit ac81d9b

Please sign in to comment.