diff --git a/vault/activity/query.go b/vault/activity/query.go index e96935c4b137..8b9b773fd3cf 100644 --- a/vault/activity/query.go +++ b/vault/activity/query.go @@ -368,10 +368,10 @@ func (q *PrecomputedQuery) CombineWithCurrentMonth(currentMonth *MonthRecord) { existingNamespaceMounts[monthlyNamespaceRecord.NamespaceID] = monthlyNamespaceRecord } - // Get the counts of each mount per namespace in the current month, and increment + // Get the counts of new clients each mount per namespace in the current month, and increment // its total count in the precomputed query. These total values will be visible in the // by_namespace grouping in the final response data - for _, nsRecord := range currentMonth.Namespaces { + for _, nsRecord := range currentMonth.NewClients.Namespaces { namespaceId := nsRecord.NamespaceID // If the namespace already exists in the previous months, iterate through the mounts and increment the counts diff --git a/vault/activity/query_test.go b/vault/activity/query_test.go index d73c022911a7..f0043385ce60 100644 --- a/vault/activity/query_test.go +++ b/vault/activity/query_test.go @@ -388,28 +388,28 @@ func TestCombineWithCurrentMonth(t *testing.T) { { NamespaceID: "ns1", Counts: &CountsRecord{ - EntityClients: 2, - NonEntityClients: 2, - SecretSyncs: 2, - ACMEClients: 2, + EntityClients: 4, + NonEntityClients: 4, + SecretSyncs: 4, + ACMEClients: 4, }, Mounts: []*MountRecord{ { MountPath: "m1", Counts: &CountsRecord{ - EntityClients: 1, - NonEntityClients: 1, - SecretSyncs: 1, - ACMEClients: 1, + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, }, }, { MountPath: "m2", Counts: &CountsRecord{ - EntityClients: 1, - NonEntityClients: 1, - SecretSyncs: 1, - ACMEClients: 1, + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, }, }, }, @@ -417,28 +417,28 @@ func TestCombineWithCurrentMonth(t *testing.T) { { NamespaceID: "ns2", Counts: &CountsRecord{ - EntityClients: 2, - NonEntityClients: 2, - SecretSyncs: 2, - ACMEClients: 2, + EntityClients: 4, + NonEntityClients: 4, + SecretSyncs: 4, + ACMEClients: 4, }, Mounts: []*MountRecord{ { MountPath: "m1", Counts: &CountsRecord{ - EntityClients: 1, - NonEntityClients: 1, - SecretSyncs: 1, - ACMEClients: 1, + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, }, }, { MountPath: "m3", Counts: &CountsRecord{ - EntityClients: 1, - NonEntityClients: 1, - SecretSyncs: 1, - ACMEClients: 1, + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, }, }, }, @@ -446,28 +446,119 @@ func TestCombineWithCurrentMonth(t *testing.T) { { NamespaceID: "ns3", Counts: &CountsRecord{ - EntityClients: 2, - NonEntityClients: 2, - SecretSyncs: 2, - ACMEClients: 2, + EntityClients: 4, + NonEntityClients: 4, + SecretSyncs: 4, + ACMEClients: 4, }, Mounts: []*MountRecord{ { MountPath: "m1", Counts: &CountsRecord{ - EntityClients: 1, - NonEntityClients: 1, - SecretSyncs: 1, - ACMEClients: 1, + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, }, }, { MountPath: "m2", Counts: &CountsRecord{ - EntityClients: 1, - NonEntityClients: 1, - SecretSyncs: 1, - ACMEClients: 1, + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, + }, + }, + }, + }, + }, + NewClients: &NewClientRecord{ + Namespaces: []*MonthlyNamespaceRecord{ + { + NamespaceID: "ns1", + Counts: &CountsRecord{ + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, + }, + Mounts: []*MountRecord{ + { + MountPath: "m1", + Counts: &CountsRecord{ + EntityClients: 1, + NonEntityClients: 1, + SecretSyncs: 1, + ACMEClients: 1, + }, + }, + { + MountPath: "m2", + Counts: &CountsRecord{ + EntityClients: 1, + NonEntityClients: 1, + SecretSyncs: 1, + ACMEClients: 1, + }, + }, + }, + }, + { + NamespaceID: "ns2", + Counts: &CountsRecord{ + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, + }, + Mounts: []*MountRecord{ + { + MountPath: "m1", + Counts: &CountsRecord{ + EntityClients: 1, + NonEntityClients: 1, + SecretSyncs: 1, + ACMEClients: 1, + }, + }, + { + MountPath: "m3", + Counts: &CountsRecord{ + EntityClients: 1, + NonEntityClients: 1, + SecretSyncs: 1, + ACMEClients: 1, + }, + }, + }, + }, + { + NamespaceID: "ns3", + Counts: &CountsRecord{ + EntityClients: 2, + NonEntityClients: 2, + SecretSyncs: 2, + ACMEClients: 2, + }, + Mounts: []*MountRecord{ + { + MountPath: "m1", + Counts: &CountsRecord{ + EntityClients: 1, + NonEntityClients: 1, + SecretSyncs: 1, + ACMEClients: 1, + }, + }, + { + MountPath: "m2", + Counts: &CountsRecord{ + EntityClients: 1, + NonEntityClients: 1, + SecretSyncs: 1, + ACMEClients: 1, + }, }, }, },