Page MenuHomePhabricator

Log when the lookup fails on attempting to INSERT to actor_data (because the proxy/behaviour doesn't exist)
Closed, DeclinedPublic

Description

Following T344499: Move behaviors/proxies/tunnels processing into an independent script, attempting to INSERT to actor_data can fail because the proxy/behaviour doesn't exist. (This should happen rarely.)

Log the actor data when this happens.

How to respond to these logs will be decided in T344941: Respond to data update and import errors.

QA Results - iPoid

Event Timeline

@Tchanders Dom and I were taking a look at this, and based on the details in the description, we weren't sure if we were doing this correctly or not. If this isn't correct, can you please add some steps to the description? Thanks!

Status: ❌FAIL
Environment: Ipoid: cf65a5b31f14f37e392cf1269bc1f717e4c7c9d0 Fri Oct 20 18:40:03 2023 +0000
OS: macOS Sonoma 14.0
Browser: Chrome 117- Visual Studio Code
Skins. n/a
Device: MBA M2
Emulated Device:: n/a
Test Links: n/a

statement.sql used

INSERT INTO actor_data (ip,org,client_count,types,conc_city,conc_state,conc_country,countries,location_country,risks) VALUES ('6bcaac10-88d8-4e2c-8e98-ae27d8840e26','Foobar',10,16,'Foobar','Foobar','NL',10,'AZ',2);@@@@@INSERT INTO actor_data_behaviors (actor_data_id, behavior_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM behaviors WHERE behavior = 'wizwit') );@@@@@INSERT INTO actor_data_proxies (actor_data_id, proxy_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM proxies WHERE proxy = 'wizwit2' ) );@@@@@INSERT INTO actor_data_tunnels (actor_data_id, tunnel_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM tunnels WHERE operator = 'TUNNELBEAR_VPN' ) );@@@@@

❌AC1: https://phabricator.wikimedia.org/T344939

Steps

  1. In VS, we cd ipoid than ran docker-compose exec web node init-db.js
  2. Listed the folders with docker-compose exec web ls /tmp
  3. Copied the statement.sql into my local tmp folders with docker-compose exec web cp /tmp/statements.sql tmp
  4. Changed the data for behavior and proxy to "wizwit" and "wizwit2" respectively, since they don't exist. The whole data used can be seen above.
  5. Copied it back into the docker tmp folder with docker-compose exec web cp tmp/statements.sql /tmp
  6. Import the file with docker-compose exec web ./import.sh
  7. Got the 'ER_BAD_NULL_ERROR' as seen below

Error

