Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: feature flag to clean inventory cache on start #2026

Merged
merged 3 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

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

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

type inventoryState struct {
Expand Down Expand Up @@ -393,6 +395,7 @@ func NewAgent(
cloudHarvester,
fpHarvester,
notificationHandler,
ffRetriever,
)
}

Expand All @@ -410,6 +413,7 @@ func New(
cloudHarvester cloud.Harvester,
fpHarvester fingerprint.Harvester,
notificationHandler *ctl.NotificationHandlerWithCancellation,
ffRetriever feature_flags.Retriever,
) (*Agent, error) {
a := &Agent{
Context: ctx,
Expand All @@ -422,6 +426,7 @@ func New(
connectSrv: connectSrv,
provideIDs: provideIDs,
notificationHandler: notificationHandler,
ffRetriever: ffRetriever,
}

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

// We check FF to delete the whole inventory and trigger the whoel inventory send
// This will bypass the deltas cache and force the inventory to be sent after restarting the Agent
if a.ffRetriever != nil {
alog.Debug("readding FlagFullInventoryDeletion feature flag")

ffFullInventoryDeletionEnabled, ffExists := a.ffRetriever.GetFeatureFlag(fflag.FlagFullInventoryDeletion)
if ffExists && ffFullInventoryDeletionEnabled {
alog.Info("Cleaning inventory cache and forcing full inventory report")
a.store.ResetAllDeltas(a.Context.EntityKey())
}
} else {
alog.Warn("Feature flags retriever is not available")
}

if a.inventoryHandler != nil {
if a.shouldSendInventory() {
a.inventoryHandler.Start()
Expand Down
Loading
Loading