mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 02:02:43 +00:00
Deprecate distinct_entities and nont_entity_tokens (#27830)
* OSS Changes * Added changelog * Fix build errors
This commit is contained in:
3
changelog/27830.txt
Normal file
3
changelog/27830.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:change
|
||||
activity (enterprise): remove deprecated fields distinct_entities and non_entity_tokens
|
||||
```
|
||||
@@ -132,7 +132,7 @@ func (c *OperatorUsageCommand) Run(args []string) int {
|
||||
c.outputTimestamps(resp.Data)
|
||||
|
||||
out := []string{
|
||||
"Namespace path | Distinct entities | Non-Entity tokens | Secret syncs | ACME clients | Active clients",
|
||||
"Namespace path | Entity Clients | Non-Entity clients | Secret syncs | ACME clients | Active clients",
|
||||
}
|
||||
|
||||
out = append(out, c.namespacesOutput(resp.Data)...)
|
||||
@@ -233,14 +233,14 @@ func (c *OperatorUsageCommand) parseNamespaceCount(rawVal interface{}) (UsageRes
|
||||
return ret, errors.New("missing counts")
|
||||
}
|
||||
|
||||
ret.entityCount, ok = jsonNumberOK(counts, "distinct_entities")
|
||||
ret.entityCount, ok = jsonNumberOK(counts, "entity_clients")
|
||||
if !ok {
|
||||
return ret, errors.New("missing distinct_entities")
|
||||
return ret, errors.New("missing entity_clients")
|
||||
}
|
||||
|
||||
ret.tokenCount, ok = jsonNumberOK(counts, "non_entity_tokens")
|
||||
ret.tokenCount, ok = jsonNumberOK(counts, "non_entity_clients")
|
||||
if !ok {
|
||||
return ret, errors.New("missing non_entity_tokens")
|
||||
return ret, errors.New("missing non_entity_clients")
|
||||
}
|
||||
|
||||
// don't error if the secret syncs key is missing
|
||||
@@ -311,15 +311,15 @@ func (c *OperatorUsageCommand) totalOutput(data map[string]interface{}) []string
|
||||
return out
|
||||
}
|
||||
|
||||
entityCount, ok := jsonNumberOK(total, "distinct_entities")
|
||||
entityCount, ok := jsonNumberOK(total, "entity_clients")
|
||||
if !ok {
|
||||
c.UI.Error("missing distinct_entities in total")
|
||||
c.UI.Error("missing entity_clients in total")
|
||||
return out
|
||||
}
|
||||
|
||||
tokenCount, ok := jsonNumberOK(total, "non_entity_tokens")
|
||||
tokenCount, ok := jsonNumberOK(total, "non_entity_clients")
|
||||
if !ok {
|
||||
c.UI.Error("missing non_entity_tokens in total")
|
||||
c.UI.Error("missing non_entity_clients in total")
|
||||
return out
|
||||
}
|
||||
// don't error if secret syncs key is missing
|
||||
|
||||
@@ -1701,9 +1701,7 @@ func (r *ResponseCounts) Add(newRecord *ResponseCounts) {
|
||||
}
|
||||
r.EntityClients += newRecord.EntityClients
|
||||
r.Clients += newRecord.Clients
|
||||
r.DistinctEntities += newRecord.DistinctEntities
|
||||
r.NonEntityClients += newRecord.NonEntityClients
|
||||
r.NonEntityTokens += newRecord.NonEntityTokens
|
||||
r.ACMEClients += newRecord.ACMEClients
|
||||
r.SecretSyncs += newRecord.SecretSyncs
|
||||
}
|
||||
@@ -2747,7 +2745,7 @@ func (a *ActivityLog) calculateByNamespaceResponseForQuery(ctx context.Context,
|
||||
for _, mountRecord := range nsRecord.Mounts {
|
||||
mountResponse = append(mountResponse, &ResponseMount{
|
||||
MountPath: mountRecord.MountPath,
|
||||
Counts: a.countsRecordToCountsResponse(mountRecord.Counts, true),
|
||||
Counts: a.countsRecordToCountsResponse(mountRecord.Counts),
|
||||
})
|
||||
}
|
||||
// Sort the mounts in descending order of usage
|
||||
@@ -2832,7 +2830,7 @@ func (a *ActivityLog) prepareNamespaceResponse(ctx context.Context, nsRecords []
|
||||
|
||||
mountResponse = append(mountResponse, &ResponseMount{
|
||||
MountPath: mountRecord.MountPath,
|
||||
Counts: a.countsRecordToCountsResponse(mountRecord.Counts, false),
|
||||
Counts: a.countsRecordToCountsResponse(mountRecord.Counts),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2845,7 +2843,7 @@ func (a *ActivityLog) prepareNamespaceResponse(ctx context.Context, nsRecords []
|
||||
nsResponse := &ResponseNamespace{
|
||||
NamespaceID: nsRecord.NamespaceID,
|
||||
NamespacePath: displayPath,
|
||||
Counts: *a.countsRecordToCountsResponse(nsRecord.Counts, false),
|
||||
Counts: *a.countsRecordToCountsResponse(nsRecord.Counts),
|
||||
Mounts: mountResponse,
|
||||
}
|
||||
nsResponses = append(nsResponses, nsResponse)
|
||||
|
||||
@@ -3990,8 +3990,8 @@ func TestActivityLog_partialMonthClientCount(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, clientCount := range clientCountResponse {
|
||||
if int(clientCounts[clientCount.NamespaceID]) != clientCount.Counts.DistinctEntities {
|
||||
t.Errorf("bad entity count for namespace %s . expected %d, got %d", clientCount.NamespaceID, int(clientCounts[clientCount.NamespaceID]), clientCount.Counts.DistinctEntities)
|
||||
if int(clientCounts[clientCount.NamespaceID]) != clientCount.Counts.EntityClients {
|
||||
t.Errorf("bad entity count for namespace %s . expected %d, got %d", clientCount.NamespaceID, int(clientCounts[clientCount.NamespaceID]), clientCount.Counts.EntityClients)
|
||||
}
|
||||
totalCount := int(clientCounts[clientCount.NamespaceID])
|
||||
if totalCount != clientCount.Counts.Clients {
|
||||
@@ -3999,12 +3999,12 @@ func TestActivityLog_partialMonthClientCount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
distinctEntities, ok := results["distinct_entities"]
|
||||
entityClients, ok := results["entity_clients"]
|
||||
if !ok {
|
||||
t.Fatalf("malformed results. got %v", results)
|
||||
}
|
||||
if distinctEntities != len(clients) {
|
||||
t.Errorf("bad entity count. expected %d, got %d", len(clients), distinctEntities)
|
||||
if entityClients != len(clients) {
|
||||
t.Errorf("bad entity count. expected %d, got %d", len(clients), entityClients)
|
||||
}
|
||||
|
||||
clientCount, ok := results["clients"]
|
||||
@@ -4067,8 +4067,8 @@ func TestActivityLog_partialMonthClientCountUsingHandleQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, clientCount := range clientCountResponse {
|
||||
if int(clientCounts[clientCount.NamespaceID]) != clientCount.Counts.DistinctEntities {
|
||||
t.Errorf("bad entity count for namespace %s . expected %d, got %d", clientCount.NamespaceID, int(clientCounts[clientCount.NamespaceID]), clientCount.Counts.DistinctEntities)
|
||||
if int(clientCounts[clientCount.NamespaceID]) != clientCount.Counts.EntityClients {
|
||||
t.Errorf("bad entity count for namespace %s . expected %d, got %d", clientCount.NamespaceID, int(clientCounts[clientCount.NamespaceID]), clientCount.Counts.EntityClients)
|
||||
}
|
||||
totalCount := int(clientCounts[clientCount.NamespaceID])
|
||||
if totalCount != clientCount.Counts.Clients {
|
||||
@@ -4082,9 +4082,9 @@ func TestActivityLog_partialMonthClientCountUsingHandleQuery(t *testing.T) {
|
||||
}
|
||||
totalCounts := ResponseCounts{}
|
||||
err = mapstructure.Decode(totals, &totalCounts)
|
||||
distinctEntities := totalCounts.DistinctEntities
|
||||
if distinctEntities != len(clients) {
|
||||
t.Errorf("bad entity count. expected %d, got %d", len(clients), distinctEntities)
|
||||
entityClients := totalCounts.EntityClients
|
||||
if entityClients != len(clients) {
|
||||
t.Errorf("bad entity count. expected %d, got %d", len(clients), entityClients)
|
||||
}
|
||||
|
||||
clientCount := totalCounts.Clients
|
||||
@@ -4112,30 +4112,20 @@ func TestActivityLog_partialMonthClientCountUsingHandleQuery(t *testing.T) {
|
||||
if monthsResponse[0].Counts.NonEntityClients != totalCounts.NonEntityClients {
|
||||
t.Fatalf("wrong non-entity client count. got %v, expected %v", monthsResponse[0].Counts.NonEntityClients, totalCounts.NonEntityClients)
|
||||
}
|
||||
if monthsResponse[0].Counts.NonEntityTokens != totalCounts.NonEntityTokens {
|
||||
t.Fatalf("wrong non-entity client count. got %v, expected %v", monthsResponse[0].Counts.NonEntityTokens, totalCounts.NonEntityTokens)
|
||||
}
|
||||
if monthsResponse[0].Counts.Clients != monthsResponse[0].NewClients.Counts.Clients {
|
||||
t.Fatalf("wrong client count. got %v, expected %v", monthsResponse[0].Counts.Clients, monthsResponse[0].NewClients.Counts.Clients)
|
||||
}
|
||||
if monthsResponse[0].Counts.DistinctEntities != monthsResponse[0].NewClients.Counts.DistinctEntities {
|
||||
t.Fatalf("wrong distinct entities count. got %v, expected %v", monthsResponse[0].Counts.DistinctEntities, monthsResponse[0].NewClients.Counts.DistinctEntities)
|
||||
}
|
||||
if monthsResponse[0].Counts.EntityClients != monthsResponse[0].NewClients.Counts.EntityClients {
|
||||
t.Fatalf("wrong entity client count. got %v, expected %v", monthsResponse[0].Counts.EntityClients, monthsResponse[0].NewClients.Counts.EntityClients)
|
||||
}
|
||||
if monthsResponse[0].Counts.NonEntityClients != monthsResponse[0].NewClients.Counts.NonEntityClients {
|
||||
t.Fatalf("wrong non-entity client count. got %v, expected %v", monthsResponse[0].Counts.NonEntityClients, monthsResponse[0].NewClients.Counts.NonEntityClients)
|
||||
}
|
||||
if monthsResponse[0].Counts.NonEntityTokens != monthsResponse[0].NewClients.Counts.NonEntityTokens {
|
||||
t.Fatalf("wrong non-entity token count. got %v, expected %v", monthsResponse[0].Counts.NonEntityTokens, monthsResponse[0].NewClients.Counts.NonEntityTokens)
|
||||
}
|
||||
|
||||
namespaceResponseMonth := monthsResponse[0].Namespaces
|
||||
|
||||
for _, clientCount := range namespaceResponseMonth {
|
||||
if int(clientCounts[clientCount.NamespaceID]) != clientCount.Counts.EntityClients {
|
||||
t.Errorf("bad entity count for namespace %s . expected %d, got %d", clientCount.NamespaceID, int(clientCounts[clientCount.NamespaceID]), clientCount.Counts.DistinctEntities)
|
||||
t.Errorf("bad entity count for namespace %s . expected %d, got %d", clientCount.NamespaceID, int(clientCounts[clientCount.NamespaceID]), clientCount.Counts.EntityClients)
|
||||
}
|
||||
totalCount := int(clientCounts[clientCount.NamespaceID])
|
||||
if totalCount != clientCount.Counts.Clients {
|
||||
|
||||
@@ -458,9 +458,8 @@ func (e *segmentReader) ReadEntity(ctx context.Context) (*activity.EntityActivit
|
||||
|
||||
// namespaceRecordToCountsResponse converts the record to the ResponseCounts
|
||||
// type. The function sums entity, non-entity, and secret sync counts to get the
|
||||
// total client count. If includeDeprecated is true, the deprecated fields
|
||||
// NonEntityTokens and DistinctEntities are populated
|
||||
func (a *ActivityLog) countsRecordToCountsResponse(record *activity.CountsRecord, includeDeprecated bool) *ResponseCounts {
|
||||
// total client count.
|
||||
func (a *ActivityLog) countsRecordToCountsResponse(record *activity.CountsRecord) *ResponseCounts {
|
||||
response := &ResponseCounts{
|
||||
EntityClients: record.EntityClients,
|
||||
NonEntityClients: record.NonEntityClients,
|
||||
@@ -468,10 +467,6 @@ func (a *ActivityLog) countsRecordToCountsResponse(record *activity.CountsRecord
|
||||
SecretSyncs: record.SecretSyncs,
|
||||
ACMEClients: record.ACMEClients,
|
||||
}
|
||||
if includeDeprecated {
|
||||
response.NonEntityTokens = response.NonEntityClients
|
||||
response.DistinctEntities = response.EntityClients
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
@@ -480,9 +475,7 @@ func (a *ActivityLog) countsRecordToCountsResponse(record *activity.CountsRecord
|
||||
// counts to get the total client count.
|
||||
func (a *ActivityLog) namespaceRecordToCountsResponse(record *activity.NamespaceRecord) *ResponseCounts {
|
||||
return &ResponseCounts{
|
||||
DistinctEntities: int(record.Entities),
|
||||
EntityClients: int(record.Entities),
|
||||
NonEntityTokens: int(record.NonEntityTokens),
|
||||
NonEntityClients: int(record.NonEntityTokens),
|
||||
Clients: int(record.Entities + record.NonEntityTokens + record.SecretSyncs + record.ACMEClients),
|
||||
SecretSyncs: int(record.SecretSyncs),
|
||||
|
||||
@@ -89,7 +89,6 @@ func TestACMERegeneration_RegenerateWithCurrentMonth(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, vault.ResponseCounts{
|
||||
NonEntityTokens: 26,
|
||||
NonEntityClients: 26,
|
||||
Clients: 43,
|
||||
ACMEClients: 17,
|
||||
@@ -102,7 +101,6 @@ func TestACMERegeneration_RegenerateWithCurrentMonth(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, vault.ResponseCounts{
|
||||
NonEntityTokens: 36,
|
||||
NonEntityClients: 36,
|
||||
Clients: 73,
|
||||
ACMEClients: 37,
|
||||
@@ -146,7 +144,6 @@ func TestACMERegeneration_RegenerateMuchOlder(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, vault.ResponseCounts{
|
||||
NonEntityTokens: 26,
|
||||
NonEntityClients: 26,
|
||||
Clients: 43,
|
||||
ACMEClients: 17,
|
||||
@@ -191,7 +188,6 @@ func TestACMERegeneration_RegeneratePreviousMonths(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, vault.ResponseCounts{
|
||||
NonEntityTokens: 26,
|
||||
NonEntityClients: 26,
|
||||
Clients: 43,
|
||||
ACMEClients: 17,
|
||||
|
||||
Reference in New Issue
Block a user