Skip to content

Commit

Permalink
Backport of feat: add no-op reporting background routine into release…
Browse files Browse the repository at this point in the history
…/1.13.x (#17194)

* backport of commit 503134b

* fix: resolve lint issues for serviceusage method

---------

Co-authored-by: Poonam Jadhav <[email protected]>
  • Loading branch information
1 parent 6ea33fc commit d62d175
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
23 changes: 18 additions & 5 deletions agent/consul/reporting/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
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 @@ -3,6 +3,10 @@

package reporting

import (
"context"
)

type EntDeps struct{}

func (rm *ReportingManager) initEnterpriseReporting(entDeps EntDeps) error {
Expand All @@ -19,3 +23,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 @@ -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{
Expand Down

0 comments on commit d62d175

Please sign in to comment.