Skip to content

Commit 1efb5cd

Browse files
committed
Remove embedded interfaces from structs
The `db` struct doesn't need to embed the `Database` interface. Instead we can verify that it satisfies the interface which would detect when the definition of the interface changes (new method for instance). The change has also been applied to the other structs following the same pattern. Signed-off-by: Simon Pasquier <[email protected]>
1 parent c27fdc0 commit 1efb5cd

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

database/database.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func New(cfg config.Database) Database {
7171
}
7272

7373
type db struct {
74-
Database
7574
// metrics is the list of metric name (as a key) associated with their usage based on the different collector activated.
7675
// This struct is our "database".
7776
metrics map[string]*v1.Metric
@@ -115,6 +114,8 @@ type db struct {
115114
partialMetricsUsageMutex sync.Mutex
116115
}
117116

117+
var _ = Database(&db{})
118+
118119
func (d *db) DeleteMetric(name string) bool {
119120
d.metricsMutex.Lock()
120121
defer d.metricsMutex.Unlock()

source/grafana/grafana.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ func NewCollector(db database.Database, cfg config.GrafanaCollector) (async.Simp
7171
}
7272

7373
type grafanaCollector struct {
74-
async.SimpleTask
7574
metricUsageClient *usageclient.Client
7675
grafanaURL string
7776
grafanaClient *grafanaapi.GrafanaHTTPAPI
7877
logger *logrus.Entry
7978
}
8079

80+
var _ async.SimpleTask = &grafanaCollector{}
81+
8182
func (c *grafanaCollector) Execute(ctx context.Context, _ context.CancelFunc) error {
8283
hits, err := c.collectAllDashboardUID(ctx)
8384
if err != nil {

source/labels/labels.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func NewCollector(db database.Database, cfg *config.LabelsCollector) (async.Simp
5151
}
5252

5353
type labelCollector struct {
54-
async.SimpleTask
5554
promClient v1.API
5655
db database.Database
5756
metricUsageClient client.Client
@@ -60,6 +59,8 @@ type labelCollector struct {
6059
logger *logrus.Entry
6160
}
6261

62+
var _ async.SimpleTask = &labelCollector{}
63+
6364
func (c *labelCollector) Execute(ctx context.Context, _ context.CancelFunc) error {
6465
now := time.Now()
6566
start := now.Add(time.Duration(-c.period))

source/metric/metric.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ func NewCollector(db database.Database, cfg config.MetricCollector) (async.Simpl
4040
}
4141

4242
type metricCollector struct {
43-
async.SimpleTask
4443
client v1.API
4544
db database.Database
4645
period model.Duration
4746
logger *logrus.Entry
4847
}
4948

49+
var _ async.SimpleTask = &metricCollector{}
50+
5051
func (c *metricCollector) Execute(ctx context.Context, _ context.CancelFunc) error {
5152
now := time.Now()
5253
start := now.Add(time.Duration(-c.period))

source/perses/perses.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ func NewCollector(db database.Database, cfg config.PersesCollector) (async.Simpl
6060
}
6161

6262
type persesCollector struct {
63-
async.SimpleTask
6463
persesClient persesClientV1.DashboardInterface
6564
metricUsageClient *usageclient.Client
6665
persesURL string
6766
logger *logrus.Entry
6867
}
6968

69+
var _ async.SimpleTask = &persesCollector{}
70+
7071
func (c *persesCollector) Execute(_ context.Context, _ context.CancelFunc) error {
7172
dashboards, err := c.persesClient.List("")
7273
if err != nil {

source/rules/rules.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ func NewCollector(db database.Database, cfg *config.RulesCollector) (async.Simpl
6262
}
6363

6464
type rulesCollector struct {
65-
async.SimpleTask
6665
promClient v1.API
6766
metricUsageClient *usageclient.Client
6867
promURL string
6968
logger *logrus.Entry
7069
retry uint
7170
}
7271

72+
var _ async.SimpleTask = &rulesCollector{}
73+
7374
func (c *rulesCollector) Execute(ctx context.Context, _ context.CancelFunc) error {
7475
result, err := c.getRules(ctx)
7576
if err != nil {

0 commit comments

Comments
 (0)