Ejemplo n.º 1
0
func NewAppLogDrain(appGUID string) (*AppLogDrain, error) {
	d := new(AppLogDrain)

	srv, err := lineserver.NewLineServer(
		LINESERVER_PROTO,
		fmt.Sprintf("%v:0", server.LocalIPMust()))
	if err != nil {
		return nil, err
	}

	addr, err := srv.GetUDPAddr()
	if err != nil {
		return nil, err
	}

	d.appGUID = appGUID
	d.srv = srv
	d.port = addr.Port
	d.lifetime, err = time.ParseDuration(config.GetConfig().DrainLifetime)
	if err != nil {
		return nil, fmt.Errorf(
			"Invalid duration value (%v) for drain_lifetime", err)
	}
	// TODO: name should have an uniq id, to allow multiple taile
	// sessions for same app.
	d.drainName = fmt.Sprintf("%s.%s", DRAIN_PREFIX, d.appGUID)

	return d, nil
}
Ejemplo n.º 2
0
// addDrain adds a logyard drain for the apptail.{appGUID} stream
// pointing to ourself (port)
func (d *AppLogDrain) addDrain() error {
	uri := fmt.Sprintf("%s://%v:%v",
		LINESERVER_PROTO,
		server.LocalIPMust(),
		d.port)
	filter := fmt.Sprintf("apptail.%s", d.appGUID)
	drainURI, err := drain.ConstructDrainURI(
		d.drainName, uri, []string{filter}, nil)
	if err != nil {
		return err
	}
	if err = logyard.AddDrain(d.drainName, drainURI); err != nil {
		return err
	}
	log.Infof("Added drain %v => %v", d.drainName, drainURI)
	return nil
}