func TestHealthD(t *testing.T) { // Make two sinks: sink := health.NewJsonPollingSink(time.Minute, time.Minute*5) sink.StartServer(":6050") sink.EmitEvent("foo", "bar", nil) sink.EmitTiming("foo", "baz", 1234, nil) sink.EmitComplete("foo", health.Success, 5678, nil) sink2 := health.NewJsonPollingSink(time.Minute, time.Minute*5) sink2.StartServer(":6051") sink2.EmitEvent("foo", "bar", nil) sink2.EmitTiming("foo", "baz", 4321, nil) sink2.EmitComplete("foo", health.ValidationError, 8765, nil) hd := StartNewHealthD([]string{":6050", ":6051"}, ":6060", health.NewStream()) defer func() { hd.Stop() time.Sleep(time.Millisecond) }() time.Sleep(time.Millisecond * 15) testAggregations(t, hd) testAggregationsOverall(t, hd) testJobs(t, hd) testHosts(t, hd) }
// nice to have's // - handle the case when time goes backwards. // - we need some way to not return all data from clients on every request. Necessary? func main() { // Get inputs. Read from env variables for now (command line options?) monitoredHostPorts := getMonitoredHostPorts() serverHostPort := getServerHostPort() healthHostPort := getHealthHostPort() // Monitor ourselves. This will make our own instrumentation show up in the healthd output // I'm not totally sure we want to do this, but (shrug) seems reasonable right now. monitoredHostPorts = append(monitoredHostPorts, healthHostPort) // Setup our health stream. // Log to stdout and a setup an polling sink stream := health.NewStream() stream.AddSink(&health.WriterSink{os.Stdout}) jsonPollingSink := health.NewJsonPollingSink(time.Minute, time.Minute*5) jsonPollingSink.StartServer(healthHostPort) stream.AddSink(jsonPollingSink) // Say we're starting! stream.EventKv("starting", health.Kvs{ "monitored_host_ports": strings.Join(monitoredHostPorts, ","), "server_host_port": serverHostPort, "health_host_port": healthHostPort, }) // Start the healthd aggregators in a goroutine(s) healthd.StartNewHealthD(monitoredHostPorts, serverHostPort, stream) // Block select {} }