Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 220_logs_default_pipeline.yml with java rest test (#99764) #100014

Merged
merged 2 commits into from
Oct 5, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesRegex;

public class LogsDataStreamIT extends DisabledSecurityDataStreamTestCase {

Expand Down Expand Up @@ -100,6 +101,108 @@ public void testDefaultLogsSettingAndMapping() throws Exception {
}
}

@SuppressWarnings("unchecked")
public void testLogsDefaultPipeline() throws Exception {
RestClient client = client();
waitForLogs(client);

{
Request request = new Request("POST", "/_component_template/logs@custom");
request.setJsonEntity("""
{
"template": {
"mappings": {
"properties": {
"custom_timestamp": {
"type": "date"
}
}
}
}
}
""");
assertOK(client.performRequest(request));
}
{
Request request = new Request("PUT", "/_ingest/pipeline/logs@custom");
request.setJsonEntity("""
{
"processors": [
{
"set" : {
"field": "custom_timestamp",
"copy_from": "_ingest.timestamp"
}
}
]
}
""");
assertOK(client.performRequest(request));
}

String dataStreamName = "logs-generic-default";
createDataStream(client, dataStreamName);
String backingIndex = getWriteBackingIndex(client, dataStreamName);

// Verify mapping from custom logs
Map<String, Object> mappingProperties = getMappingProperties(client, backingIndex);
assertThat(((Map<String, Object>) mappingProperties.get("@timestamp")).get("type"), equalTo("date"));

// no timestamp - testing default pipeline's @timestamp set processor
{
indexDoc(client, dataStreamName, """
{
"message": "no_timestamp"
}
""");
List<Object> results = searchDocs(client, dataStreamName, """
{
"query": {
"term": {
"message": {
"value": "no_timestamp"
}
}
},
"fields": ["@timestamp", "custom_timestamp"]
}
""");
Map<String, Object> source = ((Map<String, Map<String, Object>>) results.get(0)).get("_source");
String timestamp = (String) source.get("@timestamp");
assertThat(timestamp, matchesRegex("[0-9-]+T[0-9:.]+Z"));
assertThat(source.get("custom_timestamp"), is(timestamp));

Map<String, Object> fields = ((Map<String, Map<String, Object>>) results.get(0)).get("fields");
timestamp = ((List<String>) fields.get("@timestamp")).get(0);
assertThat(timestamp, matchesRegex("[0-9-]+T[0-9:.]+Z"));
assertThat(((List<Object>) fields.get("custom_timestamp")).get(0), is(timestamp));
}

// verify that when a document is ingested with a timestamp, it does not get overridden
{
indexDoc(client, dataStreamName, """
{
"message": "with_timestamp",
"@timestamp": "2023-05-10"
}
""");
List<Object> results = searchDocs(client, dataStreamName, """
{
"query": {
"term": {
"message": {
"value": "with_timestamp"
}
}
},
"fields": ["@timestamp", "custom_timestamp"]
}
""");
Map<String, Object> fields = ((Map<String, Map<String, Object>>) results.get(0)).get("fields");
assertThat(fields.get("@timestamp"), is(List.of("2023-05-10T00:00:00.000Z")));
}
}

private static void waitForLogs(RestClient client) throws Exception {
assertBusy(() -> {
try {
Expand Down

This file was deleted.