Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redo input/response encoding for easy parsing #408

Merged
merged 1 commit into from
Apr 15, 2023

Conversation

fenollp
Copy link
Contributor

@fenollp fenollp commented Mar 28, 2023

cc #247
cc #322

EDIT:
This enables us to chain ghz calls and thus set up load testing scenarios.
Here's an example usage:

req_books=$(mktemp)
rep_books=$(mktemp)
req_gets=$(mktemp)
rep_gets=$(mktemp)

# Book
P "Booking $TOTAL IPs..."
source="$(printf '{"privateNetworkId":"%s"}' "$PRIVATE_NETWORK_ID")"

jq \
    --arg PROJECT_ID "$PROJECT_ID" \
    --argjson tags "$TAGS" \
    --argjson TOTAL "$TOTAL" \
    --argjson source "$source" \
    -nR '[range($TOTAL) | {projectId:$PROJECT_ID, tags:$tags, source:$source, resource:{id:input, type:"instance_server"}}]' \
    < <(for ((i=0; i<TOTAL; i++)); do uuidgen ; done) \
    >"$req_books"

DEBUG="$rep_books" RPS=10 load \
    --proto api.proto \
    --call v1.Api.BookIP \
    --data-file "$req_books"


# Get
cat "$rep_books" | jq -r .response | jq 'select(. != null) | {ip_id:.id}' | jq -s . >"$req_gets"
booked_ips=$(grep -Fc '"ip_id":' "$req_gets")
P "Getting $booked_ips IPs..."

DEBUG="$rep_gets" TOTAL="$booked_ips" load \
    --proto api.proto \
    --call v1.Api.GetIP \
    --data-file "$req_gets"

where load is a wrapper around ghz

load() {
    local args=()

    if [[ "$DEBUG" != '' ]]; then
        args+=(--debug "$DEBUG")
    fi

    args+=(--total "$TOTAL")
    args+=(--rps "$RPS")
    args+=(--cacert "$(dirname "$0")"/../api.pem)
    args+=(--import-paths "$PROTOBUF_DIR")
    args+=(--disable-template-functions)
    args+=(--disable-template-data)
    args+=(--output /dev/stderr)

    if ! [[ "$*" =~ .*' --metadata '.* ]]; then
        args+=(--metadata "{\"x-auth-token\":\"$TOKEN\", \"x-region\":\"$REGION\"}")
    fi

    args+=("$@")

    args+=(api.example.com:443)

    ghz "${args[@]}"

    if [[ -s "$DEBUG" ]]; then
        # Print requests and their responses to STDERR if any
        cat "$DEBUG" | jq 'select(.input | . != null) | select(.error | . != null)' | jq -S --tab '. | {error:.error, req:.input, rep:.response}' 1>&2
    fi
}

@fenollp
Copy link
Contributor Author

fenollp commented Apr 13, 2023

Hello @bojand ! Could you review this? We'd love to see this under a new tag! Thanks

@bojand bojand merged commit 0aabbc9 into bojand:master Apr 15, 2023
@fenollp fenollp deleted the encode-usefully branch April 15, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants