Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/v1/logs/SubmitLog_2329487120.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Send deflate logs with explicit compression returns "Response from server (always 200 empty
// JSON)." response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.LogsApi;
import com.datadog.api.client.v1.api.LogsApi.SubmitLogOptionalParameters;
import com.datadog.api.client.v1.model.ContentEncoding;
import com.datadog.api.client.v1.model.HTTPLogItem;
import java.util.Collections;
import java.util.List;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsApi apiInstance = new LogsApi(defaultClient);

List<HTTPLogItem> body =
Collections.singletonList(
new HTTPLogItem().message("Example-Log").ddtags("host:ExampleLog"));

try {
apiInstance.submitLog(
body, new SubmitLogOptionalParameters().contentEncoding(ContentEncoding.DEFLATE));
} catch (ApiException e) {
System.err.println("Exception when calling LogsApi#submitLog");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
33 changes: 33 additions & 0 deletions examples/v1/logs/SubmitLog_348923381.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Send gzip logs with explicit compression returns "Response from server (always 200 empty JSON)."
// response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.LogsApi;
import com.datadog.api.client.v1.api.LogsApi.SubmitLogOptionalParameters;
import com.datadog.api.client.v1.model.ContentEncoding;
import com.datadog.api.client.v1.model.HTTPLogItem;
import java.util.Collections;
import java.util.List;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsApi apiInstance = new LogsApi(defaultClient);

List<HTTPLogItem> body =
Collections.singletonList(
new HTTPLogItem().message("Example-Log").ddtags("host:ExampleLog"));

try {
apiInstance.submitLog(
body, new SubmitLogOptionalParameters().contentEncoding(ContentEncoding.GZIP));
} catch (ApiException e) {
System.err.println("Exception when calling LogsApi#submitLog");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
38 changes: 38 additions & 0 deletions examples/v2/logs/SubmitLog_1695361854.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Send deflate logs with explicit compression returns "Request accepted for processing (always 202
// empty JSON)." response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.LogsApi;
import com.datadog.api.client.v2.api.LogsApi.SubmitLogOptionalParameters;
import com.datadog.api.client.v2.model.ContentEncoding;
import com.datadog.api.client.v2.model.HTTPLogItem;
import java.util.Collections;
import java.util.List;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsApi apiInstance = new LogsApi(defaultClient);

List<HTTPLogItem> body =
Collections.singletonList(
new HTTPLogItem()
.ddsource("nginx")
.ddtags("env:staging,version:5.1")
.hostname("i-012345678")
.message("2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World")
.service("payment"));

try {
apiInstance.submitLog(
body, new SubmitLogOptionalParameters().contentEncoding(ContentEncoding.DEFLATE));
} catch (ApiException e) {
System.err.println("Exception when calling LogsApi#submitLog");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
38 changes: 38 additions & 0 deletions examples/v2/logs/SubmitLog_3804768803.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Send gzip logs with explicit compression returns "Request accepted for processing (always 202
// empty JSON)." response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.LogsApi;
import com.datadog.api.client.v2.api.LogsApi.SubmitLogOptionalParameters;
import com.datadog.api.client.v2.model.ContentEncoding;
import com.datadog.api.client.v2.model.HTTPLogItem;
import java.util.Collections;
import java.util.List;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsApi apiInstance = new LogsApi(defaultClient);

List<HTTPLogItem> body =
Collections.singletonList(
new HTTPLogItem()
.ddsource("nginx")
.ddtags("env:staging,version:5.1")
.hostname("i-012345678")
.message("2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World")
.service("payment"));

try {
apiInstance.submitLog(
body, new SubmitLogOptionalParameters().contentEncoding(ContentEncoding.GZIP));
} catch (ApiException e) {
System.err.println("Exception when calling LogsApi#submitLog");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
12 changes: 12 additions & 0 deletions src/test/java/com/datadog/api/RecorderSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.cucumber.java.BeforeAll;
import io.cucumber.java.Scenario;
import io.cucumber.java.Status;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -197,6 +199,16 @@ public String getCassetteName() {
return world.getName() + ".json";
}

@Then("the request uses {string} compression")
public void theRequestUsesCompression(String compression) throws Exception {
TestRunner.assertLastRequestContentEncoding(world, compression);
}

@Given("the client selects {string} compression")
public void theClientSelectsCompression(String compression) {
// The generated request plan passes the selected compression to the client call.
}

@When("the request is sent")
public void theRequestIsSent() throws Exception {
TestRunner.applyPlan(world, false);
Expand Down
36 changes: 34 additions & 2 deletions src/test/java/com/datadog/api/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ public static void stopSession(World world) throws Exception {
world.testServerSession = null;
}

@SuppressWarnings("unchecked")
public static void assertLastRequestContentEncoding(World world, String expected)
throws Exception {
if (!serverEnabled()) {
return;
}
if (world.testServerSession == null) {
throw new IllegalStateException("Generated test-server session has not been started");
}
Map<String, Object> result =
controlRequest("GET", "/sessions/" + world.testServerSession + "/last-request", null);
Map<String, Object> request = (Map<String, Object>) result.get("request");
if (request == null) {
throw new AssertionError("Generated test server has not received a request");
}
Map<String, Object> headers = (Map<String, Object>) request.get("headers");
String actual = headers == null ? null : (String) headers.get("content-encoding");
if (actual == null || !actual.equalsIgnoreCase(expected)) {
throw new AssertionError(
String.format("Expected Content-Encoding %s, got %s", expected, actual));
}
}

public static void applyPlan(World world, boolean pagination) throws Exception {
if (!runnerEnabled()) {
return;
Expand Down Expand Up @@ -167,6 +190,10 @@ public static void applyPlan(World world, boolean pagination) throws Exception {
Object value = materialize(body.get("value"), world);
world.addMaterializedRequestParameter("body", MAPPER.writeValueAsString(value));
}
if (request.get("selected_compression") != null) {
world.addMaterializedRequestParameter(
"Content-Encoding", MAPPER.writeValueAsString(request.get("selected_compression")));
}
for (Map<String, Object> parameter : parameters) {
if (!"path".equals(parameter.get("in")) && !Boolean.TRUE.equals(parameter.get("required"))) {
applyParameter(world, parameter);
Expand Down Expand Up @@ -254,9 +281,14 @@ private static Map<String, Object> readMap(Path path) throws Exception {

private static Map<String, Object> controlRequest(String endpoint, Map<String, Object> payload)
throws Exception {
return controlRequest("POST", endpoint, payload);
}

private static Map<String, Object> controlRequest(
String method, String endpoint, Map<String, Object> payload) throws Exception {
URL url = new URL(serverUrl() + CONTROL_ROOT + endpoint);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestMethod(method);
connection.setRequestProperty("Connection", "close");
if (payload != null) {
byte[] body = MAPPER.writeValueAsBytes(payload);
Expand All @@ -283,7 +315,7 @@ private static Map<String, Object> controlRequest(String endpoint, Map<String, O
}
if (status >= HttpURLConnection.HTTP_BAD_REQUEST) {
throw new IllegalStateException(
String.format("Test server POST %s failed (%d): %s", endpoint, status, response));
String.format("Test server %s %s failed (%d): %s", method, endpoint, status, response));
}
return MAPPER.readValue(response.toString(), new TypeReference<Map<String, Object>>() {});
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/resources/com/datadog/api/client/v1/api/logs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ Feature: Logs
When the request is sent
Then the response status is 200 Response from server (always 200 empty JSON).

@skip-terraform-config @skip-validation @team:DataDog/event-platform-intake
Scenario: Send deflate logs with explicit compression returns "Response from server (always 200 empty JSON)." response
Given new "SubmitLog" request
And body with value [{"message": "{{ unique }}", "ddtags": "host:{{ unique_alnum }}"}]
And the client selects "deflate" compression
When the request is sent
Then the response status is 200 Response from server (always 200 empty JSON).
And the request uses "deflate" compression

@integration-only @skip-terraform-config @skip-validation @team:DataDog/event-platform-intake
Scenario: Send gzip logs returns "Response from server (always 200 empty JSON)." response
Given new "SubmitLog" request
Expand All @@ -48,6 +57,15 @@ Feature: Logs
When the request is sent
Then the response status is 200 Response from server (always 200 empty JSON).

@skip-terraform-config @skip-validation @team:DataDog/event-platform-intake
Scenario: Send gzip logs with explicit compression returns "Response from server (always 200 empty JSON)." response
Given new "SubmitLog" request
And body with value [{"message": "{{ unique }}", "ddtags": "host:{{ unique_alnum }}"}]
And the client selects "gzip" compression
When the request is sent
Then the response status is 200 Response from server (always 200 empty JSON).
And the request uses "gzip" compression

@team:DataDog/event-platform-intake
Scenario: Send logs returns "Response from server (always 200 empty JSON)." response
Given new "SubmitLog" request
Expand Down
18 changes: 18 additions & 0 deletions src/test/resources/com/datadog/api/client/v2/api/logs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ Feature: Logs
When the request is sent
Then the response status is 202 Response from server (always 202 empty JSON).

@skip-terraform-config @skip-validation @team:DataDog/event-platform-intake @team:DataDog/logs-backend @team:DataDog/logs-ingestion
Scenario: Send deflate logs with explicit compression returns "Request accepted for processing (always 202 empty JSON)." response
Given new "SubmitLog" request
And body with value [{"ddsource": "nginx", "ddtags": "env:staging,version:5.1", "hostname": "i-012345678", "message": "2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World", "service": "payment"}]
And the client selects "deflate" compression
When the request is sent
Then the response status is 202 Response from server (always 202 empty JSON).
And the request uses "deflate" compression

@integration-only @skip-terraform-config @skip-validation @team:DataDog/event-platform-intake @team:DataDog/logs-backend @team:DataDog/logs-ingestion
Scenario: Send gzip logs returns "Request accepted for processing (always 202 empty JSON)." response
Given new "SubmitLog" request
Expand All @@ -144,6 +153,15 @@ Feature: Logs
When the request is sent
Then the response status is 202 Request accepted for processing (always 202 empty JSON).

@skip-terraform-config @skip-validation @team:DataDog/event-platform-intake @team:DataDog/logs-backend @team:DataDog/logs-ingestion
Scenario: Send gzip logs with explicit compression returns "Request accepted for processing (always 202 empty JSON)." response
Given new "SubmitLog" request
And body with value [{"ddsource": "nginx", "ddtags": "env:staging,version:5.1", "hostname": "i-012345678", "message": "2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World", "service": "payment"}]
And the client selects "gzip" compression
When the request is sent
Then the response status is 202 Request accepted for processing (always 202 empty JSON).
And the request uses "gzip" compression

@generated @skip @team:DataDog/event-platform-intake @team:DataDog/logs-backend @team:DataDog/logs-ingestion
Scenario: Send logs returns "Bad Request" response
Given new "SubmitLog" request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,20 @@
"scenario": "Search test logs returns \"OK\" response",
"version": "v1"
},
{
"feature": "Logs",
"feature_file": "../../com/datadog/api/client/v1/api/logs.feature",
"file": "v1/logs/send-deflate-logs-with-explicit-compression-returns-response-from-server-always-200-empty-json-response.json",
"scenario": "Send deflate logs with explicit compression returns \"Response from server (always 200 empty JSON).\" response",
"version": "v1"
},
{
"feature": "Logs",
"feature_file": "../../com/datadog/api/client/v1/api/logs.feature",
"file": "v1/logs/send-gzip-logs-with-explicit-compression-returns-response-from-server-always-200-empty-json-response.json",
"scenario": "Send gzip logs with explicit compression returns \"Response from server (always 200 empty JSON).\" response",
"version": "v1"
},
{
"feature": "Logs",
"feature_file": "../../com/datadog/api/client/v1/api/logs.feature",
Expand Down Expand Up @@ -6391,6 +6405,20 @@
"scenario": "Search logs returns \"OK\" response with pagination",
"version": "v2"
},
{
"feature": "Logs",
"feature_file": "../../com/datadog/api/client/v2/api/logs.feature",
"file": "v2/logs/send-deflate-logs-with-explicit-compression-returns-request-accepted-for-processing-always-202-empty-json-response.json",
"scenario": "Send deflate logs with explicit compression returns \"Request accepted for processing (always 202 empty JSON).\" response",
"version": "v2"
},
{
"feature": "Logs",
"feature_file": "../../com/datadog/api/client/v2/api/logs.feature",
"file": "v2/logs/send-gzip-logs-with-explicit-compression-returns-request-accepted-for-processing-always-202-empty-json-response.json",
"scenario": "Send gzip logs with explicit compression returns \"Request accepted for processing (always 202 empty JSON).\" response",
"version": "v2"
},
{
"feature": "Logs",
"feature_file": "../../com/datadog/api/client/v2/api/logs.feature",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"api": "Logs",
"expected_status": 200,
"feature": "Logs",
"id": "v1/Logs/Send deflate logs with explicit compression returns \"Response from server (always 200 empty JSON).\" response",
"operation_id": "SubmitLog",
"request": {
"body": {
"schema": {
"format": null,
"items": {
"format": null,
"ref": "HTTPLogItem",
"type": "object"
},
"ref": "HTTPLog",
"type": "array"
},
"source": "inline",
"value": [
{
"ddtags": "host:{{ unique_alnum }}",
"message": "{{ unique }}"
}
]
},
"content_type": "application/json",
"method": "POST",
"pagination": false,
"parameters": [],
"path": "/v1/input",
"selected_compression": "deflate"
},
"scenario": "Send deflate logs with explicit compression returns \"Response from server (always 200 empty JSON).\" response",
"schema_version": 1,
"version": "v1"
}
Loading
Loading