Skip to content

Commit

Permalink
Merge pull request #27 from neiljerram/health
Browse files Browse the repository at this point in the history
Implement health endpoints for Typha
  • Loading branch information
fasaxc authored Jul 20, 2017
2 parents 2bc57a6 + a8300f8 commit ba7de84
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 397 deletions.
2 changes: 1 addition & 1 deletion check-licenses/check_licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"regexp"
"strings"

"github.com/projectcalico/libcalico-go/lib/set"
"github.com/projectcalico/typha/pkg/logutils"
"github.com/projectcalico/typha/pkg/set"
)

var (
Expand Down
12 changes: 7 additions & 5 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import:
- package: github.com/go-ini/ini
version: ^1.21.0
- package: github.com/projectcalico/libcalico-go
version: 639aa7b2d33b94419143a2e6987d2d77aa395f2f
version: e1ab5e5bf4a57ea6fa71bf4a7712af27b824a005
subpackages:
- lib
- package: github.com/Sirupsen/logrus
Expand Down Expand Up @@ -58,4 +58,3 @@ import:
version: ^0.3.0
testImport:
- package: github.com/onsi/gomega
version: 9b8c753e8dfb382618ba8fa19b4197b5dcb0434c
2 changes: 2 additions & 0 deletions pkg/config/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type Config struct {
LogSeverityScreen string `config:"oneof(DEBUG,INFO,WARNING,ERROR,CRITICAL);INFO"`
LogSeveritySys string `config:"oneof(DEBUG,INFO,WARNING,ERROR,CRITICAL);INFO"`

HealthEnabled bool `config:"bool;false"`
HealthPort int `config:"int(0,65535);9098"`
PrometheusMetricsEnabled bool `config:"bool;false"`
PrometheusMetricsPort int `config:"int(0,65535);9093"`
PrometheusGoMetricsEnabled bool `config:"bool;true"`
Expand Down
18 changes: 16 additions & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/docopt/docopt-go"
docopt "github.com/docopt/docopt-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/projectcalico/libcalico-go/lib/api"
"github.com/projectcalico/libcalico-go/lib/backend"
bapi "github.com/projectcalico/libcalico-go/lib/backend/api"
"github.com/projectcalico/libcalico-go/lib/health"
"github.com/projectcalico/typha/pkg/buildinfo"
"github.com/projectcalico/typha/pkg/calc"
"github.com/projectcalico/typha/pkg/config"
Expand Down Expand Up @@ -77,6 +78,9 @@ type TyphaDaemon struct {
NewBackendClient func(config api.CalicoAPIConfig) (BackendClient, error)
ConfigureEarlyLogging func()
ConfigureLogging func(configParams *config.Config)

// Health monitoring.
healthAggregator *health.HealthAggregator
}

func New() *TyphaDaemon {
Expand Down Expand Up @@ -215,6 +219,9 @@ configRetry:
func (t *TyphaDaemon) CreateServer() {
// Now create the Syncer; our caching layer and the TCP server.

// Health monitoring, for liveness and readiness endpoints.
t.healthAggregator = health.NewHealthAggregator()

// Get a Syncer from the datastore, which will feed the validator layer with updates.
t.SyncerToValidator = calc.NewSyncerCallbacksDecoupler()
t.Syncer = t.DatastoreClient.Syncer(t.SyncerToValidator)
Expand All @@ -226,7 +233,8 @@ func (t *TyphaDaemon) CreateServer() {

// Create our snapshot cache, which stores point-in-time copies of the datastore contents.
t.Cache = snapcache.New(snapcache.Config{
MaxBatchSize: t.ConfigParams.SnapshotCacheMaxBatchSize,
MaxBatchSize: t.ConfigParams.SnapshotCacheMaxBatchSize,
HealthAggregator: t.healthAggregator,
})

// Create the server, which listens for connections from Felix.
Expand All @@ -241,6 +249,7 @@ func (t *TyphaDaemon) CreateServer() {
DropInterval: t.ConfigParams.ConnectionDropIntervalSecs,
MaxConns: t.ConfigParams.MaxConnectionsUpperLimit,
Port: t.ConfigParams.ServerPort,
HealthAggregator: t.healthAggregator,
},
)
}
Expand Down Expand Up @@ -268,6 +277,11 @@ func (t *TyphaDaemon) Start(cxt context.Context) {
log.Info("Prometheus metrics enabled. Starting server.")
go servePrometheusMetrics(t.ConfigParams)
}

if t.ConfigParams.HealthEnabled {
log.WithField("port", t.ConfigParams.HealthPort).Info("Health enabled. Starting server.")
go t.healthAggregator.ServeHTTP(t.ConfigParams.HealthPort)
}
}

// WaitAndShutDown waits for OS signals or context.Done() and exits as appropriate.
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/projectcalico/typha/pkg/set"
"github.com/projectcalico/libcalico-go/lib/set"
)

func NewK8sAPI() *RealK8sAPI {
Expand Down
133 changes: 0 additions & 133 deletions pkg/set/set.go

This file was deleted.

33 changes: 0 additions & 33 deletions pkg/set/set_suite_test.go

This file was deleted.

Loading

0 comments on commit ba7de84

Please sign in to comment.