Source maps are not being removed

ELK stack version: 8.5.2

Describe the bug
I was testing the RUM agent and I realized that some of the source maps that I uploaded are incorrect. To mitigate this, I wrote a Python script that removes all source maps that belong to my app. However, none of them are actually being removed. Even though I get responses with status code 200.

To Reproduce
Steps to reproduce the behavior:

  1. Use this script (or test the DELETE endpoint yourself) and set the missing variables (URL, API_KEY, APP_NAME):
import requests

AUTH_HEADER = f"ApiKey {API_KEY}"

def get_source_maps():
    return requests.get(f"{URL}/api/apm/sourcemaps", headers={
        "kbn-xsrf": "true",
        "Authorization": AUTH_HEADER,
    }).json()['artifacts']

def remove_source_maps():
    for source_map in get_source_maps():
        source_map_id = source_map['id']
        if APP_NAME not in source_map_id:
            continue
        
        r = requests.delete(f"{URL}/api/apm/sourcemaps/${source_map_id}", headers={
            "Authorization": AUTH_HEADER,
            "kbn-xsrf": "true",
            "Content-Type": "application/json"
        })

        print(r, source_map_id)

remove_source_maps()

  1. Upload some source maps
  2. Run it
  3. Notice that you get responses with status code 200
  4. Run it again and it will still find the source maps that you tried to remove

Expected behavior
Source maps should actually be deleted.

Actual behavior

Run it again and it says that it worked, but really it did not.

It is worth noting that every 'source_map_id' would result in a status code 200 response. I do not expect a delete request with an invalid source map identifier to result in an OK response.

Hi @Casper_Aangeenbrug,

Thanks for reaching out!

  1. You should remove the $ next to the {source_map_id}
  2. Make sure the source_map_id doesn't contain blank spaces.
import requests

AUTH_HEADER = f"YOURKEY"
URL = f"http://YOURURL:5601"
APP_NAME = f"YOURAPPNAME"  # in my case I used Apm Rum Test-0.1.0

def get_source_maps():
    return requests.get(f"{URL}/api/apm/sourcemaps", headers={
        "kbn-xsrf": "true",
        "Authorization": AUTH_HEADER,
    }).json()['artifacts']

def remove_source_maps():
    for source_map in get_source_maps():
        source_map_id = source_map['id']
        if APP_NAME not in source_map_id:
            continue
        formatted_source_map_id = source_map_id.replace(" ", "%20")
        r = requests.delete(f"{URL}/api/apm/sourcemaps/{formatted_source_map_id}", headers={
            "Authorization": AUTH_HEADER,
            "kbn-xsrf": "true",
            "Content-Type": "application/json"
        })

        print(r, f"{URL}/api/apm/sourcemaps/{formatted_source_map_id}")

remove_source_maps()

Cheers,
Alberto

1 Like

Thanks! I guess that I have been programming a bit too much TypeScript lately (${variable}).

The only thing that is still bugging me is that the status code of the response is a bit off. Invalid input should not result in a response with status code 200, but rather with 'Not found' (404) IMO.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.