Skip to content

Commit

Permalink
chore(CE): add request response log for Airtable
Browse files Browse the repository at this point in the history
  • Loading branch information
TivonB-AI2 committed Aug 12, 2024
1 parent 8222794 commit fbd2c57
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 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.7)
activesupport
async-websocket
aws-sdk-athena
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ def write(sync_config, records, _action = "create")
connection_config = sync_config.destination.connection_specification.with_indifferent_access
api_key = connection_config[:api_key]
url = sync_config.stream.url
log_message_array = []
write_success = 0
write_failure = 0
records.each_slice(MAX_CHUNK_SIZE) do |chunk|
payload = create_payload(chunk)
args = [sync_config.stream.request_method, url, payload]
response = Multiwoven::Integrations::Core::HttpClient.request(
url,
sync_config.stream.request_method,
Expand All @@ -74,6 +76,7 @@ def write(sync_config, records, _action = "create")
else
write_failure += chunk.size
end
log_message_array << log_request_response("info", args, response)
rescue StandardError => e
handle_exception(e, {
context: "AIRTABLE:RECORD:WRITE:EXCEPTION",
Expand All @@ -82,13 +85,9 @@ def write(sync_config, records, _action = "create")
sync_run_id: sync_config.sync_run_id
})
write_failure += chunk.size
log_message_array << log_request_response("error", args, e.message)
end

tracker = Multiwoven::Integrations::Protocol::TrackingMessage.new(
success: write_success,
failed: write_failure
)
tracker.to_multiwoven_message
tracking_message(write_success, write_failure, log_message_array)
rescue StandardError => e
handle_exception(e, {
context: "AIRTABLE:RECORD:WRITE:EXCEPTION",
Expand Down Expand Up @@ -119,7 +118,7 @@ def auth_headers(access_token)
end

def base_id_exists?(bases, base_id)
return if extract_data(bases).any? { |base| base["id"] == base_id }
return if extract_bases(bases).any? { |base| base["id"] == base_id }

raise ArgumentError, "base_id not found"
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.7"

ENABLED_SOURCES = %w[
Snowflake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

it "returns a successful connection status if the request is successful" do
allow(Multiwoven::Integrations::Core::HttpClient).to receive(:request).and_return(success_response)
allow(client).to receive(:extract_data).with(success_response).and_return([{ "id" => "app43WSzJbarW7bTX" }])
allow(client).to receive(:extract_bases).with(success_response).and_return([{ "id" => "app43WSzJbarW7bTX" }])
message = client.check_connection(connection_config)
expect(message).to be_a(Multiwoven::Integrations::Protocol::MultiwovenMessage)
result = message.connection_status
Expand All @@ -88,7 +88,7 @@

it "raises an error if the base idis not found in the response" do
allow(Multiwoven::Integrations::Core::HttpClient).to receive(:request).and_return(success_response)
allow(client).to receive(:extract_data).with(success_response).and_return([{ "id" => "invalid" }])
allow(client).to receive(:extract_bases).with(success_response).and_return([{ "id" => "invalid" }])
message = client.check_connection(connection_config)
expect(message).to be_a(Multiwoven::Integrations::Protocol::MultiwovenMessage)
result = message.connection_status
Expand Down Expand Up @@ -156,6 +156,12 @@
message = client.write(sync_config, records)
expect(message.tracking.success).to eq(2)
expect(message.tracking.failed).to eq(0)
log_message = message.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

it "increments the failure count" do
Expand All @@ -164,6 +170,12 @@
message = client.write(sync_config, records)
expect(message.tracking.success).to eq(0)
expect(message.tracking.failed).to eq(2)
log_message = message.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 Down

0 comments on commit fbd2c57

Please sign in to comment.