Skip to content

Commit d3dac62

Browse files
authored
Fix: geo_points can be imported from ECS (#476)
1 parent ea23354 commit d3dac62

File tree

13 files changed

+132
-2
lines changed

13 files changed

+132
-2
lines changed

Diff for: internal/fields/validate.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ func compareKeys(key string, def FieldDefinition, searchedKey string) bool {
265265
k = strings.ReplaceAll(k, "*", "[^.]+")
266266

267267
// Workaround for potential geo_point, as "lon" and "lat" fields are not present in field definitions.
268-
if def.Type == "geo_point" {
269-
k += "\\.(lon|lat)"
268+
// Unfortunately we have to assume that imported field could be a geo_point (nasty workaround).
269+
if def.Type == "geo_point" || def.External != "" {
270+
k += "(\\.lon|\\.lat|)"
270271
}
271272

272273
k = fmt.Sprintf("^%s$", k)

Diff for: internal/fields/validate_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,14 @@ func readSampleEvent(t *testing.T, path string) json.RawMessage {
223223
require.NoError(t, err)
224224
return c
225225
}
226+
227+
func TestValidate_geo_point(t *testing.T) {
228+
validator, err := CreateValidatorForDataStream("../../test/packages/fields_tests/data_stream/first")
229+
230+
require.NoError(t, err)
231+
require.NotNil(t, validator)
232+
233+
e := readSampleEvent(t, "../../test/packages/fields_tests/data_stream/first/sample_event.json")
234+
errs := validator.ValidateDocumentBody(e)
235+
require.Empty(t, errs)
236+
}

Diff for: test/packages/fields_tests/_dev/build/build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies:
2+
ecs:
3+
reference: [email protected]

Diff for: test/packages/fields_tests/_dev/build/docs/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Fields Tests
2+
3+
{{event "first"}}
4+
5+
{{fields "first"}}

Diff for: test/packages/fields_tests/changelog.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# newer versions go on top
2+
- version: "0.0.1"
3+
changes:
4+
- description: Initial draft of the package
5+
type: enhancement
6+
link: https://github.com/elastic/integrations/pull/0 # FIXME Replace with the real PR link
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
paths:
2+
{{#each paths as |path i|}}
3+
- {{path}}
4+
{{/each}}
5+
exclude_files: [".gz$"]
6+
processors:
7+
- add_locale: ~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
description: Pipeline for processing sample logs
3+
processors:
4+
- set:
5+
field: sample_field
6+
value: "1"
7+
on_failure:
8+
- set:
9+
field: error.message
10+
value: '{{ _ingest.on_failure_message }}'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- name: data_stream.type
2+
type: constant_keyword
3+
description: Data stream type.
4+
- name: data_stream.dataset
5+
type: constant_keyword
6+
description: Data stream dataset.
7+
- name: data_stream.namespace
8+
type: constant_keyword
9+
description: Data stream namespace.
10+
- name: '@timestamp'
11+
type: date
12+
description: Event timestamp.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- name: destination.geo.location
2+
external: ecs
3+
- name: geo.location
4+
external: ecs
5+
- name: source.geo.location
6+
external: ecs
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
title: "First"
2+
type: logs
3+
streams:
4+
- input: logfile
5+
title: Sample logs
6+
description: Collect sample logs
7+
vars:
8+
- name: paths
9+
type: text
10+
title: Paths
11+
multi: true
12+
default:
13+
- /var/log/*.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"source.geo.location": {
3+
"lat": 1.0,
4+
"lon": "2.0"
5+
},
6+
"geo.location.lat": 3.0,
7+
"geo.location.lon": 4.0
8+
}

Diff for: test/packages/fields_tests/docs/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Fields Tests
2+
3+
An example event for `first` looks as following:
4+
5+
```json
6+
{
7+
"source.geo.location": {
8+
"lat": 1.0,
9+
"lon": "2.0"
10+
},
11+
"geo.location.lat": 3.0,
12+
"geo.location.lon": 4.0
13+
}
14+
```
15+
16+
**Exported fields**
17+
18+
| Field | Description | Type |
19+
|---|---|---|
20+
| @timestamp | Event timestamp. | date |
21+
| data_stream.dataset | Data stream dataset. | constant_keyword |
22+
| data_stream.namespace | Data stream namespace. | constant_keyword |
23+
| data_stream.type | Data stream type. | constant_keyword |
24+
| destination.geo.location | Longitude and latitude. | geo_point |
25+
| geo.location | Longitude and latitude. | geo_point |
26+
| source.geo.location | Longitude and latitude. | geo_point |

Diff for: test/packages/fields_tests/manifest.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
format_version: 1.0.0
2+
name: fields_tests
3+
title: "Fields Tests"
4+
version: 0.0.1
5+
license: basic
6+
description: "These are tests of field validation."
7+
type: integration
8+
categories:
9+
- custom
10+
release: experimental
11+
conditions:
12+
kibana.version: "^7.15.0"
13+
policy_templates:
14+
- name: sample
15+
title: Sample logs
16+
description: Collect sample logs
17+
inputs:
18+
- type: logfile
19+
title: Collect sample logs from instances
20+
description: Collecting sample logs
21+
owner:
22+
github: elastic/integrations

0 commit comments

Comments
 (0)