Skip to content

Commit 7208fce

Browse files
committed
Applying review suggestions
1 parent c807dc1 commit 7208fce

2 files changed

Lines changed: 31 additions & 22 deletions

File tree

docs/reference/enrich-processor/normalize-for-stream.md

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,15 @@ For example, if the `message` field is an ECS-JSON, as follows:
168168
```json
169169
{
170170
"@timestamp": "2023-10-01T12:00:00Z",
171-
"message": {
172-
"@timestamp": "2023-10-02T12:00:00Z",
173-
"log.level": "INFO",
174-
"service.name": "my-service",
175-
"message": "The actual log message",
176-
"http": {
177-
"method": "GET",
178-
"url": {
179-
"path": "/api/v1/resource"
180-
}
181-
}
182-
}
171+
"message": "{\"@timestamp\":\"2023-10-01T12:01:00Z\",\"log.level\":\"INFO\",\"service.name\":\"my-service\",\"message\":\"The actual log message\",\"http\":{\"method\":\"GET\",\"url\":{\"path\":\"/api/v1/resource\"}}}"
172+
183173
}
184174
```
185175
it will be normalized into the following form:
186176

187177
```json
188178
{
189-
"@timestamp": "2023-10-02T12:00:00Z",
179+
"@timestamp": "2023-10-01T12:01:00Z",
190180
"severity_text": "INFO",
191181
"body": {
192182
"text": "The actual log message"
@@ -215,15 +205,7 @@ However, if the `message` field is not recognized as ECS format, as follows:
215205
"name": "my-service"
216206
},
217207
"tags": ["user-action", "api-call"],
218-
"message": {
219-
"root_cause": "Network error",
220-
"http": {
221-
"method": "GET",
222-
"url": {
223-
"path": "/api/v1/resource"
224-
}
225-
}
226-
}
208+
"message": "{\"root_cause\":\"Network error\",\"http\":{\"method\":\"GET\",\"url\":{\"path\":\"/api/v1/resource\"}}}"
227209
}
228210
```
229211
it will be normalized into the following form:

modules/ingest-otel/src/test/java/org/elasticsearch/ingest/otel/NormalizeForStreamProcessorTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,33 @@ public void testExecute_nonEcsJsonMessageNormalization() throws IOException {
606606
assertEquals(message, get(get(result, "body"), "structured"));
607607
}
608608

609+
@SuppressWarnings("unchecked")
610+
public void testOtherPrimitiveMessage() {
611+
Map<String, Object> source = new HashMap<>();
612+
source.put("message", 42);
613+
IngestDocument document = new IngestDocument("index", "id", 1, null, null, source);
614+
615+
processor.execute(document);
616+
617+
Map<String, Object> result = document.getSource();
618+
assertEquals(42, ((Map<String, Object>) result.get("body")).get("text"));
619+
}
620+
621+
@SuppressWarnings("unchecked")
622+
public void testObjectMessage() {
623+
Map<String, Object> source = new HashMap<>();
624+
Map<String, Object> message = new HashMap<>();
625+
message.put("key1", "value1");
626+
message.put("key2", "value2");
627+
source.put("message", message);
628+
IngestDocument document = new IngestDocument("index", "id", 1, null, null, source);
629+
630+
processor.execute(document);
631+
632+
Map<String, Object> result = document.getSource();
633+
assertEquals(message, ((Map<String, Object>) result.get("body")).get("text"));
634+
}
635+
609636
private static String representJsonAsString(Map<String, Object> json) throws IOException {
610637
try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) {
611638
return Strings.toString(xContentBuilder.map(json));

0 commit comments

Comments
 (0)