Skip to content

Commit

Permalink
Add os_family, os_platform and os_version to host provider (#5941)
Browse files Browse the repository at this point in the history
This commit adds `os_family`, `os_platform` and `os_version` to the host provider, enabling differentiating Linux distributions. This is required to support Debian 12 and other distributions that are moving away from traditional log files in favour of Journald.

---------

Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
(cherry picked from commit d9587c4)
  • Loading branch information
belimawr authored and mergify[bot] committed Nov 12, 2024
1 parent bd59a1a commit 5c83802
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
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: Add os_family, os_platform and os_version to host provider

# 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/elastic/elastic-agent/pull/5941

# 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/elastic/integrations/issues/10797
3 changes: 3 additions & 0 deletions internal/pkg/composable/providers/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func getHostInfo(log *logger.Logger) func() (map[string]interface{}, error) {
"architecture": info.Architecture,
"ip": info.IPs,
"mac": info.MACs,
"os_family": info.OS.Family,
"os_platform": info.OS.Platform,
"os_version": info.OS.Version,
}, nil
}
}
19 changes: 19 additions & 0 deletions internal/pkg/composable/providers/host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
ctesting "github.com/elastic/elastic-agent/internal/pkg/composable/testing"
"github.com/elastic/elastic-agent/internal/pkg/config"
"github.com/elastic/elastic-agent/pkg/core/logger"
testlogger "github.com/elastic/elastic-agent/pkg/core/logger/loggertest"
"github.com/elastic/elastic-agent/pkg/features"
)

Expand Down Expand Up @@ -167,3 +168,21 @@ func returnHostMapping(log *logger.Logger) infoFetcher {
return host, nil
}
}

func TestGetHostInfoReturnsSomeKeys(t *testing.T) {
l, _ := testlogger.New(t.Name())
// this is a simple test to ensure the host provider returns the new keys
// needed to add support to Debian 12.
osInfo, err := getHostInfo(l)()
if err != nil {
t.Fatalf("could not get host provider variables: %s", err)
}

expectedKeys := []string{"os_family", "os_platform", "os_version"}

for _, key := range expectedKeys {
if _, exist := osInfo[key]; !exist {
t.Errorf("expecting key '%s' from host provider.", key)
}
}
}

0 comments on commit 5c83802

Please sign in to comment.