Skip to content

Commit ec8ddc8

Browse files
authored
Ingest node - user agent, move device to an object (#38115) (#38121)
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 54b4020 commit ec8ddc8

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ Which returns
6969
"version": "10.10.5",
7070
"full": "Mac OS X 10.10.5"
7171
},
72-
"device": "Other"
72+
"device" : {
73+
"name" : "Other"
74+
},
7375
}
7476
}
7577
}

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
@@ -139,11 +139,13 @@ public IngestDocument execute(IngestDocument ingestDocument) {
139139
}
140140
break;
141141
case DEVICE:
142+
Map<String, String> deviceDetails = new HashMap<>(1);
142143
if (uaClient.device != null && uaClient.device.name != null) {
143-
uaDetails.put("device", uaClient.device.name);
144+
deviceDetails.put("name", uaClient.device.name);
144145
} else {
145-
uaDetails.put("device", "Other");
146+
deviceDetails.put("name", "Other");
146147
}
148+
uaDetails.put("device", deviceDetails);
147149
break;
148150
}
149151
}

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

Lines changed: 12 additions & 4 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")
@@ -181,6 +187,8 @@ public void testUnknown() throws Exception {
181187

182188
assertNull(target.get("os"));
183189

184-
assertThat(target.get("device"), is("Other"));
190+
Map<String, String> device = new HashMap<>();
191+
device.put("name", "Other");
192+
assertThat(target.get("device"), is(device));
185193
}
186194
}

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
@@ -35,7 +35,7 @@
3535
- 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" }
3636
- match: { _source.user_agent.os: {"name":"Mac OS X", "version":"10.9.2", "full":"Mac OS X 10.9.2"} }
3737
- match: { _source.user_agent.version: "33.0.1750" }
38-
- match: { _source.user_agent.device: "Other" }
38+
- match: { _source.user_agent.device: {"name": "Other" }}
3939

4040
---
4141
"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
@@ -33,6 +33,6 @@
3333
id: 1
3434
- 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" }
3535
- match: { _source.user_agent.name: "Test" }
36-
- match: { _source.user_agent.device: "Other" }
36+
- match: { _source.user_agent.device: {"name": "Other" }}
3737
- is_false: _source.user_agent.os
3838
- is_false: _source.user_agent.version

0 commit comments

Comments
 (0)