mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
Add metrics for ACME clients in precomputed queries (#26519)
* Add metrics for ACME clients in precomputed queries * add changelog
This commit is contained in:
3
changelog/26519.txt
Normal file
3
changelog/26519.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:improvement
|
||||||
|
core/activity: Include ACME client metrics to precomputed queries
|
||||||
|
```
|
||||||
@@ -2399,6 +2399,7 @@ func (a *ActivityLog) reportPrecomputedQueryMetrics(ctx context.Context, segment
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
summedMetricsMonthly[secretSyncActivityType] += entry.Counts.countByType(secretSyncActivityType)
|
summedMetricsMonthly[secretSyncActivityType] += entry.Counts.countByType(secretSyncActivityType)
|
||||||
|
summedMetricsMonthly[ACMEActivityType] += entry.Counts.countByType(ACMEActivityType)
|
||||||
case opts.activePeriodStart:
|
case opts.activePeriodStart:
|
||||||
a.metrics.SetGaugeWithLabels(
|
a.metrics.SetGaugeWithLabels(
|
||||||
[]string{"identity", "entity", "active", "reporting_period"},
|
[]string{"identity", "entity", "active", "reporting_period"},
|
||||||
@@ -2415,14 +2416,15 @@ func (a *ActivityLog) reportPrecomputedQueryMetrics(ctx context.Context, segment
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
summedMetricsReporting[secretSyncActivityType] += entry.Counts.countByType(secretSyncActivityType)
|
summedMetricsReporting[secretSyncActivityType] += entry.Counts.countByType(secretSyncActivityType)
|
||||||
|
summedMetricsReporting[ACMEActivityType] += entry.Counts.countByType(ACMEActivityType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for clientType, count := range summedMetricsMonthly {
|
for ct, count := range summedMetricsMonthly {
|
||||||
a.metrics.SetGauge([]string{"identity", strings.ReplaceAll(clientType, "-", "_"), "active", "monthly"}, float32(count))
|
a.metrics.SetGauge([]string{"identity", strings.ReplaceAll(ct, "-", "_"), "active", "monthly"}, float32(count))
|
||||||
}
|
}
|
||||||
for clientType, count := range summedMetricsReporting {
|
for ct, count := range summedMetricsReporting {
|
||||||
a.metrics.SetGauge([]string{"identity", strings.ReplaceAll(clientType, "-", "_"), "active", "reporting_period"}, float32(count))
|
a.metrics.SetGauge([]string{"identity", strings.ReplaceAll(ct, "-", "_"), "active", "reporting_period"}, float32(count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4982,17 +4982,18 @@ func TestActivityLog_reportPrecomputedQueryMetrics(t *testing.T) {
|
|||||||
|
|
||||||
// for each client type, make 3 clients in their own namespaces
|
// for each client type, make 3 clients in their own namespaces
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
for _, clientType := range []string{secretSyncActivityType, nonEntityTokenActivityType, entityActivityType} {
|
for _, clientType := range ActivityClientTypes {
|
||||||
client := &activity.EntityRecord{
|
client := &activity.EntityRecord{
|
||||||
ClientID: fmt.Sprintf("%s-%d", clientType, i),
|
ClientID: fmt.Sprintf("%s-%d", clientType, i),
|
||||||
NamespaceID: fmt.Sprintf("ns-%d", i),
|
NamespaceID: fmt.Sprintf("ns-%d", i),
|
||||||
MountAccessor: fmt.Sprintf("mnt-%d", i),
|
MountAccessor: fmt.Sprintf("mnt-%d", i),
|
||||||
ClientType: clientType,
|
ClientType: clientType,
|
||||||
NonEntity: clientType == nonEntityTokenActivityType,
|
NonEntity: clientType == nonEntityTokenActivityType || clientType == ACMEActivityType,
|
||||||
}
|
}
|
||||||
processClientRecord(client, byNS, byMonth, segmentTime)
|
processClientRecord(client, byNS, byMonth, segmentTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endTime := timeutil.EndOfMonth(segmentTime)
|
endTime := timeutil.EndOfMonth(segmentTime)
|
||||||
opts := pqOptions{
|
opts := pqOptions{
|
||||||
byNamespace: byNS,
|
byNamespace: byNS,
|
||||||
@@ -5001,7 +5002,6 @@ func TestActivityLog_reportPrecomputedQueryMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
otherTime := segmentTime.Add(time.Hour)
|
otherTime := segmentTime.Add(time.Hour)
|
||||||
|
|
||||||
hasNoMetric := func(t *testing.T, intervals []*metrics.IntervalMetrics, name string) {
|
hasNoMetric := func(t *testing.T, intervals []*metrics.IntervalMetrics, name string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
gauges := intervals[len(intervals)-1].Gauges
|
gauges := intervals[len(intervals)-1].Gauges
|
||||||
@@ -5011,6 +5011,7 @@ func TestActivityLog_reportPrecomputedQueryMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasMetric := func(t *testing.T, intervals []*metrics.IntervalMetrics, name string, value float32, namespaceLabel *string) {
|
hasMetric := func(t *testing.T, intervals []*metrics.IntervalMetrics, name string, value float32, namespaceLabel *string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
fullMetric := fmt.Sprintf("%s;cluster=test-cluster", name)
|
fullMetric := fmt.Sprintf("%s;cluster=test-cluster", name)
|
||||||
@@ -5038,6 +5039,7 @@ func TestActivityLog_reportPrecomputedQueryMetrics(t *testing.T) {
|
|||||||
hasNoMetric(t, data, "identity.entity.active.reporting_period")
|
hasNoMetric(t, data, "identity.entity.active.reporting_period")
|
||||||
hasNoMetric(t, data, "identity.secret_sync.active.reporting_period")
|
hasNoMetric(t, data, "identity.secret_sync.active.reporting_period")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("monthly metric", func(t *testing.T) {
|
t.Run("monthly metric", func(t *testing.T) {
|
||||||
// activePeriodEnd is equal to the segment time, indicating that monthly
|
// activePeriodEnd is equal to the segment time, indicating that monthly
|
||||||
// metrics should be reported
|
// metrics should be reported
|
||||||
@@ -5057,7 +5059,9 @@ func TestActivityLog_reportPrecomputedQueryMetrics(t *testing.T) {
|
|||||||
// secret sync metrics should be the sum of clients across all
|
// secret sync metrics should be the sum of clients across all
|
||||||
// namespaces
|
// namespaces
|
||||||
hasMetric(t, data, "identity.secret_sync.active.monthly", 3, nil)
|
hasMetric(t, data, "identity.secret_sync.active.monthly", 3, nil)
|
||||||
|
hasMetric(t, data, "identity.pki_acme.active.monthly", 3, nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("reporting period metric", func(t *testing.T) {
|
t.Run("reporting period metric", func(t *testing.T) {
|
||||||
// activePeriodEnd is not equal to the segment time but activePeriodStart
|
// activePeriodEnd is not equal to the segment time but activePeriodStart
|
||||||
// is, which indicates that metrics for the reporting period should be
|
// is, which indicates that metrics for the reporting period should be
|
||||||
@@ -5078,5 +5082,6 @@ func TestActivityLog_reportPrecomputedQueryMetrics(t *testing.T) {
|
|||||||
// secret sync metrics should be the sum of clients across all
|
// secret sync metrics should be the sum of clients across all
|
||||||
// namespaces
|
// namespaces
|
||||||
hasMetric(t, data, "identity.secret_sync.active.reporting_period", 3, nil)
|
hasMetric(t, data, "identity.secret_sync.active.reporting_period", 3, nil)
|
||||||
|
hasMetric(t, data, "identity.pki_acme.active.reporting_period", 3, nil)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user