From 1a3a573fe468334af3fd0e07e60018e6cb966177 Mon Sep 17 00:00:00 2001 From: "Christian Mauduit (DataDog)" Date: Fri, 18 Aug 2017 15:03:50 +0200 Subject: [PATCH] [distributed sampling] encapsulating response in a container --- agent/receiver_responses.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/agent/receiver_responses.go b/agent/receiver_responses.go index e746287f0..af779ce47 100644 --- a/agent/receiver_responses.go +++ b/agent/receiver_responses.go @@ -15,6 +15,13 @@ const ( receiverErrorKey = "datadog.trace_agent.receiver.error" ) +// We encaspulate the answers in a container, this is to ease-up transition, +// should we add another fied. +type traceResponse struct { + // All the sampling rates recommended, by service + rates map[string]float64 `json:"rate_by_service"` +} + // HTTPFormatError is used for payload format errors func HTTPFormatError(tags []string, w http.ResponseWriter) { tags = append(tags, "error:format-error") @@ -56,9 +63,11 @@ func HTTPOK(w http.ResponseWriter) { // HTTPRateByService outputs, as a JSON, the recommended sampling rates for all services. func HTTPRateByService(w http.ResponseWriter, rates *sampler.RateByService) { w.WriteHeader(http.StatusOK) - allRates := rates.GetAll() // this is thread-safe + response := traceResponse{ + rates: rates.GetAll(), // this is thread-safe + } encoder := json.NewEncoder(w) - if err := encoder.Encode(allRates); err != nil { + if err := encoder.Encode(response); err != nil { tags := []string{"error:response-error"} statsd.Client.Count(receiverErrorKey, 1, tags, 1) }