feat: add no-op reporting background routine (#17178)

This commit is contained in:
Poonam Jadhav 2023-04-28 20:07:03 -04:00 committed by GitHub
parent a90fff4789
commit 2a33111b21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 6 deletions

View File

@ -5,19 +5,26 @@ package reporting
import ( import (
"sync" "sync"
"time"
"github.com/hashicorp/consul/agent/consul/state"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/go-hclog" "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-memdb"
) )
type ReportingManager struct { type ReportingManager struct {
logger hclog.Logger logger hclog.Logger
server ServerDelegate server ServerDelegate
stateProvider StateDelegate
tickerInterval time.Duration
EntDeps EntDeps
sync.RWMutex sync.RWMutex
} }
const ( const (
SystemMetadataReportingProcessID = "reporting-process-id" SystemMetadataReportingProcessID = "reporting-process-id"
ReportingInterval = 1 * time.Hour
) )
//go:generate mockery --name ServerDelegate --inpackage //go:generate mockery --name ServerDelegate --inpackage
@ -27,10 +34,17 @@ type ServerDelegate interface {
IsLeader() bool 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{ rm := &ReportingManager{
logger: logger.Named("reporting"), logger: logger.Named("reporting"),
server: server, server: server,
stateProvider: stateProvider,
tickerInterval: ReportingInterval,
} }
err := rm.initEnterpriseReporting(deps) err := rm.initEnterpriseReporting(deps)
if err != nil { if err != nil {

View File

@ -6,6 +6,10 @@
package reporting package reporting
import (
"context"
)
type EntDeps struct{} type EntDeps struct{}
func (rm *ReportingManager) initEnterpriseReporting(entDeps EntDeps) error { func (rm *ReportingManager) initEnterpriseReporting(entDeps EntDeps) error {
@ -22,3 +26,7 @@ func (rm *ReportingManager) StopReportingAgent() error {
// no op // no op
return nil return nil
} }
func (m *ReportingManager) Run(ctx context.Context) {
// no op
}

View File

@ -769,7 +769,8 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom
s.overviewManager = NewOverviewManager(s.logger, s.fsm, s.config.MetricsReportingInterval) s.overviewManager = NewOverviewManager(s.logger, s.fsm, s.config.MetricsReportingInterval)
go s.overviewManager.Run(&lib.StopChannelContext{StopCh: s.shutdownCh}) 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 // Initialize external gRPC server
s.setupExternalGRPC(config, logger) s.setupExternalGRPC(config, logger)