From 503134b3c70bfbdaa9efc6bb523fe23177af4951 Mon Sep 17 00:00:00 2001 From: Poonam Jadhav Date: Fri, 28 Apr 2023 11:47:34 -0400 Subject: [PATCH] feat: add no-op reporting background routine --- agent/consul/reporting/reporting.go | 24 +++++++++++++++++++----- agent/consul/reporting/reporting_oss.go | 8 ++++++++ agent/consul/server.go | 3 ++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/agent/consul/reporting/reporting.go b/agent/consul/reporting/reporting.go index a136cbef5451..fec7050f695b 100644 --- a/agent/consul/reporting/reporting.go +++ b/agent/consul/reporting/reporting.go @@ -5,19 +5,26 @@ package reporting import ( "sync" + "time" + "github.com/hashicorp/consul/agent/consul/state" + "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/go-hclog" + "github.com/hashicorp/go-memdb" ) type ReportingManager struct { - logger hclog.Logger - server ServerDelegate + logger hclog.Logger + server ServerDelegate + stateProvider StateDelegate + tickerInterval time.Duration EntDeps sync.RWMutex } const ( SystemMetadataReportingProcessID = "reporting-process-id" + ReportingInterval = 1 * time.Hour ) //go:generate mockery --name ServerDelegate --inpackage @@ -27,10 +34,17 @@ type ServerDelegate interface { IsLeader() bool } -func NewReportingManager(logger hclog.Logger, deps EntDeps, server ServerDelegate) *ReportingManager { +type StateDelegate interface { + NodeUsage() (uint64, state.NodeUsage, error) + ServiceUsage(ws memdb.WatchSet) (uint64, structs.ServiceUsage, error) +} + +func NewReportingManager(logger hclog.Logger, deps EntDeps, server ServerDelegate, stateProvider StateDelegate) *ReportingManager { rm := &ReportingManager{ - logger: logger.Named("reporting"), - server: server, + logger: logger.Named("reporting"), + server: server, + stateProvider: stateProvider, + tickerInterval: ReportingInterval, } err := rm.initEnterpriseReporting(deps) if err != nil { diff --git a/agent/consul/reporting/reporting_oss.go b/agent/consul/reporting/reporting_oss.go index d12254f6cfe3..a1e95a177416 100644 --- a/agent/consul/reporting/reporting_oss.go +++ b/agent/consul/reporting/reporting_oss.go @@ -6,6 +6,10 @@ package reporting +import ( + "context" +) + type EntDeps struct{} func (rm *ReportingManager) initEnterpriseReporting(entDeps EntDeps) error { @@ -22,3 +26,7 @@ func (rm *ReportingManager) StopReportingAgent() error { // no op return nil } + +func (m *ReportingManager) Run(ctx context.Context) { + // no op +} diff --git a/agent/consul/server.go b/agent/consul/server.go index e5140fcc2a3a..1f3476c92a3e 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -769,7 +769,8 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom s.overviewManager = NewOverviewManager(s.logger, s.fsm, s.config.MetricsReportingInterval) go s.overviewManager.Run(&lib.StopChannelContext{StopCh: s.shutdownCh}) - s.reportingManager = reporting.NewReportingManager(s.logger, getEnterpriseReportingDeps(flat), s) + s.reportingManager = reporting.NewReportingManager(s.logger, getEnterpriseReportingDeps(flat), s, s.fsm.State()) + go s.reportingManager.Run(&lib.StopChannelContext{StopCh: s.shutdownCh}) // Initialize external gRPC server s.setupExternalGRPC(config, logger)