From e118654d62690369da428b80070eecf166390324 Mon Sep 17 00:00:00 2001 From: dedenbangkit Date: Thu, 16 May 2024 12:55:37 +0700 Subject: [PATCH] [#1464] Fix curl argument list too long --- .../stress_tests/household_submission.json | 310 +++++++++--------- doc/script/stress_tests/push_submissions.sh | 35 +- 2 files changed, 180 insertions(+), 165 deletions(-) diff --git a/doc/script/stress_tests/household_submission.json b/doc/script/stress_tests/household_submission.json index ed8dbb499..429cea27a 100644 --- a/doc/script/stress_tests/household_submission.json +++ b/doc/script/stress_tests/household_submission.json @@ -1,156 +1,156 @@ { - "id": 1440, - "datapoint_name": "Gaturi - Father - 01", - "administration": 61380, - "uuid": "b0acba11-8064-4cb0-b1f2-59d3797ecae1", - "geolocation": [-7.8360744, 110.3311868], - "submission_type": 1, - "answers": { - "1701810579091": "G1 Functional toilet with privacy", - "1702284734752": "G1 Toilet use by all household members", - "1702281084786": "G1 Flyproof toilet", - "1702282119933": "G1 Clean toilet", - "1711434672": "G1 Use of flyproof and clean toilet", - "1702285101196": "G1 Some household members do not use their own toilet", - "1702283171680": "G2 Durable toilet", - "1702283955461": "G2 Toilet with safe containment", - "1711436502": "G2 Durable toilet with safe containment", - "1702285668136": "G1 Inadequate sanitation services", - "1702287053503": "G1 Handwashing facility with soap and water", - "1702288599133": "G1 Some critical handwashing times NOT mentioned", - "1702287685048": "G3 Permanent handwashing services", - "1702289546185": "G1 No exposed human excreta in compound", - "1702289725502": "G1 Safely managed child excreta and diapers", - "1702295289084": "G2 Clean and safely stored food", - "1702295769122": "G2 Clean and safely stored kitchen utensils", - "1702296110410": "G1 Milk containers not adequately washed, or not safely stored", - "1712643759": "G1", - "1702296406679": "G2 Safe management of drinking water", - "1702296839468": "G2 Safe management of water points", - "1712644066": "G2", - "1702297046194": "G1 Some animal wastes visible", - "1702297533085": "G1 Inadequate management of animal wastes", - "1702297797962": "G1 Inadequate separation of animals from under-5 children", - "1712644167": "G1", - "1702298080560": "G3 Safe management of liquid wastes", - "1702298318702": "G3 Safe management of solid wastes", - "1702298863458": "G3 Good personal hygiene", - "1702298602672": "G3 Good vector control", - "1702302232732": "G3 Good nutrition and protection", - "1712644350": "G3", - "1702301820095": "G3 Good menstrual hygiene", - "1712644557": "G3", - "1702302427536": "G3 Good nutrition and protection", - "1702302041022": "G3 Good nutrition and protection", - "1702302507816": "G3 Good nutrition and protection", - "1712644710": "G3", - "1702299714872": "G3 Malaria-safe home", - "1712657830": "G2", - "1699432887212": ["g2_cleanwashed_produce_raw_and_cooked_food"], - "1699433027913": ["g2_covered_food_storage"], - "1699433058652": ["g2_storage_off_ground"], - "1699433108344": ["g2_cleanwashed_utensils"], - "1699433162828": ["g2_covered_utensil_storage"], - "1699433205793": ["g2_storage_off_ground"], - "1699433455365": ["g2_cleanwashed_water_containers"], - "1699433503692": ["g2_adequate_quality_at_collection_point"], - "1699433564057": ["g2_clean_covered_drinking_water_storage"], - "1699433637971": ["g2_water_containers_with_spigots_or_taps"], - "1699433719018": ["g2_clean_water_points"], - "1699433765217": ["g2_well_protected_water_points"], - "1699433833227": ["g2_no_householf_water_point"], - "1699434438966": ["g3_adequate_wastewater_soakpit_or_drainage"], - "1699434488410": ["g3_adequate_stormwater_drainage"], - "1699434553677": ["g3_clean_compound_with_no_visible_solid_wastes"], - "1699434636655": ["g3_solid_waste_storage_or_disposal_system"], - "1699434771449": ["g3_no_visible_standing_water"], - "1699434939105": ["g3_clean_faces"], - "1699434983278": ["g3_clean_hands"], - "1699435026311": ["g3_clean_and_private_washing_place"], - "1699435088758": ["g3_safe_disposal_site"], - "1699435154797": ["g3_appropriate_materials_are_available"], - "1699435207476": ["g3_all_children_fully_immunized"], - "1699435265962": ["g3_all_vitamin_a_supplements_received_in_last_6_months"], - "1699435329279": ["g3_exclusive_breastfeeding_for_under_6month_children"], - "1699435397728": ["g3_nutritious_diet_for_all_6_month_to_2_year_children"], - "1699435455818": ["g3_malariasafe_home"], - "1699435526190": ["g3_not_in_sthendemic_area"], - "1699354220734": ["new"], - "1699354849382": 61380.0, - "1702914753957": [-7.8360744, 110.3311868], - "1702914803732": "b0acba11-8064-4cb0-b1f2-59d3797ecae1", - "1699417958748": ["hh_head"], - "1699419048095": "Gaturi", - "1699419165632": "Father", - "1699419372643": ["male"], - "1699419815660": 35.0, - "1699419861172": 1.0, - "1699419951523": 0.0, - "1712229529": "1", - "1699419994672": 1.0, - "1699420051321": 0.0, - "1699420070055": 1.0, - "1699420103720": 1.0, - "1699420121397": 0.0, - "1699420137191": 0.0, - "1703265705460": "3", - "1703265879204": "1", - "1712234331": "1", - "1712234349": "4", - "1699420621840": ["other_hh_not_in_atrisk_category"], - "1710829091": ["no_animals_kept_in_household_compound"], - "1703073469466": "01", - "1699422286091": ["g1_toilet_observed"], - "1703066902325": "https://rtmis.akvotest.org/images/photo_1703066902325_1-c46fec21-216d-47f4-92aa-4071f405225e.jpeg", - "1703066989526": "https://rtmis.akvotest.org/images/photo_1703066989526_1-c24fd673-6116-4e26-b805-fdfde89cd936.jpeg", - "1699423357200": ["g1_fully_functional_toilet"], - "1699423571454": ["g1_good_toilet_privacy"], - "1699423696720": ["g1_dry_latrine_with_drophole"], - "1699423946170": ["g1_single_latrine_pit_under_toilet"], - "1699424375968": ["g1_tightfitting_drophole_cover_in_place"], - "1699425852809": [ - "g1_clean_minor_traces_of_faeces_or_soiled_materials_easily_cleaned" - ], - "1699426059842": ["g1_clean_minor_traces_of_faeces_easily_cleaned"], - "1699427405024": ["g2_concrete_slab"], - "1699427743413": ["g2_single_pit_not_yet_full_no_surface_outflows"], - "1702282796765": ["g2_low_risk_of_groundwater_contamination"], - "1699428072669": ["g1_use_own_toilet"], - "1699428400205": ["g1_toilet_notshared_less_than_1015_users"], - "1710742384": 0.0, - "1699428351326": ["g1_all_use_toilet"], - "1699428535663": ["hh_member_1_g2_use_own_toilet_not_shared"], - "1711626271": ["hh_member_1_g2_use_own_toilet_not_shared"], - "1711626326": ["hh_member_1_g2_use_own_toilet_not_shared"], - "1711626360": ["hh_member_1_g2_use_own_toilet_not_shared"], - "1699427574765": ["g2_containment_unlined_in_stable_soil"], - "1699427885744": ["g2_never"], - "1699428661689": ["g3_never_emptied_first_pit_no_intention_to_empty"], - "1699429162796": ["g1_handwashing_facility_by_toilet"], - "1710840898": "https://rtmis.akvotest.org/images/photo_1710840898_1-d400ffe1-334d-4a26-8941-03f2563b32ed.jpeg", - "1710753585": ["g1_fully_functional_handwashing_facility"], - "1699430427692": ["g1_water_available"], - "1699430472221": ["g1_solid_liquid_or_powder_soap_available"], - "1699430580239": [ - "g3_permanent_handwashing_station_with_adequate_water_storage" - ], - "1699430671868": ["g3_closed_water_storage_container_with_tap"], - "1699430761393": ["g3_safe_collection_and_disposal_of_washing_water"], - "1699430839676": ["g2_after_toilet_use"], - "1699431035188": ["g2_before_eating_food_preparation_and_feeding_children"], - "1699431983680": [ - "g2_after_cleaning_or_handling_infant_faeces_or_after_washing_or_disposal_of_diapers" - ], - "1699432663952": [ - "g1_no_visible_od_or_human_excreta_child_or_adult_in_compound" - ], - "1699432130951": ["g1_safely_managed_child_faeces_buried"], - "1699432802923": ["g1_disposable_diaper_buried_in_compound"], - "16994260598422": ["yes"], - "16994260598423": ["yes"], - "1703299101191": "G1 Open Defecation Free", - "1703299101192": "G3 Clean and Healthy", - "1712658383": "G2", - "1715238587": "G0" - } -} \ No newline at end of file + "id": 1440, + "datapoint_name": "Gaturi - Mother - 01", + "administration": 61380, + "uuid": "b0acba11-8064-4cb0-b1f2-59d3797ecae1", + "geolocation": [-7.8360744, 110.3311868], + "submission_type": 1, + "answers": { + "1701810579091": "G1 Functional toilet with privacy", + "1702284734752": "G1 Toilet use by all household members", + "1702281084786": "G1 Flyproof toilet", + "1702282119933": "G1 Clean toilet", + "1711434672": "G1 Use of flyproof and clean toilet", + "1702285101196": "G1 Some household members do not use their own toilet", + "1702283171680": "G2 Durable toilet", + "1702283955461": "G2 Toilet with safe containment", + "1711436502": "G2 Durable toilet with safe containment", + "1702285668136": "G1 Inadequate sanitation services", + "1702287053503": "G1 Handwashing facility with soap and water", + "1702288599133": "G1 Some critical handwashing times NOT mentioned", + "1702287685048": "G3 Permanent handwashing services", + "1702289546185": "G1 No exposed human excreta in compound", + "1702289725502": "G1 Safely managed child excreta and diapers", + "1702295289084": "G2 Clean and safely stored food", + "1702295769122": "G2 Clean and safely stored kitchen utensils", + "1702296110410": "G1 Milk containers not adequately washed, or not safely stored", + "1712643759": "G1", + "1702296406679": "G2 Safe management of drinking water", + "1702296839468": "G2 Safe management of water points", + "1712644066": "G2", + "1702297046194": "G1 Some animal wastes visible", + "1702297533085": "G1 Inadequate management of animal wastes", + "1702297797962": "G1 Inadequate separation of animals from under-5 children", + "1712644167": "G1", + "1702298080560": "G3 Safe management of liquid wastes", + "1702298318702": "G3 Safe management of solid wastes", + "1702298863458": "G3 Good personal hygiene", + "1702298602672": "G3 Good vector control", + "1702302232732": "G3 Good nutrition and protection", + "1712644350": "G3", + "1702301820095": "G3 Good menstrual hygiene", + "1712644557": "G3", + "1702302427536": "G3 Good nutrition and protection", + "1702302041022": "G3 Good nutrition and protection", + "1702302507816": "G3 Good nutrition and protection", + "1712644710": "G3", + "1702299714872": "G3 Malaria-safe home", + "1712657830": "G2", + "1699432887212": ["g2_cleanwashed_produce_raw_and_cooked_food"], + "1699433027913": ["g2_covered_food_storage"], + "1699433058652": ["g2_storage_off_ground"], + "1699433108344": ["g2_cleanwashed_utensils"], + "1699433162828": ["g2_covered_utensil_storage"], + "1699433205793": ["g2_storage_off_ground"], + "1699433455365": ["g2_cleanwashed_water_containers"], + "1699433503692": ["g2_adequate_quality_at_collection_point"], + "1699433564057": ["g2_clean_covered_drinking_water_storage"], + "1699433637971": ["g2_water_containers_with_spigots_or_taps"], + "1699433719018": ["g2_clean_water_points"], + "1699433765217": ["g2_well_protected_water_points"], + "1699433833227": ["g2_no_householf_water_point"], + "1699434438966": ["g3_adequate_wastewater_soakpit_or_drainage"], + "1699434488410": ["g3_adequate_stormwater_drainage"], + "1699434553677": ["g3_clean_compound_with_no_visible_solid_wastes"], + "1699434636655": ["g3_solid_waste_storage_or_disposal_system"], + "1699434771449": ["g3_no_visible_standing_water"], + "1699434939105": ["g3_clean_faces"], + "1699434983278": ["g3_clean_hands"], + "1699435026311": ["g3_clean_and_private_washing_place"], + "1699435088758": ["g3_safe_disposal_site"], + "1699435154797": ["g3_appropriate_materials_are_available"], + "1699435207476": ["g3_all_children_fully_immunized"], + "1699435265962": ["g3_all_vitamin_a_supplements_received_in_last_6_months"], + "1699435329279": ["g3_exclusive_breastfeeding_for_under_6month_children"], + "1699435397728": ["g3_nutritious_diet_for_all_6_month_to_2_year_children"], + "1699435455818": ["g3_malariasafe_home"], + "1699435526190": ["g3_not_in_sthendemic_area"], + "1699354220734": ["new"], + "1699354849382": 61380.0, + "1702914753957": [-7.8360744, 110.3311868], + "1702914803732": "b0acba11-8064-4cb0-b1f2-59d3797ecae1", + "1699417958748": ["hh_head"], + "1699419048095": "Gaturi", + "1699419165632": "Mother", + "1699419372643": ["male"], + "1699419815660": 35.0, + "1699419861172": 1.0, + "1699419951523": 0.0, + "1712229529": "1", + "1699419994672": 1.0, + "1699420051321": 0.0, + "1699420070055": 1.0, + "1699420103720": 1.0, + "1699420121397": 0.0, + "1699420137191": 0.0, + "1703265705460": "3", + "1703265879204": "1", + "1712234331": "1", + "1712234349": "4", + "1699420621840": ["other_hh_not_in_atrisk_category"], + "1710829091": ["no_animals_kept_in_household_compound"], + "1703073469466": "01", + "1699422286091": ["g1_toilet_observed"], + "1703066902325": "https://rtmis.akvotest.org/images/photo_1703066902325_1-c46fec21-216d-47f4-92aa-4071f405225e.jpeg", + "1703066989526": "https://rtmis.akvotest.org/images/photo_1703066989526_1-c24fd673-6116-4e26-b805-fdfde89cd936.jpeg", + "1699423357200": ["g1_fully_functional_toilet"], + "1699423571454": ["g1_good_toilet_privacy"], + "1699423696720": ["g1_dry_latrine_with_drophole"], + "1699423946170": ["g1_single_latrine_pit_under_toilet"], + "1699424375968": ["g1_tightfitting_drophole_cover_in_place"], + "1699425852809": [ + "g1_clean_minor_traces_of_faeces_or_soiled_materials_easily_cleaned" + ], + "1699426059842": ["g1_clean_minor_traces_of_faeces_easily_cleaned"], + "1699427405024": ["g2_concrete_slab"], + "1699427743413": ["g2_single_pit_not_yet_full_no_surface_outflows"], + "1702282796765": ["g2_low_risk_of_groundwater_contamination"], + "1699428072669": ["g1_use_own_toilet"], + "1699428400205": ["g1_toilet_notshared_less_than_1015_users"], + "1710742384": 0.0, + "1699428351326": ["g1_all_use_toilet"], + "1699428535663": ["hh_member_1_g2_use_own_toilet_not_shared"], + "1711626271": ["hh_member_1_g2_use_own_toilet_not_shared"], + "1711626326": ["hh_member_1_g2_use_own_toilet_not_shared"], + "1711626360": ["hh_member_1_g2_use_own_toilet_not_shared"], + "1699427574765": ["g2_containment_unlined_in_stable_soil"], + "1699427885744": ["g2_never"], + "1699428661689": ["g3_never_emptied_first_pit_no_intention_to_empty"], + "1699429162796": ["g1_handwashing_facility_by_toilet"], + "1710840898": "https://rtmis.akvotest.org/images/photo_1710840898_1-d400ffe1-334d-4a26-8941-03f2563b32ed.jpeg", + "1710753585": ["g1_fully_functional_handwashing_facility"], + "1699430427692": ["g1_water_available"], + "1699430472221": ["g1_solid_liquid_or_powder_soap_available"], + "1699430580239": [ + "g3_permanent_handwashing_station_with_adequate_water_storage" + ], + "1699430671868": ["g3_closed_water_storage_container_with_tap"], + "1699430761393": ["g3_safe_collection_and_disposal_of_washing_water"], + "1699430839676": ["g2_after_toilet_use"], + "1699431035188": ["g2_before_eating_food_preparation_and_feeding_children"], + "1699431983680": [ + "g2_after_cleaning_or_handling_infant_faeces_or_after_washing_or_disposal_of_diapers" + ], + "1699432663952": [ + "g1_no_visible_od_or_human_excreta_child_or_adult_in_compound" + ], + "1699432130951": ["g1_safely_managed_child_faeces_buried"], + "1699432802923": ["g1_disposable_diaper_buried_in_compound"], + "16994260598422": ["yes"], + "16994260598423": ["yes"], + "1703299101191": "G1 Open Defecation Free", + "1703299101192": "G3 Clean and Healthy", + "1712658383": "G2", + "1715238587": "G0" + } +} diff --git a/doc/script/stress_tests/push_submissions.sh b/doc/script/stress_tests/push_submissions.sh index 44cf2a8ba..20cc91833 100755 --- a/doc/script/stress_tests/push_submissions.sh +++ b/doc/script/stress_tests/push_submissions.sh @@ -1,24 +1,30 @@ #!/bin/bash -if [ "$#" -ne 1 ]; then - echo "Usage: $0 " +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " exit 1 fi get_auth_token() { + code=$1 curl -s -X 'POST' \ 'https://rtmis.akvotest.org/api/v1/device/auth' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'X-CSRFTOKEN: 8inxCl7WRqWt2enWNQaxpym2N7hN9StDGiccC6YofLz9AC6ORiraiHyuLYYCieTP' \ - -d '{"code": "$1"}' | jq -r '.syncToken' + -d '{"code": "'$code'"}' | jq -r '.syncToken' } URL="https://rtmis.akvotest.org/api/v1/device/sync" -MOBILE_AUTH_TOKEN=$(get_auth_token $1) +MOBILE_AUTH_TOKEN=$(get_auth_token "$1") +# exit if equal to null +if [ "$MOBILE_AUTH_TOKEN" == "null" ]; then + echo "Invalid auth code" + exit 1 +fi SCHEDULE_TIME="now + 1 minute" -touch sync.log LOG_FILE="./sync.log" +touch $LOG_FILE # jq function to generate a random UUID generate_uuid() { @@ -33,14 +39,23 @@ mkdir -p ./tmp # The sync endpoint push_schedule() { - # the payload - DATA=$(jq . "./tmp/$1.json") - echo "curl -s -X 'POST' \ + # the submission payload + DATA=$(<"./tmp/$1.json") + + # Prevent curl argument list too long + TMP_DATA_FILE="./tmp/tmp_$1.json" + echo "$DATA" >"$TMP_DATA_FILE" + + # Create the curl command to get only the status code + CURL_CMD="curl -o /dev/null -s -w \"File:$1.json | Status Code:%{http_code} | Time Total: %{time_total}\n\" -X 'POST' \ '$URL' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer $MOBILE_AUTH_TOKEN' \ - -d '$DATA' >> $LOG_FILE 2>&1; echo -e '\n'" | at "$SCHEDULE_TIME" + --data-binary @$TMP_DATA_FILE >> $LOG_FILE 2>&1; rm $TMP_DATA_FILE" + + # Schedule the curl command using 'at' + echo "$CURL_CMD" | at "$SCHEDULE_TIME" >/dev/null 2>&1 } push_data() { @@ -74,6 +89,6 @@ push_data() { input_file="./household_submission.json" # Repeat 10 times -for i in $(seq 2 10); do +for i in $(seq 2 "$2"); do push_data "$input_file" "$i" done