Skip to content

Commit 5b008a3

Browse files
authored
Ingest node - user agent, move device to an object (#38115)
When the ingest node user agent parses the device field, it will result in a string value. To match the ecs schema this commit moves the value of the parsed device to an object with an inner field named 'name'. There are not any passivity concerns since this modifies an unreleased change. closes #38094 relates #37329
1 parent 91b79eb commit 5b008a3

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

docs/reference/ingest/processors/user-agent.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ Which returns
6767
"version": "10.10.5",
6868
"full": "Mac OS X 10.10.5"
6969
},
70-
"device": "Other"
70+
"device" : {
71+
"name" : "Other"
72+
},
7173
}
7274
}
7375
}

modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ public IngestDocument execute(IngestDocument ingestDocument) {
134134
}
135135
break;
136136
case DEVICE:
137+
Map<String, String> deviceDetails = new HashMap<>(1);
137138
if (uaClient.device != null && uaClient.device.name != null) {
138-
uaDetails.put("device", uaClient.device.name);
139+
deviceDetails.put("name", uaClient.device.name);
139140
} else {
140-
uaDetails.put("device", "Other");
141+
deviceDetails.put("name", "Other");
141142
}
143+
uaDetails.put("device", deviceDetails);
142144
break;
143145
}
144146
}

modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public void testCommonBrowser() throws Exception {
110110
os.put("version", "10.9.2");
111111
os.put("full", "Mac OS X 10.9.2");
112112
assertThat(target.get("os"), is(os));
113-
assertThat(target.get("device"), is("Other"));
113+
Map<String, String> device = new HashMap<>();
114+
device.put("name", "Other");
115+
assertThat(target.get("device"), is(device));
114116
}
115117

116118
@SuppressWarnings("unchecked")
@@ -136,7 +138,9 @@ public void testUncommonDevice() throws Exception {
136138
os.put("full", "Android 3.0");
137139
assertThat(target.get("os"), is(os));
138140

139-
assertThat(target.get("device"), is("Motorola Xoom"));
141+
Map<String, String> device = new HashMap<>();
142+
device.put("name", "Motorola Xoom");
143+
assertThat(target.get("device"), is(device));
140144
}
141145

142146
@SuppressWarnings("unchecked")
@@ -157,7 +161,9 @@ public void testSpider() throws Exception {
157161
assertNull(target.get("version"));
158162
assertNull(target.get("os"));
159163

160-
assertThat(target.get("device"), is("Spider"));
164+
Map<String, String> device = new HashMap<>();
165+
device.put("name", "Spider");
166+
assertThat(target.get("device"), is(device));
161167
}
162168

163169
@SuppressWarnings("unchecked")
@@ -180,7 +186,8 @@ public void testUnknown() throws Exception {
180186
assertNull(target.get("build"));
181187

182188
assertNull(target.get("os"));
183-
184-
assertThat(target.get("device"), is("Other"));
189+
Map<String, String> device = new HashMap<>();
190+
device.put("name", "Other");
191+
assertThat(target.get("device"), is(device));
185192
}
186193
}

modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/20_useragent_processor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
- match: { _source.user_agent.original: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" }
3333
- match: { _source.user_agent.os: {"name":"Mac OS X", "version":"10.9.2", "full":"Mac OS X 10.9.2"} }
3434
- match: { _source.user_agent.version: "33.0.1750" }
35-
- match: { _source.user_agent.device: "Other" }
35+
- match: { _source.user_agent.device: {"name": "Other" }}
3636

3737
---
3838
"Test user agent processor with parameters":

modules/ingest-user-agent/src/test/resources/rest-api-spec/test/ingest-useragent/30_custom_regex.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
id: 1
3131
- match: { _source.field1: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" }
3232
- match: { _source.user_agent.name: "Test" }
33-
- match: { _source.user_agent.device: "Other" }
33+
- match: { _source.user_agent.device: {"name": "Other" }}
3434
- is_false: _source.user_agent.os
3535
- is_false: _source.user_agent.version

0 commit comments

Comments
 (0)