Skip to content

Commit

Permalink
revert telemetry changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lornasong committed May 27, 2020
1 parent ebf5aec commit 0fed622
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 138 deletions.
9 changes: 0 additions & 9 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
"sync"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/go-uuid"
)

Expand Down Expand Up @@ -66,7 +64,6 @@ type Agent struct {
knownNodeStatuses map[string]lastKnownStatus
knwonNodeStatusesLock sync.Mutex

memSink *metrics.InmemSink
}

func NewAgent(config *Config, logger *log.Logger) (*Agent, error) {
Expand All @@ -86,11 +83,6 @@ func NewAgent(config *Config, logger *log.Logger) (*Agent, error) {
}
}

memSink, err := lib.InitTelemetry(config.Telemetry)
if err != nil {
return nil, err
}

agent := Agent{
config: config,
client: client,
Expand All @@ -99,7 +91,6 @@ func NewAgent(config *Config, logger *log.Logger) (*Agent, error) {
shutdownCh: make(chan struct{}),
inflightPings: make(map[string]struct{}),
knownNodeStatuses: make(map[string]lastKnownStatus),
memSink: memSink,
}

logger.Printf("[INFO] Connecting to Consul on %s...", clientConf.Address)
Expand Down
3 changes: 0 additions & 3 deletions check.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"
consulchecks "github.com/hashicorp/consul/agent/checks"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
Expand Down Expand Up @@ -175,7 +174,6 @@ func (c *CheckRunner) updateCheckTcp(latestCheck *api.HealthCheck, checkHash typ
// UpdateChecks takes a list of checks from the catalog and updates
// our list of running checks to match.
func (c *CheckRunner) UpdateChecks(checks api.HealthChecks) {
defer metrics.MeasureSince([]string{"checks", "update"}, time.Now())
c.Lock()
defer c.Unlock()

Expand Down Expand Up @@ -329,7 +327,6 @@ func (c *CheckRunner) handleCheckUpdate(check *api.HealthCheck, status, output s
},
},
}
metrics.IncrCounter([]string{"check", "txn"}, 1)
ok, resp, _, err := c.client.Txn().Txn(ops, nil)
if err != nil {
c.logger.Printf("[WARN] Error updating check status in Consul: %v", err)
Expand Down
114 changes: 3 additions & 111 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/command/flags"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/hcl"
"github.com/hashicorp/hcl/hcl/ast"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -52,8 +51,6 @@ type Config struct {
DisableRedundantStatusUpdates bool
DisableCoordinateUpdates bool

Telemetry lib.TelemetryConfig

// Test-only fields.
id string
}
Expand Down Expand Up @@ -109,31 +106,6 @@ func DefaultConfig() *Config {
}
}

type Telemetry struct {
CirconusAPIApp *string `mapstructure:"circonus_api_app"`
CirconusAPIToken *string `mapstructure:"circonus_api_token"`
CirconusAPIURL *string `mapstructure:"circonus_api_url"`
CirconusBrokerID *string `mapstructure:"circonus_broker_id"`
CirconusBrokerSelectTag *string `mapstructure:"circonus_broker_select_tag"`
CirconusCheckDisplayName *string `mapstructure:"circonus_check_display_name"`
CirconusCheckForceMetricActivation *string `mapstructure:"circonus_check_force_metric_activation"`
CirconusCheckID *string `mapstructure:"circonus_check_id"`
CirconusCheckInstanceID *string `mapstructure:"circonus_check_instance_id"`
CirconusCheckSearchTag *string `mapstructure:"circonus_check_search_tag"`
CirconusCheckTags *string `mapstructure:"circonus_check_tags"`
CirconusSubmissionInterval *string `mapstructure:"circonus_submission_interval"`
CirconusSubmissionURL *string `mapstructure:"circonus_submission_url"`
DisableHostname *bool `mapstructure:"disable_hostname"`
DogstatsdAddr *string `mapstructure:"dogstatsd_addr"`
DogstatsdTags []string `mapstructure:"dogstatsd_tags"`
FilterDefault *bool `mapstructure:"filter_default"`
PrefixFilter []string `mapstructure:"prefix_filter"`
MetricsPrefix *string `mapstructure:"metrics_prefix"`
PrometheusRetentionTime *string `mapstructure:"prometheus_retention_time"`
StatsdAddr *string `mapstructure:"statsd_address"`
StatsiteAddr *string `mapstructure:"statsite_address"`
}

type HumanConfig struct {
LogLevel flags.StringValue `mapstructure:"log_level"`
EnableSyslog flags.BoolValue `mapstructure:"enable_syslog"`
Expand All @@ -160,8 +132,6 @@ type HumanConfig struct {

DisableRedundantStatusUpdates flags.BoolValue `mapstructure:"disable_redundant_status_updates"`
DisableCoordinateUpdates flags.BoolValue `mapstructure:"disable_cooridinate_updates"`

Telemetry []Telemetry `mapstructure:"telemetry"`
}

func DecodeConfig(r io.Reader) (*HumanConfig, error) {
Expand All @@ -188,11 +158,6 @@ func DecodeConfig(r io.Reader) (*HumanConfig, error) {
return nil, fmt.Errorf("only one node_meta block allowed")
}

telemetry := list.Filter("telemetry")
if len(telemetry.Elem().Items) > 1 {
return nil, fmt.Errorf("only one telemetry block allowed")
}

// Decode the full thing into a map[string]interface for ease of use
var config HumanConfig
var m map[string]interface{}
Expand Down Expand Up @@ -277,8 +242,9 @@ func MergeConfigPaths(dst *Config, paths []string) error {
if err != nil {
return err
}
MergeConfig(dst, src)

return MergeConfig(dst, src)
return nil
}

for _, path := range paths {
Expand All @@ -290,22 +256,7 @@ func MergeConfigPaths(dst *Config, paths []string) error {
return nil
}

func stringVal(v *string) string {
if v == nil {
return ""
}
return *v
}

func boolVal(v *bool) bool {
if v == nil {
return false
}

return *v
}

func MergeConfig(dst *Config, src *HumanConfig) error {
func MergeConfig(dst *Config, src *HumanConfig) {
src.LogLevel.Merge(&dst.LogLevel)
src.Service.Merge(&dst.Service)
src.Tag.Merge(&dst.Tag)
Expand All @@ -326,63 +277,4 @@ func MergeConfig(dst *Config, src *HumanConfig) error {
src.PingType.Merge(&dst.PingType)
src.DisableRedundantStatusUpdates.Merge(&dst.DisableRedundantStatusUpdates)
src.DisableCoordinateUpdates.Merge(&dst.DisableCoordinateUpdates)

// We check on parse time that there is at most one
if len(src.Telemetry) != 0 {
telemetry := src.Telemetry[0]
// Parse the metric filters
var telemetryAllowedPrefixes, telemetryBlockedPrefixes []string
for _, rule := range telemetry.PrefixFilter {
if rule == "" {
fmt.Println("[WARN] Cannot have empty filter rule in prefix_filter")
continue
}
switch rule[0] {
case '+':
telemetryAllowedPrefixes = append(telemetryAllowedPrefixes, rule[1:])
case '-':
telemetryBlockedPrefixes = append(telemetryBlockedPrefixes, rule[1:])
default:
fmt.Printf("[WARN] Filter rule must begin with either '+' or '-': %q\n", rule)
}
}

var prometheusRetentionTime time.Duration
if telemetry.PrometheusRetentionTime != nil {
d, err := time.ParseDuration(*telemetry.PrometheusRetentionTime)
if err != nil {
return fmt.Errorf("prometheus_retention_time: invalid duration: %q: %s", *telemetry.PrometheusRetentionTime, err)
}

prometheusRetentionTime = d
}

dst.Telemetry = lib.TelemetryConfig{
CirconusAPIApp: stringVal(telemetry.CirconusAPIApp),
CirconusAPIToken: stringVal(telemetry.CirconusAPIToken),
CirconusAPIURL: stringVal(telemetry.CirconusAPIURL),
CirconusBrokerID: stringVal(telemetry.CirconusBrokerID),
CirconusBrokerSelectTag: stringVal(telemetry.CirconusBrokerSelectTag),
CirconusCheckDisplayName: stringVal(telemetry.CirconusCheckDisplayName),
CirconusCheckForceMetricActivation: stringVal(telemetry.CirconusCheckForceMetricActivation),
CirconusCheckID: stringVal(telemetry.CirconusCheckID),
CirconusCheckInstanceID: stringVal(telemetry.CirconusCheckInstanceID),
CirconusCheckSearchTag: stringVal(telemetry.CirconusCheckSearchTag),
CirconusCheckTags: stringVal(telemetry.CirconusCheckTags),
CirconusSubmissionInterval: stringVal(telemetry.CirconusSubmissionInterval),
CirconusSubmissionURL: stringVal(telemetry.CirconusSubmissionURL),
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),
}
}

return nil
}
11 changes: 0 additions & 11 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"strings"
"testing"
"time"

"github.com/hashicorp/consul/lib"
)

func TestDecodeMergeConfig(t *testing.T) {
Expand All @@ -31,10 +29,6 @@ cert_file = "cert.pem"
key_file = "key.pem"
tls_server_name = "example.io"
ping_type = "socket"
telemetry {
statsd_address = "example.io:8888"
prefix_filter = ["+good", "-bad", "+better", "-worse", "wrong", ""]
}
`)

expected := &Config{
Expand All @@ -57,11 +51,6 @@ telemetry {
KeyFile: "key.pem",
TLSServerName: "example.io",
PingType: PingTypeSocket,
Telemetry: lib.TelemetryConfig{
StatsdAddr: "example.io:8888",
AllowedPrefixes: []string{"good", "better"},
BlockedPrefixes: []string{"bad", "worse"},
},
}

result := &Config{}
Expand Down
2 changes: 0 additions & 2 deletions coordinate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
multierror "github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -265,7 +264,6 @@ func (a *Agent) updateFailedNodeTxn(node *api.Node, kvClient *api.KV, key string

// updateNodeCheck updates the node's externalNodeHealth check with the given status/output.
func (a *Agent) updateNodeCheck(node *api.Node, ops api.TxnOps, status, output string) error {
metrics.IncrCounter([]string{"coord", "txn"}, 1)
// Update the external health check status.
ops = append(ops, &api.TxnOp{
Check: &api.CheckTxnOp{
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ func main() {
ui.Info(fmt.Sprintf("Node Reconnect Timeout: %q", config.NodeReconnectTimeout.String()))
ui.Info(fmt.Sprintf(" No Redundant updates: %t", config.DisableRedundantStatusUpdates))
ui.Info(fmt.Sprintf(" Disable coordinates: %t", config.DisableCoordinateUpdates))
ui.Info(fmt.Sprintf(" Statsd address: %q", config.Telemetry.StatsdAddr))
ui.Info(fmt.Sprintf(" Metrix prefix: %q", config.Telemetry.MetricsPrefix))
ui.Info("")
ui.Output("Log data will now stream in as it occurs:\n")

Expand Down

0 comments on commit 0fed622

Please sign in to comment.