Skip to content

Commit

Permalink
[Hearbteat]Set expected url format in case of parsing error (#37255) (#…
Browse files Browse the repository at this point in the history
…37288)

URL mappings expect an object type, whereas heartbeat is setting it as a string in case of a parsing error. Fix that by appending url.full with the faulty url.

(cherry picked from commit cdb006d)

Co-authored-by: Emilio Alvarez Piñeiro <[email protected]>
  • Loading branch information
mergify[bot] and emilioalvap authored Dec 4, 2023
1 parent 2de1337 commit 43709cc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
*Heartbeat*

- Fix panics when parsing dereferencing invalid parsed url. {pull}34702[34702]
- Fix mapping errors with invalid urls. {pull}37255[37255]

*Metricbeat*

Expand Down
1 change: 1 addition & 0 deletions x-pack/heartbeat/monitors/browser/synthexec/synthtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (se SynthEvent) ToMap() (m mapstr.M) {
if se.URL != "" {
u, e := url.Parse(se.URL)
if e != nil {
_, _ = m.Put("url", mapstr.M{"full": se.URL})
logp.L().Warn("Could not parse synthetics URL '%s': %s", se.URL, e.Error())
} else {
_, _ = m.Put("url", wraputil.URLFields(u))
Expand Down
25 changes: 25 additions & 0 deletions x-pack/heartbeat/monitors/browser/synthexec/synthtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ func TestToMap(t *testing.T) {
"truly_at_root": "v2",
},
},
{
"root fields with invalid URL",
mapstr.M{
"type": JourneyStart,
"package_version": "1.2.3",
"root_fields": map[string]interface{}{
"synthetics": map[string]interface{}{
"nested": "v1",
},
"truly_at_root": "v2",
},
"url": "https://{example}.com",
},
mapstr.M{
"synthetics": mapstr.M{
"type": JourneyStart,
"package_version": "1.2.3",
"nested": "v1",
},
"url": mapstr.M{
"full": "https://{example}.com",
},
"truly_at_root": "v2",
},
},
{
"root fields, step metadata",
mapstr.M{
Expand Down

0 comments on commit 43709cc

Please sign in to comment.