From 5c1c048f306bc3a19c8baa2b772cebe89a069253 Mon Sep 17 00:00:00 2001 From: Wiard van Rij Date: Fri, 11 Oct 2024 17:08:08 +0200 Subject: [PATCH 1/3] Change response type for v1 and v2 series to be JSON as part of DD response standard --- receiver/datadogreceiver/receiver.go | 12 ++++++++++-- receiver/datadogreceiver/receiver_test.go | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/receiver/datadogreceiver/receiver.go b/receiver/datadogreceiver/receiver.go index bdfb6b9c53a8..905230e18e27 100644 --- a/receiver/datadogreceiver/receiver.go +++ b/receiver/datadogreceiver/receiver.go @@ -282,8 +282,12 @@ func (ddr *datadogReceiver) handleV1Series(w http.ResponseWriter, req *http.Requ return } + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) - _, _ = w.Write([]byte("OK")) + response := map[string]string{ + "status": "ok", + } + _ = json.NewEncoder(w).Encode(response) } // handleV2Series handles the v2 series endpoint https://docs.datadoghq.com/api/latest/metrics/#submit-metrics @@ -312,8 +316,12 @@ func (ddr *datadogReceiver) handleV2Series(w http.ResponseWriter, req *http.Requ return } + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) - _, _ = w.Write([]byte("OK")) + response := map[string]interface{}{ + "errors": []string{}, + } + _ = json.NewEncoder(w).Encode(response) } // handleCheckRun handles the service checks endpoint https://docs.datadoghq.com/api/latest/service-checks/ diff --git a/receiver/datadogreceiver/receiver_test.go b/receiver/datadogreceiver/receiver_test.go index 9e53fcf43e8f..52c1844b59fe 100644 --- a/receiver/datadogreceiver/receiver_test.go +++ b/receiver/datadogreceiver/receiver_test.go @@ -293,7 +293,7 @@ func TestDatadogMetricsV1_EndToEnd(t *testing.T) { body, err := io.ReadAll(resp.Body) require.NoError(t, multierr.Combine(err, resp.Body.Close()), "Must not error when reading body") - require.Equal(t, "OK", string(body), "Expected response to be 'OK', got %s", string(body)) + require.JSONEq(t, `{"status": "ok"}`, string(body), "Expected JSON response to be `{\"status\": \"ok\"}`, got %s", string(body)) require.Equal(t, http.StatusAccepted, resp.StatusCode) mds := sink.AllMetrics() @@ -371,7 +371,7 @@ func TestDatadogMetricsV2_EndToEnd(t *testing.T) { body, err := io.ReadAll(resp.Body) require.NoError(t, multierr.Combine(err, resp.Body.Close()), "Must not error when reading body") - require.Equal(t, "OK", string(body), "Expected response to be 'OK', got %s", string(body)) + require.JSONEq(t, `{"errors": []}`, string(body), "Expected JSON response to be `{\"errors\": []}`, got %s", string(body)) require.Equal(t, http.StatusAccepted, resp.StatusCode) mds := sink.AllMetrics() From 0ede00d874660f7c55133071e85b9e14f6a3968f Mon Sep 17 00:00:00 2001 From: Wiard van Rij Date: Fri, 11 Oct 2024 17:15:34 +0200 Subject: [PATCH 2/3] add changelog --- .chloggen/wvanrij-dd-receiver-task_35743.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/wvanrij-dd-receiver-task_35743.yaml diff --git a/.chloggen/wvanrij-dd-receiver-task_35743.yaml b/.chloggen/wvanrij-dd-receiver-task_35743.yaml new file mode 100644 index 000000000000..c129aac3da87 --- /dev/null +++ b/.chloggen/wvanrij-dd-receiver-task_35743.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: 'datadogreceiver' + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Changes response message for `/api/v1/series` and `/api/v2/series` 202 response to be JSON and on par with Datadog API spec" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35743] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From f85647e7e26b9ce7ebaa475d35b6495bec8375e9 Mon Sep 17 00:00:00 2001 From: Wiard van Rij Date: Fri, 11 Oct 2024 17:27:17 +0200 Subject: [PATCH 3/3] fmt, interf -> any --- receiver/datadogreceiver/receiver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/datadogreceiver/receiver.go b/receiver/datadogreceiver/receiver.go index 905230e18e27..fb7cae448490 100644 --- a/receiver/datadogreceiver/receiver.go +++ b/receiver/datadogreceiver/receiver.go @@ -318,7 +318,7 @@ func (ddr *datadogReceiver) handleV2Series(w http.ResponseWriter, req *http.Requ w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) - response := map[string]interface{}{ + response := map[string]any{ "errors": []string{}, } _ = json.NewEncoder(w).Encode(response)