[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 { type ResponseCounts struct {
DistinctEntities int `json:"distinct_entities"` DistinctEntities int `json:"distinct_entities" mapstructure:"distinct_entities"`
EntityClients int `json:"entity_clients"` EntityClients int `json:"entity_clients" mapstructure:"entity_clients"`
NonEntityTokens int `json:"non_entity_tokens"` NonEntityTokens int `json:"non_entity_tokens" mapstructure:"non_entity_tokens"`
NonEntityClients int `json:"non_entity_clients"` NonEntityClients int `json:"non_entity_clients" mapstructure:"non_entity_clients"`
Clients int `json:"clients"` Clients int `json:"clients"`
} }
type ResponseNamespace struct { type ResponseNamespace struct {
NamespaceID string `json:"namespace_id"` NamespaceID string `json:"namespace_id" mapstructure:"namespace_id"`
NamespacePath string `json:"namespace_path"` NamespacePath string `json:"namespace_path" mapstructure:"namespace_path"`
Counts ResponseCounts `json:"counts"` Counts ResponseCounts `json:"counts"`
Mounts []*ResponseMount `json:"mounts"` Mounts []*ResponseMount `json:"mounts"`
} }
@@ -1598,7 +1598,7 @@ type ResponseNewClients struct {
} }
type ResponseMount struct { type ResponseMount struct {
MountPath string `json:"mount_path"` MountPath string `json:"mount_path" mapstructure:"mount_path"`
Counts *ResponseCounts `json:"counts"` Counts *ResponseCounts `json:"counts"`
} }

View File

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