Skip to content

Commit

Permalink
Do external package manager check only at startup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
swiatekm committed Dec 2, 2024
1 parent 1ab3edc commit a95566c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
32 changes: 32 additions & 0 deletions changelog/fragments/1733131399-vars-for-platform.yaml
Original file line number Diff line number Diff line change
@@ -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: feature

# 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
3 changes: 1 addition & 2 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion pkg/component/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package component

import (
"fmt"
"github.com/elastic/elastic-agent/internal/pkg/agent/install/pkgmgr"
goruntime "runtime"
"strings"

Expand Down Expand Up @@ -114,7 +115,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.
Expand Down Expand Up @@ -155,6 +157,7 @@ func LoadPlatformDetail(modifiers ...PlatformModifier) (PlatformDetail, error) {
User: UserDetail{
Root: hasRoot,
},
IsInstalledViaExternalPkgMgr: pkgmgr.InstalledViaExternalPkgMgr(),
}
for _, modifier := range modifiers {
detail = modifier(detail)
Expand Down

0 comments on commit a95566c

Please sign in to comment.