refactor: Call Close() on collector

Doesn't do anything at present, but will be used later.

Change the signature on BillingEmitter.Close() to match. Note we didn't use the error returned.
This commit is contained in:
Bryan Boreham
2020-04-13 09:29:19 +00:00
parent 777ff07e19
commit 104b9cba50
4 changed files with 15 additions and 3 deletions

View File

@@ -58,6 +58,7 @@ type Adder interface {
type Collector interface {
Reporter
Adder
Close()
}
// Collector receives published reports from multiple producers. It yields a
@@ -112,6 +113,9 @@ func NewCollector(window time.Duration) Collector {
}
}
// Close is a no-op for the regular collector
func (c *collector) Close() {}
// Add adds a report to the collector's internal state. It implements Adder.
func (c *collector) Add(_ context.Context, rpt report.Report, _ []byte) error {
c.mtx.Lock()
@@ -243,6 +247,9 @@ func (c StaticCollector) Report(context.Context, time.Time) (report.Report, erro
return report.Report(c), nil
}
// Close is a no-op for the static collector
func (c StaticCollector) Close() {}
// HasReports indicates whether the collector contains reports between
// timestamp-app.window and timestamp.
func (c StaticCollector) HasReports(context.Context, time.Time) (bool, error) {

View File

@@ -182,6 +182,10 @@ func NewAWSCollector(config AWSCollectorConfig) (AWSCollector, error) {
}, nil
}
// Close is a no-op for awsCollector
func (c *awsCollector) Close() {
}
// CreateTables creates the required tables in dynamodb
func (c *awsCollector) CreateTables() error {
// see if tableName exists

View File

@@ -166,6 +166,7 @@ func hasWeaveNet(r report.Report) bool {
}
// Close shuts down the billing emitter and billing client flushing events.
func (e *BillingEmitter) Close() error {
return e.billing.Close()
func (e *BillingEmitter) Close() {
e.Collector.Close()
_ = e.billing.Close()
}

View File

@@ -259,9 +259,9 @@ func appMain(flags appFlags) {
log.Fatalf("Error creating emitter: %v", err)
return
}
defer billingEmitter.Close()
collector = billingEmitter
}
defer collector.Close()
controlRouter, err := controlRouterFactory(userIDer, flags.controlRouterURL, flags.controlRPCTimeout)
if err != nil {