Exemplo n.º 1
0
func newLogger(faculty string, args ...string) *Logger {
	cnfBld := conf.Builder{Defaults: conf.DEFAULTS}
	cnf, err := cnfBld.Build()
	if err != nil {
		panic(fmt.Sprintf("failed to create conf: %s", err.Error()))
	}
	cnf2 := cnf.Clone(args...)
	lg := NewLogger(faculty, cnf2)
	return lg
}
func TestHeartbeaterStartupShutdown(t *testing.T) {
	cnfBld := conf.Builder{
		Values:   conf.TEST_VALUES(),
		Defaults: conf.DEFAULTS,
	}
	cnf, err := cnfBld.Build()
	if err != nil {
		t.Fatalf("failed to create conf: %s", err.Error())
	}
	lg := common.NewLogger("heartbeater", cnf)
	hb := NewHeartbeater("ExampleHeartbeater", 1, lg)
	if hb.String() != "ExampleHeartbeater" {
		t.Fatalf("hb.String() returned %s instead of %s\n", hb.String(), "ExampleHeartbeater")
	}
	hb.Shutdown()
}
Exemplo n.º 3
0
// Run the helper process which TestSignals spawns.
func runHelperProcess() {
	cnfMap := map[string]string{
		conf.HTRACE_LOG_LEVEL: "TRACE",
		conf.HTRACE_LOG_PATH:  "", // log to stdout
	}
	cnfBld := conf.Builder{Values: cnfMap, Defaults: conf.DEFAULTS}
	cnf, err := cnfBld.Build()
	if err != nil {
		fmt.Printf("Error building configuration: %s\n", err.Error())
		os.Exit(1)
	}
	InstallSignalHandlers(cnf)
	fmt.Fprintf(os.Stderr, "Signal handler installed.\n")
	// Wait for a signal to be delivered
	for {
		time.Sleep(time.Hour * 100)
	}
}
func TestHeartbeaterSendsHeartbeats(t *testing.T) {
	cnfBld := conf.Builder{
		Values:   conf.TEST_VALUES(),
		Defaults: conf.DEFAULTS,
	}
	cnf, err := cnfBld.Build()
	if err != nil {
		t.Fatalf("failed to create conf: %s", err.Error())
	}
	lg := common.NewLogger("heartbeater", cnf)
	// The minimum amount of time which the heartbeater test should take
	MINIMUM_TEST_DURATION := time.Millisecond * (NUM_TEST_HEARTBEATS * HEARTBEATER_PERIOD)
	duration := MINIMUM_TEST_DURATION
	for duration <= MINIMUM_TEST_DURATION {
		start := time.Now()
		testHeartbeaterSendsHeartbeatsImpl(t, lg)
		end := time.Now()
		duration = end.Sub(start)
		lg.Debugf("Measured duration: %v; minimum expected duration: %v\n",
			duration, MINIMUM_TEST_DURATION)
	}
}
Exemplo n.º 5
0
func TestMetricsSinkPerHostEviction(t *testing.T) {
	cnfBld := conf.Builder{
		Values:   conf.TEST_VALUES(),
		Defaults: conf.DEFAULTS,
	}
	cnfBld.Values[conf.HTRACE_METRICS_MAX_ADDR_ENTRIES] = "2"
	cnf, err := cnfBld.Build()
	if err != nil {
		t.Fatalf("failed to create conf: %s", err.Error())
	}
	msink := NewMetricsSink(cnf)
	msink.UpdatePersisted("192.168.0.100", 20, 10)
	msink.UpdatePersisted("192.168.0.101", 20, 10)
	msink.UpdatePersisted("192.168.0.102", 20, 10)
	msink.lock.Lock()
	defer msink.lock.Unlock()
	if len(msink.HostSpanMetrics) != 2 {
		for k, v := range msink.HostSpanMetrics {
			fmt.Printf("WATERMELON: [%s] = [%s]\n", k, v)
		}
		t.Fatalf("Expected len(msink.HostSpanMetrics) to be 2, but got %d\n",
			len(msink.HostSpanMetrics))
	}
}
Exemplo n.º 6
0
func (bld *MiniHTracedBuilder) Build() (*MiniHTraced, error) {
	var err error
	var store *dataStore
	var rsv *RestServer
	var hsv *HrpcServer
	if bld.Name == "" {
		bld.Name = "HTraceTest"
	}
	if bld.Cnf == nil {
		bld.Cnf = make(map[string]string)
	}
	if bld.DataDirs == nil {
		bld.DataDirs = make([]string, 2)
	}
	for idx := range bld.DataDirs {
		if bld.DataDirs[idx] == "" {
			bld.DataDirs[idx], err = ioutil.TempDir(os.TempDir(),
				fmt.Sprintf("%s%d", bld.Name, idx+1))
			if err != nil {
				return nil, err
			}
		}
	}
	// Copy the default test configuration values.
	for k, v := range conf.TEST_VALUES() {
		_, hasVal := bld.Cnf[k]
		if !hasVal {
			bld.Cnf[k] = v
		}
	}
	bld.Cnf[conf.HTRACE_DATA_STORE_DIRECTORIES] =
		strings.Join(bld.DataDirs, conf.PATH_LIST_SEP)
	cnfBld := conf.Builder{Values: bld.Cnf, Defaults: conf.DEFAULTS}
	cnf, err := cnfBld.Build()
	if err != nil {
		return nil, err
	}
	lg := common.NewLogger("mini.htraced", cnf)
	defer func() {
		if err != nil {
			if store != nil {
				store.Close()
			}
			for idx := range bld.DataDirs {
				if !bld.KeepDataDirsOnClose {
					if bld.DataDirs[idx] != "" {
						os.RemoveAll(bld.DataDirs[idx])
					}
				}
			}
			if rsv != nil {
				rsv.Close()
			}
			lg.Infof("Failed to create MiniHTraced %s: %s\n", bld.Name, err.Error())
			lg.Close()
		}
	}()
	store, err = CreateDataStore(cnf, bld.WrittenSpans)
	if err != nil {
		return nil, err
	}
	rstListener, listenErr := net.Listen("tcp", cnf.Get(conf.HTRACE_WEB_ADDRESS))
	if listenErr != nil {
		return nil, listenErr
	}
	defer func() {
		if rstListener != nil {
			rstListener.Close()
		}
	}()
	rsv, err = CreateRestServer(cnf, store, rstListener)
	if err != nil {
		return nil, err
	}
	rstListener = nil
	hsv, err = CreateHrpcServer(cnf, store, bld.HrpcTestHooks)
	if err != nil {
		return nil, err
	}

	lg.Infof("Created MiniHTraced %s\n", bld.Name)
	return &MiniHTraced{
		Name:                bld.Name,
		Cnf:                 cnf,
		DataDirs:            bld.DataDirs,
		Store:               store,
		Rsv:                 rsv,
		Hsv:                 hsv,
		Lg:                  lg,
		KeepDataDirsOnClose: bld.KeepDataDirsOnClose,
	}, nil
}
Exemplo n.º 7
0
func (bld *MiniHTracedBuilder) Build() (*MiniHTraced, error) {
	var err error
	var store *dataStore
	var rsv *RestServer
	var hsv *HrpcServer
	if bld.Name == "" {
		bld.Name = "HTraceTest"
	}
	if bld.Cnf == nil {
		bld.Cnf = make(map[string]string)
	}
	if bld.DataDirs == nil {
		bld.DataDirs = make([]string, 2)
	}
	for idx := range bld.DataDirs {
		if bld.DataDirs[idx] == "" {
			bld.DataDirs[idx], err = ioutil.TempDir(os.TempDir(),
				fmt.Sprintf("%s%d", bld.Name, idx+1))
			if err != nil {
				return nil, err
			}
		}
	}
	bld.Cnf[conf.HTRACE_DATA_STORE_DIRECTORIES] =
		strings.Join(bld.DataDirs, conf.PATH_LIST_SEP)
	bld.Cnf[conf.HTRACE_WEB_ADDRESS] = ":0"  // use a random port for the REST server
	bld.Cnf[conf.HTRACE_HRPC_ADDRESS] = ":0" // use a random port for the HRPC server
	bld.Cnf[conf.HTRACE_LOG_LEVEL] = "TRACE"
	cnfBld := conf.Builder{Values: bld.Cnf, Defaults: conf.DEFAULTS}
	cnf, err := cnfBld.Build()
	if err != nil {
		return nil, err
	}
	lg := common.NewLogger("mini.htraced", cnf)
	defer func() {
		if err != nil {
			if store != nil {
				store.Close()
			}
			for idx := range bld.DataDirs {
				if bld.DataDirs[idx] != "" {
					os.RemoveAll(bld.DataDirs[idx])
				}
			}
			if rsv != nil {
				rsv.Close()
			}
			lg.Infof("Failed to create MiniHTraced %s: %s\n", bld.Name, err.Error())
			lg.Close()
		}
	}()
	store, err = CreateDataStore(cnf, bld.WrittenSpans)
	if err != nil {
		return nil, err
	}
	rsv, err = CreateRestServer(cnf, store)
	if err != nil {
		return nil, err
	}
	hsv, err = CreateHrpcServer(cnf, store)
	if err != nil {
		return nil, err
	}

	lg.Infof("Created MiniHTraced %s\n", bld.Name)
	return &MiniHTraced{
		Name:                bld.Name,
		Cnf:                 cnf,
		DataDirs:            bld.DataDirs,
		Store:               store,
		Rsv:                 rsv,
		Hsv:                 hsv,
		Lg:                  lg,
		KeepDataDirsOnClose: bld.KeepDataDirsOnClose,
	}, nil
}