From 9063360f7c1ce6a64ea71de0adccc98ff52da9b8 Mon Sep 17 00:00:00 2001 From: Truong Nguyen Date: Mon, 13 Jan 2025 14:52:54 -0800 Subject: [PATCH] feat: add Integration Version to Inventory Payload (#1153) --- CHANGELOG.md | 3 +++ src/definition/populate.go | 10 ++++++++++ src/definition/populate_test.go | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f19cea86a5..a8bba6c7a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### enhancements +- Add K8s Integration version to Inventory @TmNguyen12 [#1153](https://github.com/newrelic/nri-kubernetes/pull/1153) + ## v3.32.4 - 2025-01-13 ### ⛓️ Dependencies diff --git a/src/definition/populate.go b/src/definition/populate.go index 57c3bf10cf..26c211d96e 100644 --- a/src/definition/populate.go +++ b/src/definition/populate.go @@ -39,6 +39,16 @@ func populateCluster(i *integration.Integration, clusterName string, k8sVersion return err } + err = e.Inventory.SetItem("cluster", "newrelic.integrationVersion", i.IntegrationVersion) + if err != nil { + return err //nolint: wrapcheck + } + + err = e.Inventory.SetItem("cluster", "newrelic.integrationName", i.Name) + if err != nil { + return err //nolint: wrapcheck + } + return ms.SetMetric("clusterK8sVersion", k8sVersionStr, metric.ATTRIBUTE) } diff --git a/src/definition/populate_test.go b/src/definition/populate_test.go index aa1b8e3040..54b1c091cd 100644 --- a/src/definition/populate_test.go +++ b/src/definition/populate_test.go @@ -767,6 +767,29 @@ func TestIntegrationPopulator_CustomMsTypeGuesser(t *testing.T) { //nolint: para } } +func TestIntegrationPopulator_IntegrationVersionInInventory(t *testing.T) { + t.Parallel() + integrationVersion := "2.3.1" + intgr, err := integration.New("com.newrelic.kubernetes", integrationVersion, integration.InMemoryStore()) + require.NoError(t, err) + config := testConfig(intgr) + + expectedInventory := inventory.New() + err = expectedInventory.SetItem("cluster", "name", defaultNS) + require.NoError(t, err) + err = expectedInventory.SetItem("cluster", "k8sVersion", config.K8sVersion.String()) + require.NoError(t, err) + err = expectedInventory.SetItem("cluster", "newrelic.integrationVersion", integrationVersion) + require.NoError(t, err) + err = expectedInventory.SetItem("cluster", "newrelic.integrationName", "com.newrelic.kubernetes") + require.NoError(t, err) + + populated, errs := definition.IntegrationPopulator(config) + assert.True(t, populated) + assert.Empty(t, errs) + assert.Equal(t, intgr.Entities[2].Inventory, expectedInventory) +} + type NamespaceFilterMock struct{} func (nf NamespaceFilterMock) IsAllowed(namespace string) bool {