Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consul dependency updates #134

Merged
merged 6 commits into from
May 31, 2022
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
10 changes: 5 additions & 5 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/consul-esm/version"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
Expand Down Expand Up @@ -71,7 +70,7 @@ type Agent struct {
knownNodeStatuses map[string]lastKnownStatus
knownNodeStatusesLock sync.Mutex

memSink *metrics.InmemSink
metrics *lib.MetricsConfig
}

func NewAgent(config *Config, logger hclog.Logger) (*Agent, error) {
Expand All @@ -81,7 +80,8 @@ func NewAgent(config *Config, logger hclog.Logger) (*Agent, error) {
return nil, err
}

memSink, err := lib.InitTelemetry(config.Telemetry)
// Never used locally. I think we keep the reference to avoid GC.
metricsConf, err := lib.InitTelemetry(config.Telemetry, logger)
if err != nil {
return nil, err
}
Expand All @@ -94,7 +94,7 @@ func NewAgent(config *Config, logger hclog.Logger) (*Agent, error) {
shutdownCh: make(chan struct{}),
inflightPings: make(map[string]struct{}),
knownNodeStatuses: make(map[string]lastKnownStatus),
memSink: memSink,
metrics: metricsConf,
}

logger.Info("Connecting to Consul", "address", clientConf.Address)
Expand Down Expand Up @@ -202,7 +202,7 @@ func (a *Agent) register() error {

// runMetrics is a long-running goroutine that exposes an http metrics interface
func (a *Agent) runMetrics() {
if a.config.Telemetry.PrometheusRetentionTime < 1 || a.config.ClientAddress == "" {
if a.config.Telemetry.PrometheusOpts.Expiration < 1 || a.config.ClientAddress == "" {
return
}

Expand Down
60 changes: 35 additions & 25 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/armon/go-metrics"
consulchecks "github.com/hashicorp/consul/agent/checks"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/types"
Expand Down Expand Up @@ -101,17 +102,16 @@ func (c *CheckRunner) updateCheckHTTP(latestCheck *api.HealthCheck, checkHash ty
tlsConfig.ServerName = definition.TLSServerName

http := &consulchecks.CheckHTTP{
Notify: c,
CheckID: checkHash,
HTTP: definition.HTTP,
Header: definition.Header,
Method: definition.Method,
Interval: definition.IntervalDuration,
Timeout: definition.TimeoutDuration,
Logger: c.logger.StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
}),
CheckID: structs.CheckID{ID: checkHash},
HTTP: definition.HTTP,
Header: definition.Header,
Method: definition.Method,
Interval: definition.IntervalDuration,
Timeout: definition.TimeoutDuration,
Logger: c.logger,
TLSClientConfig: tlsConfig,
StatusHandler: consulchecks.NewStatusHandler(c, c.logger,
c.PassingThreshold, c.CriticalThreshold, c.CriticalThreshold),
}

if check, checkExists := c.checks[checkHash]; checkExists {
Expand Down Expand Up @@ -153,17 +153,18 @@ func (c *CheckRunner) updateCheckHTTP(latestCheck *api.HealthCheck, checkHash ty
return true
}

func (c *CheckRunner) updateCheckTCP(latestCheck *api.HealthCheck, checkHash types.CheckID,
definition *api.HealthCheckDefinition, updated, added checkIDSet) bool {
func (c *CheckRunner) updateCheckTCP(
latestCheck *api.HealthCheck, checkHash types.CheckID,
definition *api.HealthCheckDefinition, updated, added checkIDSet,
) bool {
tcp := &consulchecks.CheckTCP{
Notify: c,
CheckID: checkHash,
CheckID: structs.CheckID{ID: checkHash},
TCP: definition.TCP,
Interval: definition.IntervalDuration,
Timeout: definition.TimeoutDuration,
Logger: c.logger.StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
}),
Logger: c.logger,
StatusHandler: consulchecks.NewStatusHandler(c, c.logger,
c.PassingThreshold, c.CriticalThreshold, c.CriticalThreshold),
}

if check, checkExists := c.checks[checkHash]; checkExists {
Expand Down Expand Up @@ -292,13 +293,22 @@ func (c *CheckRunner) UpdateChecks(checks api.HealthChecks) {
}
}

// ServiceExists is part of the consulchecks.CheckNotifier interface.
// It is currently used as part of Consul's alias service feature.
// This function is used to check for localality of service.
// Unsuppported at this time, so hardcoded false return.
func (c *CheckRunner) ServiceExists(serviceID structs.ServiceID) bool {
return false
}

// UpdateCheck handles the output of an HTTP/TCP check and decides whether or not
// to push an update to the catalog.
func (c *CheckRunner) UpdateCheck(checkID types.CheckID, status, output string) {
func (c *CheckRunner) UpdateCheck(checkID structs.CheckID, status, output string) {
c.Lock()
defer c.Unlock()

check, ok := c.checks[checkID]
checkHash := checkID.ID
check, ok := c.checks[checkHash]
if !ok {
return
}
Expand Down Expand Up @@ -326,11 +336,11 @@ func (c *CheckRunner) UpdateCheck(checkID types.CheckID, status, output string)

// Update the critical time tracking
if status == api.HealthCritical {
if _, ok := c.checksCritical[checkID]; !ok {
c.checksCritical[checkID] = time.Now()
if _, ok := c.checksCritical[checkHash]; !ok {
c.checksCritical[checkHash] = time.Now()
}
} else {
delete(c.checksCritical, checkID)
delete(c.checksCritical, checkHash)
}

// Defer a sync if the output has changed. This is an optimization around
Expand All @@ -339,15 +349,15 @@ func (c *CheckRunner) UpdateCheck(checkID types.CheckID, status, output string)
// change we do the write immediately.
if c.CheckUpdateInterval > 0 && check.Status == status {
check.Output = output
if _, ok := c.deferCheck[checkID]; !ok {
if _, ok := c.deferCheck[checkHash]; !ok {
intv := time.Duration(uint64(c.CheckUpdateInterval)/2) + lib.RandomStagger(c.CheckUpdateInterval)
deferSync := time.AfterFunc(intv, func() {
c.Lock()
c.handleCheckUpdate(&check.HealthCheck, status, output)
delete(c.deferCheck, checkID)
delete(c.deferCheck, checkHash)
c.Unlock()
})
c.deferCheck[checkID] = deferSync
c.deferCheck[checkHash] = deferSync
}
return
}
Expand Down
8 changes: 5 additions & 3 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/go-hclog"

"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -348,9 +349,10 @@ func TestCheck_NoFlapping(t *testing.T) {

runner.UpdateChecks(checks)

id := checkHash(checks[0])
hash := checkHash(checks[0])
id := structs.CheckID{ID: hash}

originalCheck, ok := runner.checks[id]
originalCheck, ok := runner.checks[hash]
if !ok {
t.Fatalf("Check was not stored on runner.checks as expected. Checks: %v", runner.checks)
}
Expand Down Expand Up @@ -412,7 +414,7 @@ func TestCheck_NoFlapping(t *testing.T) {
assert.Equal(t, api.HealthCritical, originalCheck.Status)

runner.UpdateChecks(checks)
currentCheck, ok := runner.checks[id]
currentCheck, ok := runner.checks[hash]
if !ok {
t.Fatalf("Current check was not stored on runner.checks as expected. Checks: %v", runner.checks)
}
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/armon/go-metrics/prometheus"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/command/flags"
"github.com/hashicorp/consul/lib"
Expand Down Expand Up @@ -437,13 +438,13 @@ func convertTelemetry(telemetry Telemetry) (lib.TelemetryConfig, error) {
DisableHostname: boolVal(telemetry.DisableHostname),
DogstatsdAddr: stringVal(telemetry.DogstatsdAddr),
DogstatsdTags: telemetry.DogstatsdTags,
PrometheusRetentionTime: prometheusRetentionTime,
FilterDefault: boolVal(telemetry.FilterDefault),
AllowedPrefixes: telemetryAllowedPrefixes,
BlockedPrefixes: telemetryBlockedPrefixes,
MetricsPrefix: stringVal(telemetry.MetricsPrefix),
StatsdAddr: stringVal(telemetry.StatsdAddr),
StatsiteAddr: stringVal(telemetry.StatsiteAddr),
PrometheusOpts: prometheus.PrometheusOpts{Expiration: prometheusRetentionTime},
}, nil
}

Expand Down
17 changes: 11 additions & 6 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/armon/go-metrics/prometheus"
"github.com/hashicorp/consul/lib"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -117,9 +118,11 @@ log_json = true
AllowedPrefixes: []string{"good", "better"},
BlockedPrefixes: []string{"bad", "worse"},
MetricsPrefix: "test",
PrometheusRetentionTime: 5 * time.Hour,
StatsdAddr: "example.io:8888",
StatsiteAddr: "5.6.7.8",
PrometheusOpts: prometheus.PrometheusOpts{
Expiration: 5 * time.Hour,
},
StatsdAddr: "example.io:8888",
StatsiteAddr: "5.6.7.8",
},
PassingThreshold: 3,
CriticalThreshold: 2,
Expand Down Expand Up @@ -255,9 +258,11 @@ func TestConvertTelemetry(t *testing.T) {
},
false,
lib.TelemetryConfig{
AllowedPrefixes: []string{"allow"},
BlockedPrefixes: []string{"deny"},
PrometheusRetentionTime: 1 * time.Minute,
AllowedPrefixes: []string{"allow"},
BlockedPrefixes: []string{"deny"},
PrometheusOpts: prometheus.PrometheusOpts{
Expiration: 1 * time.Minute,
},
},
},
{
Expand Down
116 changes: 66 additions & 50 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,92 @@ module github.com/hashicorp/consul-esm
go 1.17

require (
github.com/armon/go-metrics v0.3.9
github.com/go-ping/ping v1.0.0
github.com/hashicorp/consul v1.6.1
github.com/hashicorp/consul/api v1.10.1
github.com/hashicorp/consul/sdk v0.8.0
github.com/hashicorp/go-hclog v0.16.2
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-uuid v1.0.1
github.com/hashicorp/go-version v1.2.0
github.com/armon/go-metrics v0.4.0
github.com/go-ping/ping v1.1.0
github.com/hashicorp/consul v1.12.1
github.com/hashicorp/consul/api v1.12.0
github.com/hashicorp/consul/sdk v0.9.0
github.com/hashicorp/go-hclog v1.2.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.5.0
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/serf v0.9.5
github.com/mitchellh/cli v1.1.0
github.com/mitchellh/mapstructure v1.4.1
github.com/prometheus/client_golang v1.4.0
github.com/stretchr/testify v1.4.0
github.com/hashicorp/serf v0.9.8
github.com/mitchellh/cli v1.1.3
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.12.2
github.com/stretchr/testify v1.7.1
)

require (
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/Microsoft/go-winio v0.4.5 // indirect
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e // indirect
github.com/DataDog/datadog-go v4.8.3+incompatible // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible // indirect
github.com/circonus-labs/circonusllhist v0.1.3 // indirect
github.com/circonus-labs/circonusllhist v0.1.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-connections v0.3.0 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/consul-net-rpc v0.0.0-20220307172752-3602954411b4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-bexpr v0.1.11 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-retryablehttp v0.6.3 // indirect
github.com/hashicorp/go-msgpack v1.1.5 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-syslog v1.0.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/memberlist v0.2.2 // indirect
github.com/hashicorp/raft v1.1.1 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/kr/text v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/hashicorp/memberlist v0.3.1 // indirect
github.com/hashicorp/raft v1.3.9 // indirect
github.com/hashicorp/raft-autopilot v0.1.6 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/miekg/dns v1.1.26 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/miekg/dns v1.1.49 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/hashstructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/pointerstructure v1.2.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.9.1 // indirect
github.com/prometheus/procfs v0.0.8 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
google.golang.org/grpc v1.25.0 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/genproto v0.0.0-20220526192754-51939a95c655 // indirect
google.golang.org/grpc v1.46.2 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
Loading