How to resolve the error "psycopg2.errors.InvalidTextRepresentation" while shipping the data to Automation Analytics?

Solution Verified - Updated -

Environment

  • Red Hat® Ansible Tower <= 3.8.x

Issue

  • awx-manage gather analytics fails to gather data for Insights for Ansible Automation Platform

Resolution

  • Follow the below steps to replace attached (at the bottom of this page) collectors.py file and restart Ansible Tower services.

    1. Move to the correct directory and take the Backup the existing collectors.py file:

    # cd /var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/analytics/
    # cp collectors.py collectors.py.bkp 
    

    2. Copy the modified collectors.py file which is downloaded from this KCS above to the above directory:

    # cp /path/to/collectors.py /var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/analytics/
    

    3. Ensure permissions for this new file match the existing one:

    # chown root:root collectors.py
    # chmod 644 collectors.py
    

    4. Restart Ansible Tower services:

    # ansible-tower-service restart
    

    5. If there is any issues with the Tower service after applying this fix, please revert back to the collectors.py.bkp file by running the following on all cluster nodes:

    # cd /var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/analytics/
    # cp collectors.py.bkp collectors.py
    # ansible-tower-service restart
    

Diagnostic Steps

  • Manually shipping the data from cli throws the following error:

    $ awx-manage gather_analytics --ship
    
    Could not generate metric events_table.csv
    Traceback (most recent call last):
    File "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/main/analytics/collectors.py", line 377, in events_table
    return _copy_table(table='events', query=query("main_jobevent.event_data::jsonb"), path=full_path)
    File "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/main/analytics/collectors.py", line 338, in _copy_table
    cursor.copy_expert(query, file)
    psycopg2.errors.UntranslatableCharacter: unsupported Unicode escape sequence
    DETAIL:  \u0000 cannot be converted to text.
    CONTEXT:  JSON data, line 1: ...Version": null, "Publisher": null, "DisplayName":...
    
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    File "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/main/analytics/core.py", line 268, in gather
    files = func(start, full_path=gather_dir, until=end)
    File "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/main/analytics/collectors.py", line 379, in events_table
    return _copy_table(table='events', query=query("replace(main_jobevent.event_data::text, '\\u0000', '')::jsonb"), path=full_path)
    File "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/main/analytics/collectors.py", line 338, in _copy_table
    cursor.copy_expert(query, file)
    psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type json
    DETAIL:  Token "\" is invalid.
    CONTEXT:  JSON data, line 1: ...ex Pilot/G200e Graphics Driver (remove only)\\",\...
    
    /tmp/4457cd25-4722-4b62-9ae6-ce8068026bbc_2019-10-28-155420+0000.tar.gz
    
    shipping analytics file: /tmp/4457cd25-4722-4b62-9ae6-ce8068026 
    bbc_2019-10-28-155420+0000.tar.gz
    

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments