Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
[distributed sampling] encapsulating response in a container
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoot committed Aug 18, 2017
1 parent 6d6e977 commit 1a3a573
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions agent/receiver_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 1a3a573

Please sign in to comment.