Skip to content

Commit

Permalink
feat: add Integration Version to Inventory Payload (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
TmNguyen12 authored Jan 13, 2025
1 parent 757dddb commit 9063360
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/definition/populate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
23 changes: 23 additions & 0 deletions src/definition/populate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9063360

Please sign in to comment.