backend.ai icon indicating copy to clipboard operation
backend.ai copied to clipboard

Piping the output of agent list command only returns up to 20 entries

Open adrysn opened this issue 2 years ago • 0 comments

Describe the bug I tried to get every Agent ID with the CLI command. There were over 30 agents in the server farm and backend.ai admin agent list command just worked well by returning every Agent list with the pagination. However, when I pipe the result with commands like awk or wc -l, I only got 20 entries.

To Reproduce

  1. First, since a test cluster usually does not have >20 Agents, I created 50 fake TERMINTED agents.
    for i in {1..50}; do
        slots='{"cpu": "4", "mem": "34359738368", "cuda.shares": "0"}'
        fields='"id", status, region, scaling_group, available_slots, occupied_slots, addr, version, compute_plugins, architecture'
        values="'i-test-${i}', 'TERMINATED', 'local', 'default', '${slots}'::jsonb, '${slots}'::jsonb, 'tcp://1.2.3.4:6001', '22.09.0b4', '{}'::jsonb, 'x86_64'"
        insert_query="INSERT INTO agents ($fields) VALUES ($values);"
        echo $insert_query
        # Use your own DB's container name or ID.
        docker exec -it main_backendai-half-db_1 psql -U postgres -d backend -c "$insert_query"
    done
    
  2. Confirm that backend.ai admin agent list -s TERMINATED command returns >=50 Agents (including the real ones). image
  3. Now, pipe the result with any command. For example, I used awk to get the Agent's IDs only: backend.ai admin agent list -s TERMINATED | awk '{print $1}'. Then, I got just 20 Agent IDs: image
  4. wc -l command confirms again (2 for header rows): image

Expected behavior Piping the output of the Agent list command should return every item.

Client:

  • OS: CentOS 7.9
  • Python version: 3.10.5

Server:

  • OS: CentOS 7.9
    • Output of uname -snrmpio: Linux asto1 3.10.0-1160.21.1.el7.x86_64 x86_64 x86_64 x86_64 GNU/Linux
  • Backend.AI version: 22.09.0b4
  • Python version: 3.10.5
  • Installation method: on-premise

Additional context Other commands like session list also shows the same issue: image

If you want to delete the test Agents, just execute the script:

for i in {1..50}; do
    delete_query="DELETE FROM agents WHERE \"id\" = 'i-test-${i}';"
    echo $delete_query
    # Use your own DB's container name or ID.
    docker exec -it main_backendai-half-db_1 psql -U postgres -d backend -c "$delete_query"
done

adrysn avatar Aug 22 '22 15:08 adrysn