Ejemplo n.º 1
0
package consulutil

import (
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/hashicorp/consul/api"

	"github.com/square/p2/pkg/logging"
	"github.com/square/p2/pkg/util/param"
)

// SessionRetrySeconds specifies how long to wait between retries when establishing a
// session to Consul.
var SessionRetrySeconds = param.Int("session_retry_seconds", 5)

// SessionManager continually creates and maintains Consul sessions. It is intended to be
// run in its own goroutine. If one session expires, a new one will be created. As
// sessions come and go, the session ID (or "" for an expired session) will be sent on the
// output channel.
//
// Parameters:
//   config:  Configuration passed to Consul when creating a new session.
//   client:  The Consul client to use.
//   output:  The channel used for exposing Consul session IDs. This method takes
//            ownership of this channel and will close it once no new IDs will be created.
//   done:    Close this channel to close the current session (if any) and stop creating
//            new sessions.
//   logger:  Errors will be logged to this logger.
func SessionManager(
	config api.SessionEntry,
Ejemplo n.º 2
0
	"github.com/square/p2/pkg/manifest"
	"github.com/square/p2/pkg/pods"
	"github.com/square/p2/pkg/rc"
	"github.com/square/p2/pkg/types"
	"github.com/square/p2/pkg/util"
	"github.com/square/p2/pkg/util/param"

	"github.com/Sirupsen/logrus"
)

type Labeler interface {
	GetLabels(labelType labels.Type, id string) (labels.Labeled, error)
}

var (
	ensureRealityPeriodMillis = param.Int("ensure_in_reality_millis", 5000)
	ensureHealthyPeriodMillis = param.Int("ensure_healthy_millis", 1000)
)

type nodeUpdated struct {
	node types.NodeName
	err  error
}

type replicationError struct {
	err error
	// Indicates if the error halted replication or if it is recoverable
	isFatal bool
}

// Assert that replicationError implements the error interface
Ejemplo n.º 3
0
	"github.com/Sirupsen/logrus"
	"github.com/hashicorp/consul/api"

	"github.com/square/p2/pkg/health"
	"github.com/square/p2/pkg/kp/consulutil"
	"github.com/square/p2/pkg/logging"
	"github.com/square/p2/pkg/types"
	"github.com/square/p2/pkg/util/limit"
	"github.com/square/p2/pkg/util/param"
	"github.com/square/p2/pkg/util/stream"
)

var (
	// HealthRetryTimeSec determines how long to wait between retries when a health check
	// fails to write.
	HealthRetryTimeSec = param.Int("health_retry_time_sec", 5)

	// SessionTTLSec sets the TTL time for each session created by consulHealthManager. This
	// parameter controls how long it takes for clients to notice that health checks have
	// stopped.
	SessionTTLSec = param.Int("health_session_ttl_sec", 15)

	// HealthWritesPerMinute sets the average number of writes per minute per service that
	// will be sent to Consul to update health.
	HealthWritesPerMinute = param.Int("health_writes_per_minute", 4)

	// HealthMaxBucketSize sets the maximum token bucket size per service used to
	// rate-limit Consul writes.
	HealthMaxBucketSize = param.Int64("health_max_bucket_size", 16)

	// HealthResumeLimit sets the lower bound on the number of tokens at which updates will
Ejemplo n.º 4
0
import (
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/hashicorp/consul/api"

	"github.com/square/p2/pkg/logging"
	"github.com/square/p2/pkg/util/param"
	"github.com/square/p2/pkg/util/randseed"
)

// SessionRetrySeconds specifies the base time to wait between retries when establishing a
// session. In the presence of errors, the effective time is derived from this base
// following a strategy of exponential backoff with jitter.
var SessionRetrySeconds = param.Int("session_retry_seconds", 10)

// SessionMaxRetrySeconds is the maximum number of seconds to wait between failed
// attempts to acquire a session.
var SessionMaxRetrySeconds = param.Int("session_max_retry_seconds", 300)

// SessionManager continually creates and maintains Consul sessions. It is intended to be
// run in its own goroutine. If one session expires, a new one will be created. As
// sessions come and go, the session ID (or "" for an expired session) will be sent on the
// output channel.
//
// Parameters:
//   config:  Configuration passed to Consul when creating a new session.
//   client:  The Consul client to use.
//   output:  The channel used for exposing Consul session IDs. This method takes
//            ownership of this channel and will close it once no new IDs will be created.