From 6b2945402ed97b802c4c5c5ebb31123fd26291fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Mon, 9 Dec 2024 18:04:12 +0000 Subject: [PATCH] Do external package manager check only at startup (#6178) * Do external package manager check only at startup We were doing the check for external package manager use when validating vars for the platform, which happens on every configuration reload. I've made this an attribute of the platform instead, and it's now only checked on startup. * Update changelog/fragments/1733131399-vars-for-platform.yaml Co-authored-by: Blake Rouse --------- Co-authored-by: Blake Rouse (cherry picked from commit af175e07ba9b8aa50ba491192faf2e9d8f99e0a7) --- .../1733131399-vars-for-platform.yaml | 32 +++++++++++++++++++ pkg/component/component.go | 3 +- pkg/component/platforms.go | 6 +++- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 changelog/fragments/1733131399-vars-for-platform.yaml diff --git a/changelog/fragments/1733131399-vars-for-platform.yaml b/changelog/fragments/1733131399-vars-for-platform.yaml new file mode 100644 index 00000000000..6873025001f --- /dev/null +++ b/changelog/fragments/1733131399-vars-for-platform.yaml @@ -0,0 +1,32 @@ +# Kind can be one of: +# - breaking-change: a change to previously-documented behavior +# - deprecation: functionality that is being removed in a later release +# - bug-fix: fixes a problem in a previous version +# - enhancement: extends functionality but does not break or fix existing behavior +# - feature: new functionality +# - known-issue: problems that we are aware of in a given version +# - security: impacts on the security of a product or a user’s deployment. +# - upgrade: important information for someone upgrading from a prior version +# - other: does not fit into any of the other categories +kind: enhancement + +# Change summary; a 80ish characters long description of the change. +summary: Do the external package manager check only at startup + +# Long description; in case the summary is not enough to describe the change +# this field accommodate a description without length limits. +# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. +#description: + +# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. +component: elastic-agent + +# PR URL; optional; the PR number that added the changeset. +# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. +# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. +# Please provide it if you are adding a fragment for a different PR. +#pr: https://github.com/owner/repo/1234 + +# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). +# If not present is automatically filled by the tooling with the issue linked to the PR number. +#issue: https://github.com/owner/repo/1234 diff --git a/pkg/component/component.go b/pkg/component/component.go index 5ee509403e3..06a9820d8ec 100644 --- a/pkg/component/component.go +++ b/pkg/component/component.go @@ -15,7 +15,6 @@ import ( "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" - "github.com/elastic/elastic-agent/internal/pkg/agent/install/pkgmgr" "github.com/elastic/elastic-agent/internal/pkg/agent/transpiler" "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config" "github.com/elastic/elastic-agent/internal/pkg/eql" @@ -682,7 +681,7 @@ type outputI struct { func varsForPlatform(platform PlatformDetail) (*transpiler.Vars, error) { return transpiler.NewVars("", map[string]interface{}{ "install": map[string]interface{}{ - "in_default": paths.ArePathsEqual(paths.Top(), paths.InstallPath(paths.DefaultBasePath)) || pkgmgr.InstalledViaExternalPkgMgr(), + "in_default": paths.ArePathsEqual(paths.Top(), paths.InstallPath(paths.DefaultBasePath)) || platform.IsInstalledViaExternalPkgMgr, }, "runtime": map[string]interface{}{ "platform": platform.String(), diff --git a/pkg/component/platforms.go b/pkg/component/platforms.go index 0875cccc22a..d4f4d7fb656 100644 --- a/pkg/component/platforms.go +++ b/pkg/component/platforms.go @@ -9,6 +9,8 @@ import ( goruntime "runtime" "strings" + "github.com/elastic/elastic-agent/internal/pkg/agent/install/pkgmgr" + "github.com/elastic/go-sysinfo" "github.com/elastic/elastic-agent/pkg/utils" @@ -114,7 +116,8 @@ type PlatformDetail struct { Major int Minor int - User UserDetail + IsInstalledViaExternalPkgMgr bool + User UserDetail } // PlatformModifier can modify the platform details before the runtime specifications are loaded. @@ -155,6 +158,7 @@ func LoadPlatformDetail(modifiers ...PlatformModifier) (PlatformDetail, error) { User: UserDetail{ Root: hasRoot, }, + IsInstalledViaExternalPkgMgr: pkgmgr.InstalledViaExternalPkgMgr(), } for _, modifier := range modifiers { detail = modifier(detail)