Skip to content

Commit c822245

Browse files
feat: feature flag to clean inventory cache on start (#2026)
* feat: feature flag to clean inventory cache on start * chore: fix linting issues --------- Co-authored-by: Rohan Yadav <[email protected]>
1 parent defe0d3 commit c822245

File tree

4 files changed

+149
-87
lines changed

4 files changed

+149
-87
lines changed

internal/agent/agent.go

+19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/newrelic/infrastructure-agent/pkg/sysinfo/hostid"
2020

21+
"github.com/newrelic/infrastructure-agent/internal/agent/cmdchannel/fflag"
2122
"github.com/newrelic/infrastructure-agent/internal/agent/instrumentation"
2223
"github.com/newrelic/infrastructure-agent/internal/agent/inventory"
2324
"github.com/newrelic/infrastructure-agent/internal/agent/types"
@@ -95,6 +96,7 @@ type Agent struct {
9596
agentID *entity.ID // pointer as it's referred from several points
9697
mtx sync.Mutex // Protect plugins
9798
notificationHandler *ctl.NotificationHandlerWithCancellation // Handle ipc messaging.
99+
ffRetriever feature_flags.Retriever
98100
}
99101

100102
type inventoryState struct {
@@ -393,6 +395,7 @@ func NewAgent(
393395
cloudHarvester,
394396
fpHarvester,
395397
notificationHandler,
398+
ffRetriever,
396399
)
397400
}
398401

@@ -410,6 +413,7 @@ func New(
410413
cloudHarvester cloud.Harvester,
411414
fpHarvester fingerprint.Harvester,
412415
notificationHandler *ctl.NotificationHandlerWithCancellation,
416+
ffRetriever feature_flags.Retriever,
413417
) (*Agent, error) {
414418
a := &Agent{
415419
Context: ctx,
@@ -422,6 +426,7 @@ func New(
422426
connectSrv: connectSrv,
423427
provideIDs: provideIDs,
424428
notificationHandler: notificationHandler,
429+
ffRetriever: ffRetriever,
425430
}
426431

427432
a.plugins = make([]Plugin, 0)
@@ -820,6 +825,20 @@ func (a *Agent) Run() (err error) {
820825
close(exit)
821826
}()
822827

828+
// We check FF to delete the whole inventory and trigger the whoel inventory send
829+
// This will bypass the deltas cache and force the inventory to be sent after restarting the Agent
830+
if a.ffRetriever != nil {
831+
alog.Debug("readding FlagFullInventoryDeletion feature flag")
832+
833+
ffFullInventoryDeletionEnabled, ffExists := a.ffRetriever.GetFeatureFlag(fflag.FlagFullInventoryDeletion)
834+
if ffExists && ffFullInventoryDeletionEnabled {
835+
alog.Info("Cleaning inventory cache and forcing full inventory report")
836+
a.store.ResetAllDeltas(a.Context.EntityKey())
837+
}
838+
} else {
839+
alog.Warn("Feature flags retriever is not available")
840+
}
841+
823842
if a.inventoryHandler != nil {
824843
if a.shouldSendInventory() {
825844
a.inventoryHandler.Start()

0 commit comments

Comments
 (0)