Пример #1
0
func init() {
	Log = logger.New("sphinx")
}
Пример #2
0
import (
	"errors"
	"fmt"
	"net"
	"os"
	"sync"
	"time"

	gearmanWorker "github.com/Clever/gearman-go/worker"
	"gopkg.in/Clever/kayvee-go.v3/logger"
	"gopkg.in/eapache/go-resiliency.v1/retrier"
)

var (
	lg = logger.New("gearcmd")
)

// JobFunc is a function that takes in a Gearman job and does some work on it.
type JobFunc func(Job) ([]byte, error)

// Job is an alias for http://godoc.org/github.com/mikespook/gearman-go/worker#Job.
type Job gearmanWorker.Job

// SigtermHandler is the definition for the function called after the worker receives
// a TERM signal.
type SigtermHandler func(*Worker)

// Worker represents a Gearman worker.
type Worker struct {
	sync.Mutex
Пример #3
0
	PollIntervalRaw string `yaml:"poll_interval"`
	PollInterval    time.Duration
	TimeoutRaw      string `yaml:"rabbitmq_timeout"`
	Timeout         time.Duration
	OverviewOnly    bool `yaml:"overview_only"`
}

// Config from env
var (
	Version        string
	Environment    string
	SignalfxAPIKey string
	PollingConfigs []PollingConfig
)

var logger = l.New("rabbitmq-stats")

func init() {
	Environment = getEnv("_DEPLOY_ENV")
	SignalfxAPIKey = getEnv("SIGNALFX_API_KEY")
	data := getEnv("POLLING_CONFIG")

	err := yaml.Unmarshal([]byte(data), &PollingConfigs)
	if err != nil {
		log.Fatalf("error: %v", err)
	}

	for i := range PollingConfigs {
		fmt.Printf("%+v", PollingConfigs[i])
		pollInterval, err := time.ParseDuration(PollingConfigs[i].PollIntervalRaw)
		if err != nil {
Пример #4
0
	"gopkg.in/Clever/kayvee-go.v3/logger"
)

// TaskConfig defines the configuration for the task.
type TaskConfig struct {
	FunctionName string
	FunctionCmd  string
	WarningLines int
	ParseArgs    bool
	CmdTimeout   time.Duration
	RetryCount   int
	Halt         chan struct{}
}

var (
	lg = logger.New("gearcmd")
	// legacy logger used to maintain existing alerts.
	// Once all workers are migrated to using gearcmd >= v0.5.0 and the alarms are switched over,
	// then we can remove this logger
	legacyLg = logger.New("gearman")
)

// Process runs the Gearman job by running the configured task.
// We need to implement the Task interface so we return (byte[], error)
// though the byte[] is always nil.
func (conf TaskConfig) Process(job baseworker.Job) (b []byte, returnErr error) {
	jobID := getJobID(job)
	if jobID == "" {
		jobID = strconv.Itoa(rand.Int())
		lg.InfoD("rand-job-id", logger.M{"msg": "no job id parsed, random assigned."})
	}
Пример #5
0
package db

import (
	"errors"
	"fmt"
	"os"
	"time"

	"gopkg.in/Clever/kayvee-go.v3/logger"
)

var (
	// ErrNotFound represents the case when a long URL is no found
	ErrNotFound = errors.New("No items found by the db layer")
	lg          = logger.New("shorty")
)

// ShortenObject holds the metadata and the mapping for a shortened URL
// I like the NullTime concept from the pq library, so even for other backends
// let's use it instead of checking whether the date is 0001-01-01
type ShortenObject struct {
	Slug     string    `json:"slug"`
	Owner    string    `json:"owner"`
	LongURL  string    `json:"long_url"`
	Modified time.Time `json:"modified_date,omitempty"`
	Expires  time.Time `json:"expire_date,omitempty"`
}

// ShortenBackend represents the necessary interface for storing and updating URLs.
type ShortenBackend interface {
	DeleteURL(slug string) error
Пример #6
0
package metrics

import (
	"fmt"
	"io/ioutil"
	"os"
	"strings"

	"gopkg.in/Clever/kayvee-go.v3/logger"
)

var lg = logger.New("go-process-metrics")

// getSocketCount returns the number of open sockets
func getSocketCount() uint64 {
	var socketCount uint64
	pid := os.Getpid()
	base := fmt.Sprintf("/proc/%d/fd", pid)
	fds, err := ioutil.ReadDir(base)
	if err != nil {
		lg.ErrorD("failed-get-fds", logger.M{"err": err.Error()})
		return 0
	}

	hasLogged := false
	for _, fd := range fds {
		sl, err := os.Readlink(fmt.Sprintf("%s/%s", base, fd.Name()))
		// The fd opened by ReadDir is often closed at this point.
		// In general, fds may close between the check and readlink and we should ignore those
		if err != nil && !strings.HasSuffix(err.Error(), "no such file or directory") {
			if !hasLogged {