Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Lloyd <[email protected]>
  • Loading branch information
Caleb Lloyd committed Mar 7, 2024
1 parent 2c9d33c commit ba62ef0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions surveyor/collector_statz.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ type StatzCollector struct {
descs statzDescs
collectAccounts bool
natsUp *prometheus.Desc
routeIdRemap map[string]map[uint64]int
gatewayIdRemap map[string]map[uint64]int
routeIDRemap map[string]map[uint64]int
gatewayIDRemap map[string]map[uint64]int

serverLabels []string
serverInfoLabels []string
Expand Down Expand Up @@ -226,7 +226,7 @@ func (sc *StatzCollector) serverInfoLabelValues(sm *server.ServerStatsMsg) []str

func (sc *StatzCollector) routeLabelValues(sm *server.ServerStatsMsg, rStat *server.RouteStat) []string {
idxS := strconv.FormatUint(rStat.ID, 10)
if byName, ok := sc.routeIdRemap[rStat.Name]; ok {
if byName, ok := sc.routeIDRemap[rStat.Name]; ok {
if idx, ok := byName[rStat.ID]; ok {
idxS = strconv.Itoa(idx)
}
Expand All @@ -237,7 +237,7 @@ func (sc *StatzCollector) routeLabelValues(sm *server.ServerStatsMsg, rStat *ser

func (sc *StatzCollector) gatewayLabelValues(sm *server.ServerStatsMsg, gStat *server.GatewayStat) []string {
idxS := strconv.FormatUint(gStat.ID, 10)
if byName, ok := sc.gatewayIdRemap[gStat.Name]; ok {
if byName, ok := sc.gatewayIDRemap[gStat.Name]; ok {
if idx, ok := byName[gStat.ID]; ok {
idxS = strconv.Itoa(idx)
}
Expand Down Expand Up @@ -401,8 +401,8 @@ func NewStatzCollector(nc *nats.Conn, logger *logrus.Logger, numServers int, ser
servers: make(map[string]bool),
doneCh: make(chan struct{}, 1),
collectAccounts: accounts,
routeIdRemap: make(map[string]map[uint64]int),
gatewayIdRemap: make(map[string]map[uint64]int),
routeIDRemap: make(map[string]map[uint64]int),
gatewayIDRemap: make(map[string]map[uint64]int),

// TODO - normalize these if possible. Jetstream varies from the other server labels
serverLabels: []string{"server_cluster", "server_name", "server_id"},
Expand Down Expand Up @@ -1044,7 +1044,7 @@ func (sc *StatzCollector) Collect(ch chan<- prometheus.Metric) {
routeIdRemap[rs.Name] = newByName
}

byName, ok := sc.routeIdRemap[rs.Name]
byName, ok := sc.routeIDRemap[rs.Name]
if !ok {
continue
}
Expand Down Expand Up @@ -1074,12 +1074,12 @@ func (sc *StatzCollector) Collect(ch chan<- prometheus.Metric) {
}
}

pairs := make([]nameIdPair, len(sm.Stats.Routes))
pairs := make([]nameIDPair, len(sm.Stats.Routes))
for i, rs := range sm.Stats.Routes {
pairs[i].id = rs.ID
pairs[i].name = rs.Name
}
sc.routeIdRemap = remapIdToIdx(pairs, sc.routeIdRemap)
sc.routeIDRemap = remapIdToIdx(pairs, sc.routeIDRemap)

for _, rs := range sm.Stats.Routes {
labels = sc.routeLabelValues(sm, rs)
Expand All @@ -1090,12 +1090,12 @@ func (sc *StatzCollector) Collect(ch chan<- prometheus.Metric) {
metrics.newGaugeMetric(sc.descs.RoutePending, float64(rs.Pending), labels)
}

pairs = make([]nameIdPair, len(sm.Stats.Gateways))
pairs = make([]nameIDPair, len(sm.Stats.Gateways))
for i, rs := range sm.Stats.Gateways {
pairs[i].id = rs.ID
pairs[i].name = rs.Name
}
sc.gatewayIdRemap = remapIdToIdx(pairs, sc.gatewayIdRemap)
sc.gatewayIDRemap = remapIdToIdx(pairs, sc.gatewayIDRemap)

for _, gw := range sm.Stats.Gateways {
labels = sc.gatewayLabelValues(sm, gw)
Expand Down Expand Up @@ -1260,12 +1260,12 @@ func unmarshalMsg(msg *nats.Msg, v any) error {
return json.Unmarshal(data, v)
}

type nameIdPair struct {
type nameIDPair struct {
name string
id uint64
}

func remapIdToIdx(pairs []nameIdPair, existingMapping map[string]map[uint64]int) map[string]map[uint64]int {
func remapIdToIdx(pairs []nameIDPair, existingMapping map[string]map[uint64]int) map[string]map[uint64]int {

Check failure on line 1268 in surveyor/collector_statz.go

View workflow job for this annotation

GitHub Actions / test (1.21, ubuntu-latest)

ST1003: func remapIdToIdx should be remapIDToIdx (stylecheck)
newMapping := make(map[string]map[uint64]int)

// give existing the same idx
Expand Down
2 changes: 1 addition & 1 deletion surveyor/collector_statz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestRemapIdToIdx(t *testing.T) {
},
}

pairs := []nameIdPair{
pairs := []nameIDPair{
{name: "a", id: 200},
{name: "a", id: 100},
{name: "a", id: 300},
Expand Down

0 comments on commit ba62ef0

Please sign in to comment.