Importing properties generated by diff...
Resetting and generating substatement files...
Importing /tmp/sub/query_split_aa.sql...
{"name":"data-import","hostname":"8607fac2092c","pid":566,"level":50,"err":{"message":"(conn=37, no: 1048, SQLState: 23000) Column 'behavior_id' cannot be null\nsql: INSERT INTO actor_data_behaviors (actor_data_id, behavior_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM behaviors WHERE behavior = 'foobar') ); - parameters:[]","name":"SqlError","stack":"SqlError: (conn=37, no: 1048, SQLState: 23000) Column 'behavior_id' cannot be null\nsql: INSERT INTO actor_data_behaviors (actor_data_id, behavior_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM behaviors WHERE behavior = 'foobar') ); - parameters:[]\n    at Object.module.exports.createError (/srv/service/node_modules/mariadb/lib/misc/errors.js:64:10)\n    at PacketNodeEncoded.readError (/srv/service/node_modules/mariadb/lib/io/packet.js:575:19)\n    at Query.readResponsePacket (/srv/service/node_modules/mariadb/lib/cmd/parser.js:58:28)\n    at PacketInputStream.receivePacketBasic (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:85:9)\n    at PacketInputStream.onData (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:145:26)\n    at Socket.emit (node:events:513:28)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)","code":"ER_BAD_NULL_ERROR"},"yesterdayFile":"","todayFile":"tmp/reprod1.json.gz","batchFile":"/tmp/sub/query_split_aa.sql","statement":"'INSERT INTO actor_data_behaviors (actor_data_id, behavior_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = \\'6bcaac10-88d8-4e2c-8e98-ae27d8840e26\\'), (SELECT pkid FROM behaviors WHERE behavior = \\'foobar\\') );'","msg":"(conn=37, no: 1048, SQLState: 23000) Column 'behavior_id' cannot be null\nsql: INSERT INTO actor_data_behaviors (actor_data_id, behavior_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM behaviors WHERE behavior = 'foobar') ); - parameters:[]","time":"2023-10-24T17:04:33.767Z","v":0}
{"name":"data-import","hostname":"8607fac2092c","pid":566,"level":50,"err":{"message":"(conn=37, no: 1048, SQLState: 23000) Column 'proxy_id' cannot be null\nsql: INSERT INTO actor_data_proxies (actor_data_id, proxy_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM proxies WHERE proxy = 'foobar2' ) ); - parameters:[]","name":"SqlError","stack":"SqlError: (conn=37, no: 1048, SQLState: 23000) Column 'proxy_id' cannot be null\nsql: INSERT INTO actor_data_proxies (actor_data_id, proxy_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM proxies WHERE proxy = 'foobar2' ) ); - parameters:[]\n    at Object.module.exports.createError (/srv/service/node_modules/mariadb/lib/misc/errors.js:64:10)\n    at PacketNodeEncoded.readError (/srv/service/node_modules/mariadb/lib/io/packet.js:575:19)\n    at Query.readResponsePacket (/srv/service/node_modules/mariadb/lib/cmd/parser.js:58:28)\n    at PacketInputStream.receivePacketBasic (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:85:9)\n    at PacketInputStream.onData (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:145:26)\n    at Socket.emit (node:events:513:28)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)","code":"ER_BAD_NULL_ERROR"},"yesterdayFile":"","todayFile":"tmp/reprod1.json.gz","batchFile":"/tmp/sub/query_split_aa.sql","statement":"'INSERT INTO actor_data_proxies (actor_data_id, proxy_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = \\'6bcaac10-88d8-4e2c-8e98-ae27d8840e26\\'), (SELECT pkid FROM proxies WHERE proxy = \\'foobar2\\' ) );'","msg":"(conn=37, no: 1048, SQLState: 23000) Column 'proxy_id' cannot be null\nsql: INSERT INTO actor_data_proxies (actor_data_id, proxy_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM proxies WHERE proxy = 'foobar2' ) ); - parameters:[]","time":"2023-10-24T17:04:33.775Z","v":0}
{"name":"data-import","hostname":"8607fac2092c","pid":566,"level":50,"err":{"message":"(conn=37, no: 1048, SQLState: 23000) Column 'tunnel_id' cannot be null\nsql: INSERT INTO actor_data_tunnels (actor_data_id, tunnel_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM tunnels WHERE operator = 'TUNNELBEAR_VPN' ) ); - parameters:[]","name":"SqlError","stack":"SqlError: (conn=37, no: 1048, SQLState: 23000) Column 'tunnel_id' cannot be null\nsql: INSERT INTO actor_data_tunnels (actor_data_id, tunnel_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM tunnels WHERE operator = 'TUNNELBEAR_VPN' ) ); - parameters:[]\n    at Object.module.exports.createError (/srv/service/node_modules/mariadb/lib/misc/errors.js:64:10)\n    at PacketNodeEncoded.readError (/srv/service/node_modules/mariadb/lib/io/packet.js:575:19)\n    at Query.readResponsePacket (/srv/service/node_modules/mariadb/lib/cmd/parser.js:58:28)\n    at PacketInputStream.receivePacketBasic (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:85:9)\n    at PacketInputStream.onData (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:145:26)\n    at Socket.emit (node:events:513:28)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)","code":"ER_BAD_NULL_ERROR"},"yesterdayFile":"","todayFile":"tmp/reprod1.json.gz","batchFile":"/tmp/sub/query_split_aa.sql","statement":"'INSERT INTO actor_data_tunnels (actor_data_id, tunnel_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = \\'6bcaac10-88d8-4e2c-8e98-ae27d8840e26\\'), (SELECT pkid FROM tunnels WHERE operator = \\'TUNNELBEAR_VPN\\' ) );'","msg":"(conn=37, no: 1048, SQLState: 23000) Column 'tunnel_id' cannot be null\nsql: INSERT INTO actor_data_tunnels (actor_data_id, tunnel_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM tunnels WHERE operator = 'TUNNELBEAR_VPN' ) ); - parameters:[]","time":"2023-10-24T17:04:33.777Z","v":0}
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

