[VAULT-15398] Activity log data generation fixes (#22752)

This commit is contained in:
miagilepner
2023-09-07 10:53:29 +02:00
committed by GitHub
parent 953f6cd818
commit 5ab88a076b
3 changed files with 34 additions and 15 deletions

View File

@@ -1571,16 +1571,16 @@ func (a *ActivityLog) receivedFragment(fragment *activity.LogFragment) {
}
type ResponseCounts struct {
DistinctEntities int `json:"distinct_entities"`
EntityClients int `json:"entity_clients"`
NonEntityTokens int `json:"non_entity_tokens"`
NonEntityClients int `json:"non_entity_clients"`
DistinctEntities int `json:"distinct_entities" mapstructure:"distinct_entities"`
EntityClients int `json:"entity_clients" mapstructure:"entity_clients"`
NonEntityTokens int `json:"non_entity_tokens" mapstructure:"non_entity_tokens"`
NonEntityClients int `json:"non_entity_clients" mapstructure:"non_entity_clients"`
Clients int `json:"clients"`
}
type ResponseNamespace struct {
NamespaceID string `json:"namespace_id"`
NamespacePath string `json:"namespace_path"`
NamespaceID string `json:"namespace_id" mapstructure:"namespace_id"`
NamespacePath string `json:"namespace_path" mapstructure:"namespace_path"`
Counts ResponseCounts `json:"counts"`
Mounts []*ResponseMount `json:"mounts"`
}
@@ -1598,7 +1598,7 @@ type ResponseNewClients struct {
}
type ResponseMount struct {
MountPath string `json:"mount_path"`
MountPath string `json:"mount_path" mapstructure:"mount_path"`
Counts *ResponseCounts `json:"counts"`
}

View File

@@ -9,6 +9,7 @@ import (
"context"
"fmt"
"io"
"strings"
"sync"
"time"
@@ -226,6 +227,7 @@ func (m *multipleMonthsActivityClients) processMonth(ctx context.Context, core *
m.months[month.GetMonthsAgo()].generationParameters = month
add := func(c []*generation.Client, segmentIndex *int) error {
for _, clients := range c {
mountAccessor := defaultMountAccessorRootNS
if clients.Namespace == "" {
clients.Namespace = namespace.RootNamespaceID
@@ -234,34 +236,41 @@ func (m *multipleMonthsActivityClients) processMonth(ctx context.Context, core *
clients.ClientType = entityActivityType
}
// verify that the namespace exists
ns, err := core.NamespaceByID(ctx, clients.Namespace)
if err != nil {
return err
if clients.Namespace != namespace.RootNamespaceID && !strings.HasSuffix(clients.Namespace, "/") {
clients.Namespace += "/"
}
// verify that the namespace exists
ns := core.namespaceByPath(clients.Namespace)
if ns.ID == namespace.RootNamespaceID && clients.Namespace != namespace.RootNamespaceID {
return fmt.Errorf("unable to find namespace %s", clients.Namespace)
}
clients.Namespace = ns.ID
// verify that the mount exists
if clients.Mount != "" {
if !strings.HasSuffix(clients.Mount, "/") {
clients.Mount += "/"
}
nctx := namespace.ContextWithNamespace(ctx, ns)
mountEntry := core.router.MatchingMountEntry(nctx, clients.Mount)
if mountEntry == nil {
return fmt.Errorf("unable to find matching mount in namespace %s", clients.Namespace)
return fmt.Errorf("unable to find matching mount in namespace %s", ns.Path)
}
mountAccessor = mountEntry.Accessor
}
mountAccessor := defaultMountAccessorRootNS
if clients.Namespace != namespace.RootNamespaceID && clients.Mount == "" {
// if we're not using the root namespace, find a mount on the namespace that we are using
found := false
for _, mount := range mounts {
if mount.NamespaceID == clients.Namespace {
if mount.NamespaceID == ns.ID {
mountAccessor = mount.Accessor
found = true
break
}
}
if !found {
return fmt.Errorf("unable to find matching mount in namespace %s", clients.Namespace)
return fmt.Errorf("unable to find matching mount in namespace %s", ns.Path)
}
}

View File

@@ -215,6 +215,16 @@ func Test_multipleMonthsActivityClients_processMonth(t *testing.T) {
},
numMonths: 1,
},
{
name: "mount missing slash",
clients: &generation.Data{
Clients: &generation.Data_All{All: &generation.Clients{Clients: []*generation.Client{{
Namespace: namespace.RootNamespaceID,
Mount: "identity",
}}}},
},
numMonths: 1,
},
{
name: "specified namespace exists, mount empty",
clients: &generation.Data{