Example #1
0
func (c *SimpleChain) Wait() error {
	slog.Infof("Waiting for runner to finish in chain %s", c.Name)
	err := c.runner.Wait()
	slog.Infof("Exiting chain %s with error: %v", c.Name, err)

	return err
}
Example #2
0
func (c *SimpleChain) Add(o Operator) Chain {
	ops := c.runner.Operators()
	opIn, isIn := o.(In)
	if isIn && len(ops) > 0 {
		slog.Infof("Setting input channel of %s", Name(o))
		last := ops[len(ops)-1]

		lastOutCh := last.(Out).Out()

		opIn.SetIn(lastOutCh)
	}

	out, ok := o.(Out)
	if ok && nil == out.Out() {
		slog.Infof("Setting output channel of %s", Name(o))
		ch := make(chan Object, CHAN_SLACK)
		out.SetOut(ch)
	}

	c.runner.Add(o)
	return c
}
Example #3
0
func (src *UnixgramSource) Run() error {
	//the socket has to run from the same goroutine because it is not thread safe
	//memory barrier executed when goroutines moved between threads
	//reference: https://groups.google.com/forum/#!topic/golang-nuts/eABYrBA5LEk
	defer close(src.Out())

	// If the socket exists, rm it.
	syscall.Unlink(src.path)

	socket, err := net.ListenPacket("unixgram", src.path)
	if err != nil {
		slog.Fatalf("Listen: %v", err)
		return err
	}

	defer socket.Close()

	// Allow other processes to write here
	os.Chmod(src.path, 0777)

	count := 0
	sent := 0
	lf := []byte{'\n'}

	for {
		count++

		buf := make([]byte, MAX_READ_SIZE)
		nr, _, err := socket.ReadFrom(buf)
		if err != nil {
			return err
		}

		// Now, tokenize on \n, writing out each part of the slice as
		// a separate message
		for _, msg := range bytes.Split(buf[:nr], lf) {
			if len(msg) > 0 {
				wi := src.decodeNginxLog(msg)
				sent++
				src.Out() <- msg[:wi]
			}
		}

		select {
		case <-src.StopNotifier:
			slog.Infof("Closing: count ", count, "Sent:", sent)
			return nil
		default:
		}
	}
}
Example #4
0
func NewSimpleChain() *SimpleChain {
	c := &SimpleChain{runner: NewFailSilentRunner(), Name: "SimpleChain", stopOnce: sync.Once{}}

	var stopOnce sync.Once
	opCloseHandler := func(op Operator, err error) {
		stopOnce.Do(func() {
			if err != nil {
				slog.Warnf("Hard close of chain %s was triggered by op  (%v, %v). Error: %v", c.Name, op, reflect.TypeOf(op), err)
				c.Stop()
			} else {
				slog.Infof("Soft close of chain %s was triggered by op  (%v, %v).", c.Name, op, reflect.TypeOf(op))
				c.SoftStop()
			}
		})
	}

	c.runner.SetOpCloseHandler(opCloseHandler)

	return c
}
Example #5
0
func statsSender(metricsAddr *string, processName *string) {
	rep, err := zmq.NewSocket(zmq.REP)
	if err != nil {
		slog.Errorf("Stats Sender error: %v", err.Error())
		return
	}
	defer rep.Close()
	err = rep.Bind(*metricsAddr)
	if err != nil {
		slog.Errorf("Stats Sender error: %v", err.Error())
		return
	}

	slog.Infof("Stats sender, listening on %s", *metricsAddr)

	// Loop, printing the stats on request
	for {
		_, err := rep.Recv(0)
		if err != nil {
			slog.Errorf("%v", err.Error())
		} else {
			timestamp := time.Now().Unix() - Gm.StartTime
			dBag := statsPkg{*processName, timestamp, map[string]interface{}{}}
			for k, v := range Gm.OpGroups {
				dBag.OpMetrics[k] = map[string]int64{"Events": v.Events.Count(), "Errors": v.Errors.Count(), "Queue": v.QueueLength.Value()}
			}
			stats, err := json.Marshal(dBag)
			if err == nil {
				_, err = rep.SendBytes(stats, zmq.DONTWAIT)
				if err != nil {
					slog.Errorf("%v", err.Error())
				}
			}
		}
	}
}
Example #6
0
func (w *EfficientWorker) Validate(inCh chan stream.Object, typeName string) bool {
	slog.Infof("Checking %s", typeName)
	return true
}