SqlError: (conn=37, no: 1048, SQLState: 23000) Column 'behavior_id' cannot be null
sql: INSERT INTO actor_data_behaviors (actor_data_id, behavior_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM behaviors WHERE behavior = 'foobar') ); - parameters:[]
    at Object.module.exports.createError (/srv/service/node_modules/mariadb/lib/misc/errors.js:64:10)
    at PacketNodeEncoded.readError (/srv/service/node_modules/mariadb/lib/io/packet.js:575:19)
    at Query.readResponsePacket (/srv/service/node_modules/mariadb/lib/cmd/parser.js:58:28)
    at PacketInputStream.receivePacketBasic (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:85:9)
    at PacketInputStream.onData (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:145:26)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  sqlMessage: "Column 'behavior_id' cannot be null",
  sql: "INSERT INTO actor_data_behaviors (actor_data_id, behavior_id) VALUES( (SELECT pkid FROM actor_data WHERE ip = '6bcaac10-88d8-4e2c-8e98-ae27d8840e26'), (SELECT pkid FROM behaviors WHERE behavior = 'foobar') ); - parameters:[]",
  fatal: false,
  errno: 1048,
  sqlState: '23000',
  code: 'ER_BAD_NULL_ERROR'
}

@Tchanders as per our conversation, I ran the following steps below.

Steps

  1. To generate files, I ran docker-compose exec web npm run integration
  2. In VS, we cd ipoid then ran docker-compose exec web node init-db.js
  3. Listed the folders with docker-compose exec web ls ./tmp
  4. Import the file with docker-compose exec web ./import.sh
  5. After receiving the Error: Cannot find module './tmp/properties.json'

2023-11-06_10-30-32.png (476×982 px, 90 KB)

  1. I then created a properties.json file in the ./tmp folder with the data below :
{"ip":"185.186.83.70","organization":"TelKos L.L.C","as":{"number":206262,"Organization":"TelKos L.L.C"},"client":{"count":2,"types":["MOBILE"],"behaviors":["FILE_SHARING"],"proxies":["OXYLABS_PROXY"],"concentration":{"geohash":"srwcr5ugt","city":"Shtime","state":"Ferizaj","country":"XK","skew":182,"density":1},"countries":1},"tunnels":[{"type":"PROXY","anonymous":false}],"location":{"country":"AL"},"risks":["CALLBACK_PROXY","GEO_MISMATCH"]}
  1. After saving the file, I ran steps 3 to confirm and steps 4 to execute but got the following below, TypeError: Cannot read properties of undefined (reading 'length').

2023-11-06_10-21-19.png (1×2 px, 249 KB)

Tchanders moved this task from Blocked to Deployment blockers on the iPoid-Service board.

Thanks @GMikesell-WMF .

I was wrong that this specific bug had been fixed, but it's much less of a problem now, because the pipeline should always run get-properties.js before running import.sh. (Hence having to test it outside of the pipeline context.)

I'll move this out of the current sprint, but keep it open and queued.