Skip to content

Commit 771a844

Browse files
authored
fix(azure.eventhub): handles properties as string and drops empty fields (#14959)
### WHAT - Drops empty/null fields - Renames `azure.eventhub.properties` as `azure.eventhub.properties.raw` when `azure.eventhub.properties` is a string instead of an object. ### WHY **Drops empty/null fields** Sometimes Azure services emit log event like the following: ```json { "category": "NetworkSecurityGroupEvent", "operationName": "NetworkSecurityGroupEvents", "properties": { "conditions": { "": "", "destinationPortRange": "0-65535", "sourcePortRange": "0-65535" }, "direction": "Out", "macAddress": "00-11-22-33-4444", "primaryIPv4Address": "10.0.4.6", "primaryIPv6Address": "ace:ace:dead:beef::9", "priority": 65000, "ruleName": "DefaultRule_AllowVnetOutBound", "subnetPrefix": "10.0.4.0/25", "type": "allow", "vnetResourceGuid": "{a08d316f-3c0a-428d-84ec-2977078852a5}" } } ``` Elasticsearch cannot index `"": ""` field inside `properties.condition`, so we need to clean it up. **Renames `azure.eventhub.properties` as `azure.eventhub.properties.raw` when `azure.eventhub.properties` is a string instead of an object** Sometimes Azure sends `azure.eventhub.properties` as a string, this field should really be a an `object` instead, causing mapping errors like: ```text object mapping for [azure.eventhub.properties] tried to parse field [properties] as object, but found a concrete value ``` By renaming `azure.eventhub.properties` as `azure.eventhub.properties.raw`, we avoid the mapping error and give users the opportunity to handle the original value using a custom pipeline.
1 parent e98f49f commit 771a844

12 files changed

+100
-2
lines changed

packages/azure/changelog.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
- version: "1.28.3"
2+
changes:
3+
- description: Handle invalid log events (empty fields and properties as string) from Azure services.
4+
type: bugfix
5+
link: https://github.com/elastic/integrations/pull/14959
16
- version: "1.28.2"
27
changes:
38
- description: Fix Azure platformlogs ingest pipeline for function app logs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"time":"2025-08-18T22:29:56+02:00", "properties":{"":""}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fields:
2+
tags:
3+
- preserve_original_event
4+
- parse_message
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"expected": [
3+
{
4+
"@timestamp": "2025-08-18T20:29:56.000Z",
5+
"cloud": {
6+
"provider": "azure"
7+
},
8+
"ecs": {
9+
"version": "8.11.0"
10+
},
11+
"event": {
12+
"kind": "event",
13+
"original": "{\"time\":\"2025-08-18T22:29:56+02:00\", \"properties\":{\"\":\"\"}}"
14+
},
15+
"tags": [
16+
"preserve_original_event",
17+
"parse_message"
18+
]
19+
}
20+
]
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"time":"2025-08-18T22:29:56+02:00", "properties": "Usually I'm not a string"}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fields:
2+
tags:
3+
- preserve_original_event
4+
- parse_message
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"expected": [
3+
{
4+
"@timestamp": "2025-08-18T20:29:56.000Z",
5+
"azure": {
6+
"eventhub": {
7+
"properties": {
8+
"raw": "Usually I'm not a string"
9+
}
10+
}
11+
},
12+
"cloud": {
13+
"provider": "azure"
14+
},
15+
"ecs": {
16+
"version": "8.11.0"
17+
},
18+
"event": {
19+
"kind": "event",
20+
"original": "{\"time\":\"2025-08-18T22:29:56+02:00\", \"properties\": \"Usually I'm not a string\"}"
21+
},
22+
"tags": [
23+
"preserve_original_event",
24+
"parse_message"
25+
]
26+
}
27+
]
28+
}

packages/azure/data_stream/eventhub/_dev/test/pipeline/test-eventhub-raw.log-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
]
1414
}
1515
]
16-
}
16+
}

packages/azure/data_stream/eventhub/elasticsearch/ingest_pipeline/parsed-message.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ processors:
1515
- json:
1616
field: event.original
1717
target_field: azure.eventhub
18+
- rename:
19+
field: azure.eventhub.properties
20+
if: "ctx.azure?.eventhub?.properties instanceof String"
21+
target_field: azure.eventhub.properties.raw
22+
ignore_missing: true
23+
description: Rename the field to `properties.raw` to avoid parse errors when `properties` is a string.
1824
- date:
1925
field: azure.eventhub.time
2026
target_field: '@timestamp'
@@ -39,6 +45,23 @@ processors:
3945
params:
4046
param_nano: 1000000
4147
ignore_failure: true
48+
- script:
49+
description: Drops null/empty values recursively.
50+
lang: painless
51+
source: |
52+
boolean dropEmptyFields(Object object) {
53+
if (object == null || object == "") {
54+
return true;
55+
} else if (object instanceof Map) {
56+
((Map) object).values().removeIf(value -> dropEmptyFields(value));
57+
return (((Map) object).size() == 0);
58+
} else if (object instanceof List) {
59+
((List) object).removeIf(value -> dropEmptyFields(value));
60+
return (((List) object).size() == 0);
61+
}
62+
return false;
63+
}
64+
dropEmptyFields(ctx);
4265
- pipeline:
4366
name: '{{ IngestPipeline "azure-shared-pipeline" }}'
4467
ignore_failure: true

packages/azure/data_stream/eventhub/fields/package-fields.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
- name: azure
22
type: group
33
fields:
4+
- name: eventhub
5+
type: group
6+
fields:
7+
- name: properties
8+
type: group
9+
fields:
10+
- name: raw
11+
type: keyword
12+
description: |
13+
Raw properties as a string, if the `properties` field is a string.
414
- name: subscription_id
515
type: keyword
616
description: |

0 commit comments

Comments
 (0)