diff --git a/agent/consul/state/usage.go b/agent/consul/state/usage.go index 607390e7c9..978e4cadcd 100644 --- a/agent/consul/state/usage.go +++ b/agent/consul/state/usage.go @@ -71,7 +71,7 @@ type KVUsage struct { EnterpriseKVUsage } -type ConfigUsage struct { +type ConfigEntryUsage struct { ConfigByKind map[string]int EnterpriseConfigUsage } @@ -125,8 +125,8 @@ func updateUsage(tx WriteTxn, changes Changes) error { addEnterpriseKVUsage(usageDeltas, change) case tableConfigEntries: entry := changeObject(change).(structs.ConfigEntry) - usageDeltas[entry.GetKind()] += delta - addEnterpriseConfigUsage(usageDeltas, change) + usageDeltas[fmt.Sprintf("%s-%s", tableConfigEntries, entry.GetKind())] += delta + addEnterpriseConfigEntryUsage(usageDeltas, change) } } @@ -375,28 +375,28 @@ func (s *Store) KVUsage() (uint64, KVUsage, error) { return kvs.Index, results, nil } -func (s *Store) ConfigUsage() (uint64, ConfigUsage, error) { +func (s *Store) ConfigEntryUsage() (uint64, ConfigEntryUsage, error) { tx := s.db.ReadTxn() defer tx.Abort() configEntries := make(map[string]int) var maxIdx uint64 for _, kind := range structs.AllConfigEntryKinds { - configEntry, err := firstUsageEntry(tx, kind) + configEntry, err := firstUsageEntry(tx, fmt.Sprintf("%s-%s", tableConfigEntries, kind)) if configEntry.Index > maxIdx { maxIdx = configEntry.Index } if err != nil { - return 0, ConfigUsage{}, fmt.Errorf("failed config entry usage lookup: %s", err) + return 0, ConfigEntryUsage{}, fmt.Errorf("failed config entry usage lookup: %s", err) } configEntries[kind] = configEntry.Count } - usage := ConfigUsage{ + usage := ConfigEntryUsage{ ConfigByKind: configEntries, } - results, err := compileEnterpriseConfigUsage(tx, usage) + results, err := compileEnterpriseConfigEntryUsage(tx, usage) if err != nil { - return 0, ConfigUsage{}, fmt.Errorf("failed config entry usage lookup: %s", err) + return 0, ConfigEntryUsage{}, fmt.Errorf("failed config entry usage lookup: %s", err) } return maxIdx, results, nil diff --git a/agent/consul/state/usage_oss.go b/agent/consul/state/usage_oss.go index c690c9decd..3c7aa79ed2 100644 --- a/agent/consul/state/usage_oss.go +++ b/agent/consul/state/usage_oss.go @@ -23,7 +23,7 @@ func addEnterpriseConnectServiceInstanceUsage(map[string]int, *structs.ServiceNo func addEnterpriseKVUsage(map[string]int, memdb.Change) {} -func addEnterpriseConfigUsage(map[string]int, memdb.Change) {} +func addEnterpriseConfigEntryUsage(map[string]int, memdb.Change) {} func compileEnterpriseServiceUsage(tx ReadTxn, usage ServiceUsage) (ServiceUsage, error) { return usage, nil @@ -37,6 +37,6 @@ func compileEnterpriseKVUsage(tx ReadTxn, usage KVUsage) (KVUsage, error) { return usage, nil } -func compileEnterpriseConfigUsage(tx ReadTxn, usage ConfigUsage) (ConfigUsage, error) { +func compileEnterpriseConfigEntryUsage(tx ReadTxn, usage ConfigEntryUsage) (ConfigEntryUsage, error) { return usage, nil } diff --git a/agent/consul/state/usage_test.go b/agent/consul/state/usage_test.go index ce1ab890b2..3831d9c76d 100644 --- a/agent/consul/state/usage_test.go +++ b/agent/consul/state/usage_test.go @@ -462,7 +462,7 @@ func TestStateStore_Usage_ConfigEntries(t *testing.T) { s := testStateStore(t) t.Run("empty store", func(t *testing.T) { - i, usage, err := s.ConfigUsage() + i, usage, err := s.ConfigEntryUsage() require.NoError(t, err) require.Equal(t, uint64(0), i) for _, kind := range structs.AllConfigEntryKinds { @@ -493,7 +493,7 @@ func TestStateStore_Usage_ConfigEntries(t *testing.T) { Name: "web", })) - i, usage, err := s.ConfigUsage() + i, usage, err := s.ConfigEntryUsage() require.NoError(t, err) require.Equal(t, uint64(3), i) require.Equal(t, 1, usage.ConfigByKind[structs.ServiceDefaults]) diff --git a/agent/consul/usagemetrics/usagemetrics.go b/agent/consul/usagemetrics/usagemetrics.go index cba1a0fa0d..6733ed3df0 100644 --- a/agent/consul/usagemetrics/usagemetrics.go +++ b/agent/consul/usagemetrics/usagemetrics.go @@ -184,12 +184,12 @@ func (u *UsageMetricsReporter) runOnce() { u.emitKVUsage(kvUsage) - _, configUsage, err := state.ConfigUsage() + _, configUsage, err := state.ConfigEntryUsage() if err != nil { u.logger.Warn("failed to retrieve config usage from state store", "error", err) } - u.emitConfigUsage(configUsage) + u.emitConfigEntryUsage(configUsage) } func (u *UsageMetricsReporter) memberUsage() []serf.Member { diff --git a/agent/consul/usagemetrics/usagemetrics_oss.go b/agent/consul/usagemetrics/usagemetrics_oss.go index 6dfa10c939..6376cce882 100644 --- a/agent/consul/usagemetrics/usagemetrics_oss.go +++ b/agent/consul/usagemetrics/usagemetrics_oss.go @@ -75,7 +75,7 @@ func (u *UsageMetricsReporter) emitKVUsage(kvUsage state.KVUsage) { ) } -func (u *UsageMetricsReporter) emitConfigUsage(configUsage state.ConfigUsage) { +func (u *UsageMetricsReporter) emitConfigEntryUsage(configUsage state.ConfigEntryUsage) { for k, i := range configUsage.ConfigByKind { metrics.SetGaugeWithLabels( []string{"consul", "state", "config_entries"},