From d9587c46532fcbeb0ba8073ffbabb587128edd32 Mon Sep 17 00:00:00 2001 From: Tiago Queiroz Date: Tue, 12 Nov 2024 20:47:32 +0100 Subject: [PATCH] Add `os_family`, `os_platform` and `os_version` to host provider (#5941) 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 --- ...tform-and-os_version-to-host-provider.yaml | 32 +++++++++++++++++++ .../pkg/composable/providers/host/host.go | 3 ++ .../composable/providers/host/host_test.go | 19 +++++++++++ 3 files changed, 54 insertions(+) create mode 100644 changelog/fragments/1730986549-Add-os_family,-os_platform-and-os_version-to-host-provider.yaml diff --git a/changelog/fragments/1730986549-Add-os_family,-os_platform-and-os_version-to-host-provider.yaml b/changelog/fragments/1730986549-Add-os_family,-os_platform-and-os_version-to-host-provider.yaml new file mode 100644 index 00000000000..990a3406908 --- /dev/null +++ b/changelog/fragments/1730986549-Add-os_family,-os_platform-and-os_version-to-host-provider.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: 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 diff --git a/internal/pkg/composable/providers/host/host.go b/internal/pkg/composable/providers/host/host.go index 5255ccb7bc6..efa555f7bf5 100644 --- a/internal/pkg/composable/providers/host/host.go +++ b/internal/pkg/composable/providers/host/host.go @@ -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 } } diff --git a/internal/pkg/composable/providers/host/host_test.go b/internal/pkg/composable/providers/host/host_test.go index a83e44396ae..c2bae17bfc2 100644 --- a/internal/pkg/composable/providers/host/host_test.go +++ b/internal/pkg/composable/providers/host/host_test.go @@ -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" ) @@ -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) + } + } +}