Skip to content

Commit

Permalink
feat: add no-op reporting background routine
Browse files Browse the repository at this point in the history
  • Loading branch information
JadhavPoonam committed Apr 28, 2023
1 parent eff5dd1 commit 503134b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
24 changes: 19 additions & 5 deletions agent/consul/reporting/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions agent/consul/reporting/reporting_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

package reporting

import (
"context"
)

type EntDeps struct{}

func (rm *ReportingManager) initEnterpriseReporting(entDeps EntDeps) error {
Expand All @@ -22,3 +26,7 @@ func (rm *ReportingManager) StopReportingAgent() error {
// no op
return nil
}

func (m *ReportingManager) Run(ctx context.Context) {
// no op
}
3 changes: 2 additions & 1 deletion agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 503134b

Please sign in to comment.