Exemplo n.º 1
0
package scale

import (
	"time"

	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/leverutil"
	"google.golang.org/grpc"
)

var (
	// GRPCUnusedTimeoutFlag is the time a connection is dropped after it has
	// been last used.
	GRPCUnusedTimeoutFlag = config.DeclareDuration(
		PackageName, "grpcUnusedTimeout", 5*time.Minute)
)

// GRPCPool represents a pool of GRPC client connections.
type GRPCPool struct {
	conns *leverutil.Cache
}

// NewGRPCPool returns a new GRPC connection pool.
func NewGRPCPool() (*GRPCPool, error) {
	expiry := GRPCUnusedTimeoutFlag.Get()
	pool := new(GRPCPool)
	pool.conns = leverutil.NewCache(
		expiry,
		func(addr string) (interface{}, error) {
			return grpc.Dial(addr, grpc.WithInsecure())
		},
Exemplo n.º 2
0
import (
	"fmt"
	"sync"
	"time"

	dockerapi "github.com/fsouza/go-dockerclient"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/dockerutil"
	"github.com/leveros/leveros/leverutil"
	"github.com/leveros/leveros/scale"
)

var (
	// InstanceExpiryTimeFlag is the expiry time after its last use after which
	// a instance instance is evicted from the host.
	InstanceExpiryTimeFlag = config.DeclareDuration(
		PackageName, "instanceExpiryTime", 5*time.Minute)
)

// OnCloseFun is a function that is called when an instance or a resource is
// closed.
type OnCloseFun func(identifier string, err error)

// LeverInstance represents a Lever instance running on a Lever
// host. It takes care of monitoring the Docker container and the Consul lock
// associated with the instance and manages the instance's lifecycle. It also
// keeps track of the resources hosted on it and sends them keep alive's where
// appropriate.
type LeverInstance struct {
	leverEnv        string
	leverService    string
	instanceID      string
Exemplo n.º 3
0
	"net"
	"strings"
	"sync"
	"time"

	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/hostman"
	"github.com/leveros/leveros/http2stream"
	"github.com/leveros/leveros/leverutil"
	"github.com/leveros/leveros/scale"
)

var (
	// ConnectionExpiryFlag is the inactivity time after which client
	// connections are closed.
	ConnectionExpiryFlag = config.DeclareDuration(
		PackageName, "connectionExpiry", 5*time.Minute)
	// ConnectionConnectTimeoutFlag is the timeout for client connections to
	// establish.
	ConnectionConnectTimeoutFlag = config.DeclareDuration(
		PackageName, "connectionConnectTimeout", 20*time.Second)

	// DisableProxyExtFlag enables listening to the external interface
	// (regional LB).
	DisableProxyExtFlag = config.DeclareBool(
		PackageName, "disableProxyExt")
	// DisableProxyInOutFlag enables listening to requests going to or coming
	// from a local environment.
	DisableProxyInOutFlag = config.DeclareBool(
		PackageName, "disableProxyInOut")

	// EnvOutListenPortFlag is the environment listen port for outward
Exemplo n.º 4
0
	consulapi "github.com/hashicorp/consul/api"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/leverutil"
	"github.com/leveros/leveros/scale"
)

var trackerLogger = leverutil.GetLogger(PackageName, "loadtracker")

var (
	// TickNumEventsFlag is the number of events that the load tracker aims to
	// put in a tick length. Yet, due to {Min,Max}TickPeriodFlag, the number of
	// events may vary.
	TickNumEventsFlag = config.DeclareInt(PackageName, "tickNumEvents", 16)
	// MinTickPeriodFlag is the minimum time between load tracker ticks.
	MinTickPeriodFlag = config.DeclareDuration(
		PackageName, "minTickPeriod", 250*time.Millisecond)
	// MaxTickPeriodFlag is the maximum time between load tracker
	// ticks. Note: The period may still be longer than this if no events at all
	// come up for a while.
	MaxTickPeriodFlag = config.DeclareDuration(
		PackageName, "maxTickPeriod", 15*time.Second)
	// StatsExpPeriodFlag is the amount of time stats are taken into
	// consideration. This value is used for the computation of alpha in EWMA.
	StatsExpPeriodFlag = config.DeclareDuration(
		PackageName, "statsExpPeriod", 15*time.Second)
	// ScaleDownAfterFlag is the amount of time to delay scaling down (just
	// in case resource requirements pop back up).
	ScaleDownAfterFlag = config.DeclareDuration(
		PackageName, "scaleDownAfter", 45*time.Second)
	// ChangesExpectedAfterFlag is the maxium amount of time a change in number
	// of instances is expected to be reflected in Consul. (Otherwise
Exemplo n.º 5
0
var logger = leverutil.GetLogger(PackageName, "fleettracker")

// FleetTrackerService is the name of the fleettracker internal service.
const FleetTrackerService = "fleettracker"

var (
	// InstanceIDFlag is the instance ID of the fleettracker. Note: This is a
	// different instance ID than leverutil.InstanceIDFlag because they serve
	// different things.
	InstanceIDFlag = config.DeclareString(
		PackageName, "instanceID", leverutil.RandomID())
	// TTLFlag is the time after a service expires in fleettracker. If no RPC
	// event comes up during this span of time for a Lever service, fleettracker
	// stops keeping track of its stats (it is assumed all its instances
	// have expired anyway).
	TTLFlag = config.DeclareDuration(PackageName, "ttl", 20*time.Minute)
)

// FleetTracker ensures that each Lever service has the right number of
// instances in its fleet. It spins up or kills instances as necessary.
type FleetTracker struct {
	grpcPool   *scale.GRPCPool
	docker     *dockerapi.Client
	serviceSKA *scale.SelfKeepAlive

	// Guard the following.
	lock sync.RWMutex
	// servingID -> servingTracker
	services map[string]*LoadTracker
}
Exemplo n.º 6
0
	"time"

	aerospike "github.com/aerospike/aerospike-client-go"
	dockerapi "github.com/fsouza/go-dockerclient"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/core"
	"github.com/leveros/leveros/dockerutil"
	"github.com/leveros/leveros/hostman"
	"github.com/leveros/leveros/leverutil"
	"github.com/leveros/leveros/scale"
	"github.com/leveros/leveros/store"
)

var (
	// InstanceConstructTimeoutFlag is the deadline for an instance to spin up.
	InstanceConstructTimeoutFlag = config.DeclareDuration(
		PackageName, "instanceConstructTimeout", 15*time.Second)
	// ResourceConstructTimeoutFlag is the deadline for a resource to get
	// allocated (the time necessary might include spinning up an instance).
	ResourceConstructTimeoutFlag = config.DeclareDuration(
		PackageName, "resourceConstructTimeout", 20*time.Second)
)

// LeverHostInfo is the information returned by a call to GetHost.
type LeverHostInfo struct {
	HostAddr string
	// May be "" if instance was found via DNS.
	InstanceID string
	// May be "" if instance was found via DNS.
	ContainerID   string
	ServingID     string
	CodeVersion   int64
Exemplo n.º 7
0
import (
	"fmt"
	"sync"
	"time"

	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/core"
	"github.com/leveros/leveros/leverutil"
	"github.com/leveros/leveros/scale"
	"golang.org/x/net/context"
)

var (
	// ResourceExpiryTimeFlag is the expiry time after its last use after which
	// a resource is evicted from the host.
	ResourceExpiryTimeFlag = config.DeclareDuration(
		PackageName, "resourceExpiryTime", 3*time.Minute)
)

// LeverResource represents an instance of a Lever resource within a Lever
// service, that is hosted on a Lever instance. It takes care of monitoring the
// Consul lock associated with the resource and manages the resource's
// lifecycle.
type LeverResource struct {
	leverEnv       string
	leverService   string
	leverResource  string
	instanceAddr   string
	levResResource *scale.Resource
	conns          *scale.GRPCPool
	sessionKAB     *scale.KeepAliveBuffer
	expiryTimer    *time.Timer