mirror of https://github.com/status-im/consul.git
Replace fmt.Sprintf with function
This commit is contained in:
parent
a5cf4a9b57
commit
786d2896ff
|
@ -105,7 +105,6 @@ func updateUsage(tx WriteTxn, changes Changes) error {
|
||||||
case tableServices:
|
case tableServices:
|
||||||
svc := changeObject(change).(*structs.ServiceNode)
|
svc := changeObject(change).(*structs.ServiceNode)
|
||||||
usageDeltas[change.Table] += delta
|
usageDeltas[change.Table] += delta
|
||||||
// ServiceKind is empty string for non connect services
|
|
||||||
addEnterpriseServiceInstanceUsage(usageDeltas, change)
|
addEnterpriseServiceInstanceUsage(usageDeltas, change)
|
||||||
|
|
||||||
connectDeltas(change, usageDeltas, delta)
|
connectDeltas(change, usageDeltas, delta)
|
||||||
|
@ -125,7 +124,7 @@ func updateUsage(tx WriteTxn, changes Changes) error {
|
||||||
addEnterpriseKVUsage(usageDeltas, change)
|
addEnterpriseKVUsage(usageDeltas, change)
|
||||||
case tableConfigEntries:
|
case tableConfigEntries:
|
||||||
entry := changeObject(change).(structs.ConfigEntry)
|
entry := changeObject(change).(structs.ConfigEntry)
|
||||||
usageDeltas[fmt.Sprintf("%s-%s", tableConfigEntries, entry.GetKind())] += delta
|
usageDeltas[configEntryUsageTableName(entry.GetKind())] += delta
|
||||||
addEnterpriseConfigEntryUsage(usageDeltas, change)
|
addEnterpriseConfigEntryUsage(usageDeltas, change)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,11 +202,16 @@ func serviceNameChanged(change memdb.Change) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// connectTableEntry is a convenience function to make prefix addition in 1 place
|
// connectUsageTableEntry is a convenience function to make prefix addition in 1 place
|
||||||
func connectUsageTableName(kind string) string {
|
func connectUsageTableName(kind string) string {
|
||||||
return fmt.Sprintf("%s-%s", connectPrefix, kind)
|
return fmt.Sprintf("%s-%s", connectPrefix, kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// configEntryUsageTableName is a convenience function to easily get the prefix + config entry kind in 1 place
|
||||||
|
func configEntryUsageTableName(kind string) string {
|
||||||
|
return fmt.Sprintf("%s-%s", tableConfigEntries, kind)
|
||||||
|
}
|
||||||
|
|
||||||
func connectDeltas(change memdb.Change, usageDeltas map[string]int, delta int) {
|
func connectDeltas(change memdb.Change, usageDeltas map[string]int, delta int) {
|
||||||
// Connect metrics for updated services are more complicated. Check for:
|
// Connect metrics for updated services are more complicated. Check for:
|
||||||
// 1. Did ServiceKind change?
|
// 1. Did ServiceKind change?
|
||||||
|
@ -382,7 +386,7 @@ func (s *Store) ConfigEntryUsage() (uint64, ConfigEntryUsage, error) {
|
||||||
configEntries := make(map[string]int)
|
configEntries := make(map[string]int)
|
||||||
var maxIdx uint64
|
var maxIdx uint64
|
||||||
for _, kind := range structs.AllConfigEntryKinds {
|
for _, kind := range structs.AllConfigEntryKinds {
|
||||||
configEntry, err := firstUsageEntry(tx, fmt.Sprintf("%s-%s", tableConfigEntries, kind))
|
configEntry, err := firstUsageEntry(tx, configEntryUsageTableName(kind))
|
||||||
if configEntry.Index > maxIdx {
|
if configEntry.Index > maxIdx {
|
||||||
maxIdx = configEntry.Index
|
maxIdx = configEntry.Index
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue