1

I used to following instructions from https://learn.microsoft.com/en-us/rest/api/application-insights/components/purge, but now it produces the following error:

Purge operation on a workspace-based Application Insights resource is not supported. Instead, please run purge operation directly on the workspace, scoped to specific resource id. See more at https://aka.ms/purgeai"

OK, so https://aka.ms/purgeai are the new instructions, but it does not explain how to "scope the operation to the specific resource id", because the records are still in an AI bucket, not the workspace.

So, how do I purge from AI in the new world?

EDIT 1

I should have been more clear. I do not want to purge all the records. For example, consider the following purge request body, which was enough in the past:

{
    "table": "customEvents",
    "filters": [
        {
            "column": "customMeasurements",
            "key": "seq",
            "operator": "==",
            "value": "''"
        }
    ]
}

It could be used to purge all the records with customMeasurements.seq being empty. Now how do I compose it with the _ResourceId field?

When giving the following request body:

{
    "table": "customEvents",
    "filters": [
        {
            "column": "customMeasurements",
            "key": "seq",
            "operator": "==",
            "value": "''"
        },
        {
            "column": "_ResourceId",
            "operator": "==",
            "value": "/subscriptions/.../resourcegroups/.../providers/microsoft.insights/components/..."
        }
    ]
}

The request fails with:

{
  "error": {
    "message": "The request had some invalid properties",
    "code": "BadArgumentError",
    "correlationId": "...",
    "innererror": {
      "code": "QueryValidationError",
      "message": "'customEvents' is not a valid table"
    }
  }
}

EDIT 2

There is still a problem. Indeed, consider the following query:

AppEvents 
| where Measurements.seq == '' and _ResourceId == '/subscriptions/d...8/resourcegroups/app508-re-mark-test/providers/microsoft.insights/components/app508-re-mark-test-ai'
| summarize count()

This query works and return some count.

Now I want to use the same condition to purge records in the same workspace:

{
    "table": "AppEvents",
    "filters": [
        {
            "column": "Measurements",
            "key": "seq",
            "operator": "==",
            "value": "''"
        },
        {
            "column": "_ResourceId",
            "operator": "==",
            "value": "/subscriptions/d...8/resourcegroups/app508-re-mark-test/providers/microsoft.insights/components/app508-re-mark-test-ai"
        }
    ]
}

But I get back the following error:

{
  "error": {
    "message": "The request had some invalid properties",
    "code": "BadArgumentError",
    "correlationId": "c08bb441-a316-4989-a527-202a101e515d",
    "innererror": {
      "code": "QueryValidationError",
      "message": "Unsupported column '_ResourceId'"
    }
  }
}

Note, that omitting the _ResourceId works, but I do want to be able to use it.

What am I missing?

mark
  • 59,016
  • 79
  • 296
  • 580
  • I think on top of @Shemer suggestion, the table names are different in Workspace (there is internal backcompat layer which allows queries to continue to work). I think that table is called with AppEvents or AppCustomEvents (you can open your workspace and check the actual name). – ZakiMa May 03 '22 at 01:54

1 Answers1

2

Thank you for your question, and feedback.
What you will need to do, is to filter by the specific resource id, in addition to any other required filter.

Ex:

`{
  "column": "_ResourceId",
  "operator": "==",
  "value": “/subscriptions/12341234-1234-1234-1234-123412341234/resourceGroups/SomeResourceGroup/providers/microsoft.insights/components/AppInsightResource”
}`

Please note, The table names have changed between the Classic Applicaiton insights, and the workspace-based Application insights. For example, in your case the table name should be AppEvents instead of customEvents. You can review this link for other table names changes.

We will also modify the articles to reflect this information.

Shemer
  • 51
  • 4