Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
155 changes: 111 additions & 44 deletions agentconfig/agentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ const (

prodEndpoint = "{zone}-osconfig.googleapis.com.:443"

osInventoryEnabledDefault = false
guestPoliciesEnabledDefault = false
taskNotificationEnabledDefault = false
debugEnabledDefault = false
osInventoryEnabledDefault = false
guestPoliciesEnabledDefault = false
taskNotificationEnabledDefault = false
debugEnabledDefault = false
extendedInventoryEnabledDefault = false
extendedInventoryCollectionIntervalDefault = 10

oldConfigDirLinux = "/etc/osconfig"
cacheDirLinux = "/var/lib/google_osconfig_agent"
Expand Down Expand Up @@ -122,25 +124,28 @@ var (
)

type config struct {
aptRepoFilePath string
instanceName string
instanceZone string
projectID string
svcEndpoint string
googetRepoFilePath string
zypperRepoFilePath string
yumRepoFilePath string
instanceID string
universeDomain string
numericProjectID int64
osConfigPollInterval int
debugEnabled bool
taskNotificationEnabled bool
guestPoliciesEnabled bool
osInventoryEnabled bool
scalibrLinuxEnabled bool
guestAttributesEnabled bool
traceGetInventory bool
aptRepoFilePath string
instanceName string
instanceZone string
projectID string
svcEndpoint string
googetRepoFilePath string
zypperRepoFilePath string
yumRepoFilePath string
instanceID string
universeDomain string
numericProjectID int64
osConfigPollInterval int
debugEnabled bool
taskNotificationEnabled bool
guestPoliciesEnabled bool
osInventoryEnabled bool
scalibrLinuxEnabled bool
guestAttributesEnabled bool
traceGetInventory bool
extendedInventoryEnabled bool

@bromivipo bromivipo Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're updating the SCALIBR flow, am I right in understanding that we can drop scalibrLinuxEnabled and rely on extendedInventoryEnabled for both linux and windows?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, scalibrLinuxEnabled is a flag to enable extraction using osv-scalibr and extendedInventoryEnabled is used to enable extraction with extended set of extractors (other than currently supported).

@ganochenkodg ganochenkodg Aug 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please correct me if i'm wrong. if we have scalibrLinuxEnabled = true - we just start to use current default extractors ("os/cos", "os/dpkg", "os/rpm"). with additional extendedInventoryEnabled = true we start to use other extractors by default, language extractors for example. and extendedInventoryExtractorsAllowed is used to filter those additionally activated extractors. @petercieslak is that correct?

my other theory - extendedInventoryExtractorsAllowed must be non-empty to use any additional extractors with extendedInventoryEnabled, otherwise will be no effect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first description is correct, with scalibrLinuxEnabled we use the default extractors. Additionally extendedInventoryEnabled allows us to use extendedInventoryExtractorsAllowed in the extraction process. The extendedInventoryExtractorsAllowed don't have to be non-empty - if that's the case we just use the default extractors.

extendedInventoryCollectionInterval int

@bromivipo bromivipo Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this field necessary, or could we reuse the existing osConfigPollInterval ticker instead of adding a new interval configuration? Since we discussed merging the results of extended and legacy scans, it makes sense for them to run simultaneously.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, it seems that we can reuse the existing ticker

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

extendedInventoryExtractorsAllowed []string
}

func (c *config) parseFeatures(features string, enabled bool) {
Expand Down Expand Up @@ -196,6 +201,17 @@ func parseBool(s string) bool {
return enabled
}

func parseSlice(s string) []string {
var slice []string
for _, item := range strings.Split(s, ",") {
item = strings.TrimSpace(item)
if item != "" {
slice = append(slice, item)
}
}
return slice
}

type metadataJSON struct {
Instance instanceJSON
Project projectJSON
Expand All @@ -220,32 +236,37 @@ type universeJSON struct {
}

type attributesJSON struct {
PollIntervalOld *json.Number `json:"os-config-poll-interval"`
PollInterval *json.Number `json:"osconfig-poll-interval"`
InventoryEnabledOld string `json:"os-inventory-enabled"`
InventoryEnabled string `json:"enable-os-inventory"`
PreReleaseFeaturesOld string `json:"os-config-enabled-prerelease-features"`
PreReleaseFeatures string `json:"osconfig-enabled-prerelease-features"`
DebugEnabledOld string `json:"enable-os-config-debug"`
LogLevel string `json:"osconfig-log-level"`
OSConfigEndpointOld string `json:"os-config-endpoint"`
OSConfigEndpoint string `json:"osconfig-endpoint"`
OSConfigEnabled string `json:"enable-osconfig"`
DisabledFeatures string `json:"osconfig-disabled-features"`
EnableGuestAttributes string `json:"enable-guest-attributes"`
TraceGetInventory string `json:"trace-get-inventory"`
ScalibrLinuxEnabled string `json:"enable-scalibr-linux"`
PollIntervalOld *json.Number `json:"os-config-poll-interval"`
PollInterval *json.Number `json:"osconfig-poll-interval"`
InventoryEnabledOld string `json:"os-inventory-enabled"`
InventoryEnabled string `json:"enable-os-inventory"`
PreReleaseFeaturesOld string `json:"os-config-enabled-prerelease-features"`
PreReleaseFeatures string `json:"osconfig-enabled-prerelease-features"`
DebugEnabledOld string `json:"enable-os-config-debug"`
LogLevel string `json:"osconfig-log-level"`
OSConfigEndpointOld string `json:"os-config-endpoint"`
OSConfigEndpoint string `json:"osconfig-endpoint"`
OSConfigEnabled string `json:"enable-osconfig"`
DisabledFeatures string `json:"osconfig-disabled-features"`
EnableGuestAttributes string `json:"enable-guest-attributes"`
TraceGetInventory string `json:"trace-get-inventory"`
ScalibrLinuxEnabled string `json:"enable-scalibr-linux"`
ExtendedInventoryEnabled string `json:"osconfig-extended-inventory-enabled"`
ExtendedInventoryCollectionInterval *json.Number `json:"osconfig-extended-inventory-collection-interval"`
ExtendedInventoryExtractorsAllowed string `json:"osconfig-extended-inventory-extractors-allowed"`
}

func createConfigFromMetadata(md metadataJSON) *config {
old := getAgentConfig()
c := &config{
osInventoryEnabled: osInventoryEnabledDefault,
guestPoliciesEnabled: guestPoliciesEnabledDefault,
taskNotificationEnabled: taskNotificationEnabledDefault,
debugEnabled: debugEnabledDefault,
svcEndpoint: prodEndpoint,
osConfigPollInterval: osConfigPollIntervalDefault,
osInventoryEnabled: osInventoryEnabledDefault,
guestPoliciesEnabled: guestPoliciesEnabledDefault,
taskNotificationEnabled: taskNotificationEnabledDefault,
debugEnabled: debugEnabledDefault,
svcEndpoint: prodEndpoint,
osConfigPollInterval: osConfigPollIntervalDefault,
extendedInventoryEnabled: extendedInventoryEnabledDefault,
extendedInventoryCollectionInterval: extendedInventoryCollectionIntervalDefault,

googetRepoFilePath: googetRepoFilePath,
zypperRepoFilePath: zypperRepoFilePath,
Expand Down Expand Up @@ -374,10 +395,41 @@ func createConfigFromMetadata(md metadataJSON) *config {
setScalibrEnablement(md, c)
setSVCEndpoint(md, c)
setTraceGetInventory(md, c)
setExtendedInventory(md, c)

return c
}

func setExtendedInventory(md metadataJSON, c *config) {
projectSettings := md.Project.Attributes
instanceSettings := md.Instance.Attributes

if projectSettings.ExtendedInventoryEnabled != "" {
c.extendedInventoryEnabled = parseBool(projectSettings.ExtendedInventoryEnabled)
}
if instanceSettings.ExtendedInventoryEnabled != "" {
c.extendedInventoryEnabled = parseBool(instanceSettings.ExtendedInventoryEnabled)
}

if projectSettings.ExtendedInventoryCollectionInterval != nil {
if val, err := projectSettings.ExtendedInventoryCollectionInterval.Int64(); err == nil {
c.extendedInventoryCollectionInterval = int(val)
}
}
if instanceSettings.ExtendedInventoryCollectionInterval != nil {
if val, err := instanceSettings.ExtendedInventoryCollectionInterval.Int64(); err == nil {
c.extendedInventoryCollectionInterval = int(val)
}
}

if projectSettings.ExtendedInventoryExtractorsAllowed != "" {
c.extendedInventoryExtractorsAllowed = parseSlice(projectSettings.ExtendedInventoryExtractorsAllowed)
}
if instanceSettings.ExtendedInventoryExtractorsAllowed != "" {
c.extendedInventoryExtractorsAllowed = parseSlice(instanceSettings.ExtendedInventoryExtractorsAllowed)
}
}

func setScalibrEnablement(md metadataJSON, c *config) {
projectSetting := md.Project.Attributes.ScalibrLinuxEnabled
instanceSetting := md.Instance.Attributes.ScalibrLinuxEnabled
Expand Down Expand Up @@ -601,6 +653,21 @@ func TraceGetInventory() bool {
return getAgentConfig().traceGetInventory
}

// ExtendedInventoryEnabled indicates whether extended inventory collection should be enabled.
func ExtendedInventoryEnabled() bool {
return getAgentConfig().extendedInventoryEnabled
}

// ExtendedInventoryCollectionInterval returns the frequency for extended inventory collection.
func ExtendedInventoryCollectionInterval() time.Duration {
return time.Duration(getAgentConfig().extendedInventoryCollectionInterval) * time.Minute
}

// ExtendedInventoryExtractorsAllowed returns the allowed extractors for extended inventory.
func ExtendedInventoryExtractorsAllowed() []string {
return getAgentConfig().extendedInventoryExtractorsAllowed
}

// ZypperRepoDir is the location of the zypper repo files.
func ZypperRepoDir() string {
return zypperRepoDir
Expand Down
Loading
Loading