VAULT-35527 add control groups metrics (#30733)

* oss patch

* oss patch update
This commit is contained in:
Amir Aslamov 2025-05-23 12:47:00 -04:00 committed by GitHub
parent f1c83954f6
commit f444e37f10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1118,3 +1118,40 @@ func (c *Core) GetAuditExclusionStanzaCount() int {
return exclusionsCount
}
func (c *Core) GetControlGroupCount() (int, error) {
policyStore := c.policyStore
if policyStore == nil {
return 0, fmt.Errorf("could not find a policy store")
}
namespaces := c.collectNamespaces()
controlGroupCount := 0
for _, ns := range namespaces {
nsCtx := namespace.ContextWithNamespace(context.Background(), ns)
// get the names of all the ACL policies from on this namespace
policyNames, err := policyStore.ListPolicies(nsCtx, PolicyTypeACL)
if err != nil {
return 0, err
}
for _, name := range policyNames {
policy, err := policyStore.GetPolicy(nsCtx, name, PolicyTypeACL)
if err != nil {
return 0, err
}
// check for control groups inside the path rules of the policy
for _, pathPolicy := range policy.Paths {
if pathPolicy.ControlGroupHCL != nil {
controlGroupCount++
}
}
}
}
return controlGroupCount, nil
}