Rename and prefix ConfigEntry in Usage table

Rename ConfigUsage functions to ConfigEntry

prefix ConfigEntry kinds with the ConfigEntry table name to prevent
potential conflicts
This commit is contained in:
Connor Kelly 2021-10-07 16:19:55 -05:00
parent 533e7dbe85
commit 8c519d5458
No known key found for this signature in database
GPG Key ID: 588D34E7812BC0B7
5 changed files with 16 additions and 16 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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])

View File

@ -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 {

View File

@ -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"},