Exemple #1
0
func (cmd *status) GetDrains(args []string) ([]string, error) {
	var drains []string

	config := logyard.GetConfig()

	if cmd.prefix {
		// Return drains matching the given prefix (args[0])
		if len(args) != 1 {
			return nil, fmt.Errorf("Need exactly 1 position arg")
		}
		prefix := args[0]
		for name, _ := range config.Drains {
			if strings.HasPrefix(name, prefix) {
				drains = append(drains, name)
			}
		}
	} else if len(args) > 0 {
		drains = args
	} else {
		// Return all drains
		drains = sortedKeysStringMap(config.Drains)
	}

	return drains, nil
}
Exemple #2
0
func (manager *DrainManager) Run() {
	iteration := 0
	drains := logyard.GetConfig().Drains
	log.Infof("Found %d drains to start\n", len(drains))
	for name, uri := range drains {
		manager.StartDrain(name, uri, NewRetryerForDrain(name))
	}

	// Watch for config changes in redis.
	for {
		iteration += 1
		prefix := fmt.Sprintf("CONFIG.%d", iteration)

		select {
		case err := <-logyard.GetConfigChanges():
			if err != nil {
				log.Fatalf("Error re-loading config: %v", err)
			}
			log.Infof(
				"[%s] checking drains after a config change...",
				prefix)
			newDrains := logyard.GetConfig().Drains
			for _, c := range mapdiff.MapDiff(drains, newDrains) {
				if c.Deleted {
					log.Infof("[%s] Drain %s was deleted.", prefix, c.Key)
					manager.StopDrain(c.Key, true)
					delete(drains, c.Key)
				} else {
					log.Infof("[%s] Drain %s was added.", prefix, c.Key)
					manager.StopDrain(c.Key, false)
					manager.StartDrain(
						c.Key,
						c.NewValue,
						NewRetryerForDrain(c.Key))
					drains[c.Key] = c.NewValue
				}
			}
			log.Infof("[%s] Done checking drains.", prefix)
		case <-manager.stopCh:
			break
		}
	}
}
Exemple #3
0
func (cmd *list) Run(args []string) (string, error) {
	config := logyard.GetConfig()
	if cmd.json {
		data, err := json.Marshal(config.Drains)
		return string(data), err
	} else {
		for _, name := range sortedKeysStringMap(config.Drains) {
			uri := config.Drains[name]
			fmt.Printf("%-20s\t%s\n", name, uri)
		}
		return "", nil
	}
}
Exemple #4
0
// RemoveOrphanedDrains removes all drains created by applog_endpoint.
func RemoveOrphanedDrains() {
	// Note that this is tricky to do when horizontally scalling
	// applog_endpoint. Could be solved easily by using nodeID or ip
	// addr in the drain name.
	logyardConfig := logyard.GetConfig()
	for name, _ := range logyardConfig.Drains {
		if strings.HasPrefix(name, DRAIN_PREFIX) {
			log.Infof("Removing orphaned drain %v", name)
			err := logyard.DeleteDrain(name)
			if err != nil {
				log.Warnf("Failed to delete drain %v -- %v",
					name, err)
			}
		}
	}
}
Exemple #5
0
func NewDrainProcess(name, uri string) (*DrainProcess, error) {
	p := &DrainProcess{}

	cfg, err := ParseDrainUri(name, uri, logyard.GetConfig().DrainFormats)
	if err != nil {
		return nil, fmt.Errorf("[drain:%s] Invalid drain URI (%s): %s", name, uri, err)
	}

	p.name = name
	p.cfg = cfg

	if constructor, ok := DRAINS[cfg.Type]; ok && constructor != nil {
		p.constructor = constructor
	} else {
		return nil, fmt.Errorf("[drain:%s] Unsupported drain", name)
	}

	return p, nil
}
Exemple #6
0
// NewRetryerForDrain chooses
func NewRetryerForDrain(name string) retry.Retryer {
	var retryLimit time.Duration
	var err error
	for prefix, duration := range logyard.GetConfig().RetryLimits {
		if strings.HasPrefix(name, prefix) {
			if retryLimit, err = time.ParseDuration(duration); err != nil {
				log.Error("[drain:%s] Invalid duration (%s) for drain prefix %s "+
					"-- %s -- using default value (infinite)",
					name, duration, prefix, err)
				retryLimit = time.Duration(0)
			}
			if retryLimit <= retry.RESET_AFTER {
				log.Error("[drain:%s] Invalid retry limit (%v) -- must be >%v -- "+
					"using default value (infinite)",
					name, retryLimit, retry.RESET_AFTER)
				retryLimit = time.Duration(0)
			}
			break
		}
	}
	log.Infof("[drain:%s] Choosing retry limit %v", name, retryLimit)
	return retry.NewProgressiveRetryer(retryLimit)
}