diff --git a/crossdock/docker-compose.yml b/crossdock/docker-compose.yml index 59707a96d07..a476f075f58 100644 --- a/crossdock/docker-compose.yml +++ b/crossdock/docker-compose.yml @@ -55,6 +55,7 @@ services: - "8080" environment: - JAEGER_COLLECTOR_HC_HOST_PORT=jaeger-collector:${JAEGER_COLLECTOR_HC_PORT} + - JAEGER_COLLECTOR_HOST_PORT=jaeger-collector:${JAEGER_COLLECTOR_HOST_PORT} depends_on: - jaeger-query - jaeger-collector diff --git a/crossdock/main.go b/crossdock/main.go index 531ef0fc630..f4833886a42 100644 --- a/crossdock/main.go +++ b/crossdock/main.go @@ -19,9 +19,8 @@ import ( const ( behaviorEndToEnd = "endtoend" - envAgentHostPort = "JAEGER_AGENT_HOST_PORT" - envQueryHostPort = "JAEGER_QUERY_HOST_PORT" - + envCollectorSamplingHostPort = "JAEGER_COLLECTOR_HOST_PORT" + envQueryHostPort = "JAEGER_QUERY_HOST_PORT" envQueryHealthcheckHostPort = "JAEGER_QUERY_HC_HOST_PORT" envCollectorHealthcheckHostPort = "JAEGER_COLLECTOR_HC_HOST_PORT" ) @@ -29,9 +28,8 @@ const ( var ( logger, _ = zap.NewDevelopment() - agentHostPort string - queryHostPort string - + collectorSamplingHostPort string + queryHostPort string queryHealthcheckHostPort string collectorHealthcheckHostPort string ) @@ -44,7 +42,7 @@ type clientHandler struct { } func main() { - agentHostPort = getEnv(envAgentHostPort, "jaeger-agent:5778") + collectorSamplingHostPort = getEnv(envCollectorSamplingHostPort, "jaeger-collector:14268") queryHostPort = getEnv(envQueryHostPort, "jaeger-query:16686") queryHealthcheckHostPort = getEnv(envQueryHealthcheckHostPort, "jaeger-query:16687") collectorHealthcheckHostPort = getEnv(envCollectorHealthcheckHostPort, "jaeger-collector:14269") @@ -78,9 +76,9 @@ func (h *clientHandler) initialize() { httpHealthCheck(logger, "jaeger-collector", "http://"+collectorHealthcheckHostPort) queryService := services.NewQueryService("http://"+queryHostPort, logger) - agentService := services.NewAgentService("http://"+agentHostPort, logger) + collectorService := services.NewCollectorService("http://"+collectorSamplingHostPort, logger) - traceHandler := services.NewTraceHandler(queryService, agentService, logger) + traceHandler := services.NewTraceHandler(queryService, collectorService, logger) behaviors := crossdock.Behaviors{ behaviorEndToEnd: traceHandler.EndToEndTest, } diff --git a/crossdock/services/agent.go b/crossdock/services/agent.go index 126ad17f429..6104ae74a5a 100644 --- a/crossdock/services/agent.go +++ b/crossdock/services/agent.go @@ -18,30 +18,36 @@ import ( var errSamplingRateMissing = errors.New("sampling rate is missing") -// AgentService is the service used to report traces to the collector. -type AgentService interface { +// CollectorService is the service used to report traces to the collector. +type CollectorService interface { GetSamplingRate(service, operation string) (float64, error) } -type agentService struct { +type collectorService struct { url string logger *zap.Logger } -// NewAgentService returns an instance of AgentService. -func NewAgentService(url string, logger *zap.Logger) AgentService { - return &agentService{ +// NewCollectorService returns an instance of CollectorService. +func NewCollectorService(url string, logger *zap.Logger) CollectorService { + logger.Info("Initializing Collector Service", + zap.String("url", url)) + return &collectorService{ url: url, logger: logger, } } func getSamplingURL(url string) string { - return url + "/sampling?service=%s" + return url + "/api/sampling?service=%s" } // GetSamplingRate returns the sampling rate for the service-operation from the agent service. -func (s *agentService) GetSamplingRate(service, operation string) (float64, error) { +func (s *collectorService) GetSamplingRate(service, operation string) (float64, error) { + s.logger.Info("Getting sampling rate", + zap.String("url", s.url), + zap.String("service", service), + zap.String("operation", operation)) url := fmt.Sprintf(getSamplingURL(s.url), getTracerServiceName(service)) resp, err := http.Get(url) if err != nil { @@ -52,7 +58,7 @@ func (s *agentService) GetSamplingRate(service, operation string) (float64, erro if err != nil { return 0, err } - s.logger.Info("Retrieved sampling rates from agent", zap.String("body", string(body))) + s.logger.Info("Retrieved sampling rates from collector", zap.String("body", string(body))) response, err := p2json.SamplingStrategyResponseFromJSON(body) if err != nil { diff --git a/crossdock/services/agent_test.go b/crossdock/services/agent_test.go index ac1099a0756..98dbf8e0995 100644 --- a/crossdock/services/agent_test.go +++ b/crossdock/services/agent_test.go @@ -52,10 +52,14 @@ func TestGetSamplingRateInternal(t *testing.T) { } } -type testAgentHandler struct{} +type testAgentHandler struct { + logger *zap.Logger +} -func (*testAgentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func (h *testAgentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { svc := r.FormValue("service") + h.logger.Info("Handling sampling request", + zap.String("service", svc)) body := []byte("bad json") if svc == "crossdock-svc" { response := api_v2.SamplingStrategyResponse{ @@ -77,16 +81,19 @@ func (*testAgentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func TestGetSamplingRate(t *testing.T) { - handler := &testAgentHandler{} + logger := zap.NewExample() + handler := &testAgentHandler{logger: logger} server := httptest.NewServer(handler) defer server.Close() // Test with no http server - agent := NewAgentService("", zap.NewNop()) + agent := NewCollectorService("", zap.NewNop()) _, err := agent.GetSamplingRate("svc", "op") require.Error(t, err) - agent = NewAgentService(server.URL, zap.NewNop()) + agent = NewCollectorService(server.URL, zap.NewNop()) + logger.Info("Testing with mock server", + zap.String("url", server.URL)) rate, err := agent.GetSamplingRate("svc", "op") require.NoError(t, err) assert.InDelta(t, 1.0, rate, 0.01) @@ -100,7 +107,7 @@ func TestGetSamplingRateReadAllErr(t *testing.T) { w.Header().Set("Content-Length", "1") })) defer server.Close() - agent := NewAgentService(server.URL, zap.NewNop()) + agent := NewCollectorService(server.URL, zap.NewNop()) _, err := agent.GetSamplingRate("svc", "op") require.EqualError(t, err, "unexpected EOF") } diff --git a/crossdock/services/tracehandler.go b/crossdock/services/tracehandler.go index 0b386781bf1..e2eb54c60bb 100644 --- a/crossdock/services/tracehandler.go +++ b/crossdock/services/tracehandler.go @@ -46,7 +46,7 @@ type testFunc func(service string, request *traceRequest) ([]*ui.Trace, error) // TraceHandler handles creating traces and verifying them type TraceHandler struct { query QueryService - agent AgentService + agent CollectorService logger *zap.Logger getClientURL func(service string) string getTags func() map[string]string @@ -57,7 +57,7 @@ type TraceHandler struct { } // NewTraceHandler returns a TraceHandler that can create traces and verify them -func NewTraceHandler(query QueryService, agent AgentService, logger *zap.Logger) *TraceHandler { +func NewTraceHandler(query QueryService, agent CollectorService, logger *zap.Logger) *TraceHandler { return &TraceHandler{ query: query, agent: agent,