Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Remove legacy component templates on package install #130758

Conversation

hop-dev
Copy link
Contributor

@hop-dev hop-dev commented Apr 20, 2022

Summary

Closes #129662

Remove any legacy @mappings or @settings component templates during package install. Only delete if:

  • they are not used by any index templates ( e.g if (for some reason :D ) the user has created an index template referring to the fleet component templates)
  • _meta.package.name matches the package being installed (incase the user has created their own version, or another package had created the component template, not likely but I put the check there just in case)

Background

In #121184 we introduced the @package component template which is a combination of @mappings and @settings.

In #129662 @nchaulet noticed that when installing a package in 8.2 which was previously installed in a lower version, we failed to clean up the legacy @mapping component templates
When
When installing a package, check to see if there are any legacy templates

Testing

I've added unit and functional tests.

Manual test steps:

Expand for Kibana Dev Tools Commands for Manual Testing
# create legacy mappings component template
PUT _component_template/logs-apm.app@mappings
{
  "template": {
    "mappings": {
      "dynamic": false,
      "dynamic_templates": [
        {
          "numeric_labels": {
            "path_match": "numeric_labels.*",
            "mapping": {
              "scaling_factor": 1000000,
              "type": "scaled_float"
            }
          }
        }
      ]
    }
  },
  "_meta": {
    "package": {
      "name": "apm"
    }
  }
}

# create legacy settings component template
PUT _component_template/logs-apm.app@settings
{
  "template": {
    "settings": {
      "index": {
        "lifecycle": {
          "name": "logs-apm.app_logs-default_policy"
        },
        "codec": "best_compression",
        "mapping": {
          "total_fields": {
            "limit": "10000"
          }
        },
        "query": {
          "default_field": [
            "agent.ephemeral_id",
            "agent.name",
            "agent.version",
            "client.domain",
            "client.geo.city_name",
            "client.geo.continent_name",
            "client.geo.country_iso_code",
            "client.geo.country_name",
            "client.geo.region_iso_code",
            "client.geo.region_name",
            "cloud.account.id",
            "cloud.account.name",
            "cloud.availability_zone",
            "cloud.instance.id",
            "cloud.instance.name",
            "cloud.machine.type",
            "cloud.project.id",
            "cloud.project.name",
            "cloud.provider",
            "cloud.region",
            "cloud.service.name",
            "container.id",
            "destination.address",
            "ecs.version",
            "event.outcome",
            "event.action",
            "host.architecture",
            "host.hostname",
            "host.name",
            "host.os.platform",
            "http.request.method",
            "http.request.referrer",
            "http.version",
            "log.level",
            "observer.hostname",
            "observer.name",
            "observer.type",
            "observer.version",
            "observer.ephemeral_id",
            "observer.id",
            "process.args",
            "process.title",
            "service.environment",
            "service.name",
            "service.node.name",
            "service.version",
            "service.framework.name",
            "service.framework.version",
            "service.language.name",
            "service.language.version",
            "service.runtime.name",
            "service.runtime.version",
            "source.domain",
            "span.id",
            "trace.id",
            "transaction.id",
            "url.domain",
            "url.fragment",
            "url.query",
            "url.scheme",
            "user.domain",
            "user.email",
            "user.id",
            "user.name",
            "user_agent.device.name",
            "user_agent.name",
            "user_agent.original",
            "user_agent.os.family",
            "user_agent.os.full",
            "user_agent.os.kernel",
            "user_agent.os.name",
            "user_agent.os.platform",
            "user_agent.os.version",
            "user_agent.version",
            "kubernetes.namespace",
            "kubernetes.node.name",
            "kubernetes.pod.name",
            "kubernetes.pod.uid"
          ]
        }
      }
    }
  },
  "_meta": {
    "package": {
      "name": "apm"
    }
  }
}

# create index template using legacy componente templates
POST _index_template/mytemplate
{
  "composed_of" : ["logs-apm.app@mappings","logs-apm.app@settings"],
  "index_patterns" : ["idontexist"],
  "template": {
    "mappings": {
      "dynamic": false
    }
  }
}

# check if templates exist
GET /_component_template/logs-apm.app@mappings
GET /_component_template/logs-apm.app@settings
GET /_index_template/mytemplate

Scenario 1 - component templates not used by index templates

  • create fake legacy components template
  • install apm integration
  • observe component templates have been deleted

Scenario 2 - component templates are used by an index template

  • create fake legacy components template
  • create index template which is composed of the component templates
  • install apm integration
  • observe component templates have not been deleted

@hop-dev hop-dev added release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team auto-backport Deprecated - use backport:version if exact versions are needed v8.2.0 v8.2.1 labels Apr 20, 2022
@hop-dev hop-dev self-assigned this Apr 20, 2022
@hop-dev hop-dev requested a review from a team as a code owner April 20, 2022 22:36
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@jen-huang jen-huang added v8.3.0 release_note:fix and removed v8.2.0 release_note:skip Skip the PR/issue when compiling release notes labels Apr 20, 2022
@hop-dev
Copy link
Contributor Author

hop-dev commented Apr 21, 2022

@elasticmachine merge upstream

@nchaulet nchaulet self-requested a review April 21, 2022 12:51
Copy link
Member

@kpollich kpollich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple nitpicky code things - didn't pull down the code to test quite yet. Thanks for all the tests here!

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally with an upgrade from 8.0 with few packages to that PR and looks like it working fine 🚀

@hop-dev hop-dev enabled auto-merge (squash) April 21, 2022 14:04
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @hop-dev

@hop-dev hop-dev merged commit dccca6b into elastic:main Apr 21, 2022
kibanamachine pushed a commit that referenced this pull request Apr 21, 2022
* remove legacy component templates as part of package install

* re-work unit tests

* remove unnecessary await

* check if component templates are in use before deleting

* add integration tests

* PR feedback

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit dccca6b)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.2

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@joshdover
Copy link
Contributor

@hop-dev If this PR doesn't make the 8.2.0 release, will this cleanup logic work if a user upgrades to 8.2.0 first where the templates aren't cleaned up and then later upgrade to 8.2.1?

kibanamachine added a commit that referenced this pull request Apr 25, 2022
…130758) (#130803)

* [Fleet] Remove legacy component templates on package install (#130758)

* remove legacy component templates as part of package install

* re-work unit tests

* remove unnecessary await

* check if component templates are in use before deleting

* add integration tests

* PR feedback

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit dccca6b)

* fix imports

Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
Co-authored-by: Jen Huang <jen.huang@elastic.co>
@hop-dev
Copy link
Contributor Author

hop-dev commented Apr 25, 2022

will this cleanup logic work if a user upgrades to 8.2.0 first where the templates aren't cleaned up and then later upgrade to 8.2.1?

Yes, we look for legacy component templates on every package install regardless of stack version. (performance wise, in the case where there aren't any legacy templates, this will just perform a get component templates call and then exit early, so felt acceptable)

@hop-dev hop-dev deleted the 129662-remove-old-component-templates-after-install branch April 25, 2022 15:19
kertal pushed a commit to kertal/kibana that referenced this pull request May 24, 2022
…#130758)

* remove legacy component templates as part of package install

* re-work unit tests

* remove unnecessary await

* check if component templates are in use before deleting

* add integration tests

* PR feedback

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v8.2.1 v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Migrating to 8.2 keep old @mappings and @settings component templates
8 participants