# How to define delete phase of apm server policies

**URL:** <https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242>\
**Category:** APM\
**Tags:** ilm-index-lifecycle-management, server\
**Created:** [June 5, 2023, 3:53pm UTC](https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242 "2023-06-05T15:53:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kay\_Khan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kay_khan/32/45028_2.png) [@Kay\_Khan](https://discuss.elastic.co/u/Kay_Khan)\
**Post date:** [June 5, 2023, 3:53pm UTC](https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242/1 "2023-06-05T15:53:23Z")

</div>

Hi friends

I would like to remove the delete phases of every apm ilm policy or at the very least set it to delete in 3 years. Right now we can't seem to get it working at all.

Aside: Can i apply the setting globally across all of APM's created lifecycle policies. If not is there some list of policies somwhere?

Here is my current attempt.

```auto
apiVersion: apm.k8s.elastic.co/v1
kind: ApmServer
metadata:
  name: apm-server-prod
  namespace: elastic-system
spec:
  version: 8.7.1
  count: 1
  elasticsearchRef:
    name: "elasticsearch-prod"
  kibanaRef:
    name: "kibana-prod"
  http:
    service:
      spec:
        type: NodePort
  podTemplate:
    spec:
      containers:
      - name: apm-server
  config:
    http.enabled: true
    http.port: 5068
    monitoring.enabled: false
    setup.template.settings:
      index:
        routing.allocation.require.type: "monitoring"
        anonymous:
          rate_limit:
            event_limit: 300
            ip_limit: 1000
          allow_service: ["admin-dashboard", "frontend"]
    apm-server.rum.enabled: true
    apm-server.rum.allow_origins: ["*"]
    apm-server:
      template.settings:
        index:
          routing.allocation.require.type: "monitoring"
      ilm:
        enabled: "auto"
        setup:
          enabled: true
          overwrite: true
          require_policy: true
          policies:
            - name: "traces-apm.rum_traces-default_policy"
              policy:
                phases:
                  hot:
                    actions:
                      rollover:
                        max_size: "50gb"
                        max_age: "30d"
                      set_priority:
                        priority: 100
                  delete:
                    min_age: "1095d"
                    actions:
                      delete: {}

```

**GET \_ilm/policy/traces-apm.rum\_traces-default\_policy**  
But you can see nothing has changed.

```auto
{
  "traces-apm.rum_traces-default_policy": {
    "version": 1,
    "modified_date": "2023-06-05T14:19:02.806Z",
    "policy": {
      "phases": {
        "hot": {
          "min_age": "0ms",
          "actions": {
            "rollover": {
              "max_size": "50gb",
              "max_age": "30d"
            },
            "set_priority": {
              "priority": 100
            }
          }
        },
        "delete": {
          "min_age": "90d",
          "actions": {
            "delete": {
              "delete_searchable_snapshot": true
            }
          }
        }
      },
      "_meta": {
        "package": {
          "name": "apm"
        },
        "managed_by": "fleet",
        "managed": true
      }
    },
    "in_use_by": {
      "indices": [],
      "data_streams": [],
      "composable_templates": [
        "traces-apm.rum"
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![simitt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simitt/32/106406_2.png) [@simitt](https://discuss.elastic.co/u/simitt)\
**Post date:** [June 6, 2023, 5:45am UTC](https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242/2 "2023-06-06T05:45:05Z")

</div>

Hi @Kay_Khan  
you can follow this [guide for configuring custom ILM policies](https://www.elastic.co/guide/en/apm/guide/current/ilm-how-to.html#data-streams-custom-policy). You could configure one policy and then link it from multiple `@custom` component templates, if they are supposed have the same retention period.

The docs for [default policies](https://www.elastic.co/guide/en/apm/guide/current/ilm-how-to.html#index-lifecycle-policies-default) are currently not up-to-date. I created an [issue](https://github.com/elastic/apm-server/issues/10936) for us to update the docs, you can take a look the details from the issue to get informed about the data streams.  
You could alternatively also query all the @custom component templates from Elasticsearch (`traces-apm*`, `logs-apm*`, `metrics-apm*`).

---

<div class="post-metadata">

**Author:** ![Kay\_Khan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kay_khan/32/45028_2.png) [@Kay\_Khan](https://discuss.elastic.co/u/Kay_Khan)\
**Post date:** [June 6, 2023, 7:56am UTC](https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242/3 "2023-06-06T07:56:17Z")

</div>

Ok if i understand correctly the correct way to modify the policies for apm is to;

1. Create a new ILM policy with the desired configuration
2. Update the @custom component template so that it is using this new ILM policy
3. roll over the datastream.

How much of this can we define via yaml? and where should we define this

There was some documentation at one point where you could define `apm-server.ilm` ([Configure Index lifecycle management (ILM) | APM User Guide [7.17] | Elastic](https://www.elastic.co/guide/en/apm/guide/7.17/ilm-reference.html)) but this does not seem to work in 8.x

---

<div class="post-metadata">

**Author:** ![simitt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simitt/32/106406_2.png) [@simitt](https://discuss.elastic.co/u/simitt)\
**Post date:** [June 6, 2023, 3:58pm UTC](https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242/4 "2023-06-06T15:58:42Z")

</div>

Yes these are the required steps. Configuring the ilm policies via kibana config is not supported. But you can leverage the [ES API to update the component template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-component-template.html#indices-component-template) with the custom settings.

> There was some documentation at one point where you could define `apm-server.ilm` ([Configure Index lifecycle management (ILM) | APM User Guide [7.17] | Elastic](https://www.elastic.co/guide/en/apm/guide/7.17/ilm-reference.html)) but this does not seem to work in 8.x

Exactly, the apm asset setup (index templates, component templates, ILM policies, etc.) moved to Kibana from `8.0` onwards. Having multiple apm-servers with conflicting index setup configurations has caused problems in the past, therefore the setup is now centralized. This means it is not configurable anymore via `apm-server.yml`.

---

<div class="post-metadata">

**Author:** ![Kay\_Khan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kay_khan/32/45028_2.png) [@Kay\_Khan](https://discuss.elastic.co/u/Kay_Khan)\
**Post date:** [June 7, 2023, 7:39am UTC](https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242/5 "2023-06-07T07:39:45Z")

</div>

Okay thanks for confirming its no longer possible to codify these changes in our apm-server.yaml.

We have been following a standard when installing any elastic component and its a shame that we can't do this when it comes to the apm-server.

e.g filebeat and metricbeat look similar.

```auto
...
    setup.ilm:
      enabled: true
      policy_name: metricbeat-custom
      policy_file: /etc/indice-lifecycle.json
      overwrite: true

```

* * *

We understand and makes sense to centralise the creation of these resources, although we hope that you would take into consideration of allowing users to modify the @custom life cycle policy and for that to be the default ilm policy for all apm components via some .yaml configuration, so that we can codify the changes.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2023, 7:40am UTC](https://discuss.elastic.co/t/how-to-define-delete-phase-of-apm-server-policies/335242/6 "2023-07-05T07:40:19Z")

</div>

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