diff --git a/agent/consul/reporting/reporting.go b/agent/consul/reporting/reporting.go index 982ac0225d58..67fc137c07a6 100644 --- a/agent/consul/reporting/reporting.go +++ b/agent/consul/reporting/reporting.go @@ -2,19 +2,25 @@ package reporting import ( "sync" + "time" + "github.com/hashicorp/consul/agent/consul/state" + "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/go-hclog" ) 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 @@ -24,10 +30,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() (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 673559902506..240500d6d509 100644 --- a/agent/consul/reporting/reporting_oss.go +++ b/agent/consul/reporting/reporting_oss.go @@ -3,6 +3,10 @@ package reporting +import ( + "context" +) + type EntDeps struct{} func (rm *ReportingManager) initEnterpriseReporting(entDeps EntDeps) error { @@ -19,3 +23,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 a15651ab4b4c..1d395e4bf71d 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -683,7 +683,8 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server) (*Ser 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 - register services on external gRPC server. s.externalACLServer = aclgrpc.NewServer(aclgrpc.Config{