Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions server/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ func (a *App) runInitialized(parentCtx context.Context) error {
return handleError(fmt.Errorf("failed to start resource service: %w", err))
}

hostTicker, err := do.Invoke[*host.UpdateTicker](a.i)
if err != nil {
return handleError(fmt.Errorf("failed to initialize host ticker: %w", err))
}
hostTicker.Start(a.serviceCtx)

monitorSvc, err := do.Invoke[*monitor.Service](a.i)
if err != nil {
return handleError(fmt.Errorf("failed to initialize monitor service: %w", err))
Expand Down
4 changes: 3 additions & 1 deletion server/internal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/pgEdge/control-plane/server/internal/healthcheck"
)

const HostMonitorRefreshInterval = 15 * time.Second

type HostState string

const (
Expand Down Expand Up @@ -112,7 +114,7 @@ func fromStorage(host *StoredHost, status *StoredHostStatus) (*Host, error) {

// Host is considered unreachable if it has failed to check in for 2
// heartbeats.
if time.Since(out.Status.UpdatedAt) > 2*UpdateStatusInterval {
if time.Since(out.Status.UpdatedAt) > 2*HostMonitorRefreshInterval {
out.Status.State = HostStateUnreachable
out.Status.Components = nil //Clear stale component statuses
}
Expand Down
16 changes: 0 additions & 16 deletions server/internal/host/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package host
import (
"fmt"

"github.com/rs/zerolog"
"github.com/samber/do"
clientv3 "go.etcd.io/etcd/client/v3"

Expand All @@ -14,21 +13,6 @@ import (
func Provide(i *do.Injector) {
provideStore(i)
provideService(i)
provideTicker(i)
}

func provideTicker(i *do.Injector) {
do.Provide(i, func(i *do.Injector) (*UpdateTicker, error) {
logger, err := do.Invoke[zerolog.Logger](i)
if err != nil {
return nil, fmt.Errorf("failed to get logger: %w", err)
}
svc, err := do.Invoke[*Service](i)
if err != nil {
return nil, fmt.Errorf("failed to get host service: %w", err)
}
return NewUpdateTicker(logger, svc), nil
})
}

func provideService(i *do.Injector) {
Expand Down
61 changes: 0 additions & 61 deletions server/internal/host/ticker.go

This file was deleted.

6 changes: 3 additions & 3 deletions server/internal/monitor/host_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package monitor
import (
"context"

"github.com/pgEdge/control-plane/server/internal/database"
"github.com/pgEdge/control-plane/server/internal/host"
"github.com/rs/zerolog"

"github.com/pgEdge/control-plane/server/internal/host"
)

type HostMonitor struct {
Expand All @@ -22,7 +22,7 @@ func NewHostMonitor(
}
m.monitor = NewMonitor(
logger,
database.InstanceMonitorRefreshInterval,
host.HostMonitorRefreshInterval,
m.checkStatus,
)
return m
Expand Down
6 changes: 4 additions & 2 deletions server/internal/monitor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Service struct {
certSvc *certificates.Service
dbOrch database.Orchestrator
store *Store
hostMoniter *HostMonitor
hostMonitor *HostMonitor
instances map[string]*InstanceMonitor
serviceInstances map[string]*ServiceInstanceMonitor
}
Expand All @@ -46,7 +46,7 @@ func NewService(
store: store,
instances: map[string]*InstanceMonitor{},
serviceInstances: map[string]*ServiceInstanceMonitor{},
hostMoniter: NewHostMonitor(logger, hostSvc),
hostMonitor: NewHostMonitor(logger, hostSvc),
}
}

Expand All @@ -56,6 +56,7 @@ func (s *Service) Start(ctx context.Context) error {
// The monitors should run for the lifetime of the application rather than
// the lifetime of a single operation.
s.appCtx = ctx
s.hostMonitor.Start(ctx)

stored, err := s.store.InstanceMonitor.
GetAllByHostID(s.cfg.HostID).
Expand Down Expand Up @@ -104,6 +105,7 @@ func (s *Service) Shutdown() error {
}

s.serviceInstances = map[string]*ServiceInstanceMonitor{}
s.hostMonitor.Stop()

return nil
}
Expand Down