Skip to content

Commit 4723d8f

Browse files
Yuriy TeodorovychYuriy Teodorovych
authored andcommitted
fix lint
1 parent 79e4466 commit 4723d8f

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

maas-api/internal/auth/cached_admin_checker.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (c *CachedAdminChecker) IsAdmin(ctx context.Context, user *token.UserContex
9696
return result
9797
}
9898

99-
//nolint:ireturn // Prometheus counters are inherently interface-typed; callers need Counter to read values.
99+
//nolint:ireturn,nonamedreturns // Prometheus counters are inherently interface-typed; named returns clarify which is which.
100100
func (c *CachedAdminChecker) Metrics() (hits, misses prometheus.Counter) {
101101
return c.hits, c.misses
102102
}
@@ -109,14 +109,19 @@ func (c *CachedAdminChecker) evictExpiredLocked(now time.Time) {
109109
}
110110
}
111111

112+
//nolint:ireturn // prometheus.Counter is the canonical type for counters.
112113
func registerOrReuseCounter(reg prometheus.Registerer, c prometheus.Counter) prometheus.Counter {
113114
err := reg.Register(c)
114115
if err == nil {
115116
return c
116117
}
117118
var are prometheus.AlreadyRegisteredError
118119
if errors.As(err, &are) {
119-
return are.ExistingCollector.(prometheus.Counter)
120+
existing, ok := are.ExistingCollector.(prometheus.Counter)
121+
if !ok {
122+
panic("existing collector is not a Counter")
123+
}
124+
return existing
120125
}
121126
panic(err)
122127
}

maas-api/internal/auth/cached_admin_checker_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ func (m *mockDelegate) getCalls() int {
3838

3939
func counterValue(t *testing.T, c prometheus.Counter) float64 {
4040
t.Helper()
41+
metric, ok := c.(prometheus.Metric)
42+
require.True(t, ok, "counter does not implement prometheus.Metric")
4143
var m dto.Metric
42-
require.NoError(t, c.(prometheus.Metric).Write(&m))
44+
require.NoError(t, metric.Write(&m))
4345
return m.GetCounter().GetValue()
4446
}
4547

0 commit comments

Comments
 (0)