Skip to content

Commit

Permalink
[Heartbeat] Added synthetics step status field (#24206)
Browse files Browse the repository at this point in the history
Resolves: #24141

Added synthetics.step.status field and relevant mapping, status originally exists in synthetics.payload.status.
  • Loading branch information
shahzad31 authored Mar 3, 2021
1 parent 024dd5c commit 98a1cf7
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 19 deletions.
2 changes: 2 additions & 0 deletions heartbeat/_meta/fields.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
type: text
- name: index
type: integer
- name: status
type: keyword
- name: journey
type: group
fields:
Expand Down
7 changes: 7 additions & 0 deletions heartbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9783,6 +9783,13 @@ type: integer
--
*`synthetics.step.status`*::
+
--
type: keyword
--
*`synthetics.journey.name`*::
+
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x-pack/heartbeat/include/fields.go

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions x-pack/heartbeat/monitors/browser/synthexec/enrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func TestJourneyEnricher(t *testing.T) {
Journey: journey,
Payload: common.MapStr{},
}
makeStepEvent := func(typ string, ts float64, name string, index int, urlstr string, err *SynthError) *SynthEvent {
makeStepEvent := func(typ string, ts float64, name string, index int, status string, urlstr string, err *SynthError) *SynthEvent {
return &SynthEvent{
Type: typ,
TimestampEpochMicros: 1000 + ts,
PackageVersion: "1.0.0",
Step: &Step{Name: name, Index: index},
Step: &Step{Name: name, Index: index, Status: status},
Error: err,
Payload: common.MapStr{},
URL: urlstr,
Expand All @@ -66,12 +66,12 @@ func TestJourneyEnricher(t *testing.T) {

synthEvents := []*SynthEvent{
journeyStart,
makeStepEvent("step/start", 10, "Step1", 1, "", nil),
makeStepEvent("step/end", 20, "Step1", 1, url1, nil),
makeStepEvent("step/start", 21, "Step2", 1, "", nil),
makeStepEvent("step/end", 30, "Step2", 1, url2, syntherr),
makeStepEvent("step/start", 31, "Step3", 1, "", nil),
makeStepEvent("step/end", 40, "Step3", 1, url3, otherErr),
makeStepEvent("step/start", 10, "Step1", 1, "succeeded", "", nil),
makeStepEvent("step/end", 20, "Step1", 1, "", url1, nil),
makeStepEvent("step/start", 21, "Step2", 1, "", "", nil),
makeStepEvent("step/end", 30, "Step2", 1, "failed", url2, syntherr),
makeStepEvent("step/start", 31, "Step3", 1, "", "", nil),
makeStepEvent("step/end", 40, "Step3", 1, "", url3, otherErr),
journeyEnd,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func TestExecMultiplexer(t *testing.T) {

for sIdx := 0; sIdx < 3; sIdx++ {
step := &Step{
Name: fmt.Sprintf("S%d", sIdx),
Index: sIdx,
Name: fmt.Sprintf("S%d", sIdx),
Index: sIdx,
Status: "failed",
}

testEvents = append(testEvents, &SynthEvent{
Expand Down
1 change: 1 addition & 0 deletions x-pack/heartbeat/monitors/browser/synthexec/synthexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func jsonToSynthEvent(bytes []byte, text string) (res *SynthEvent, err error) {

res = &SynthEvent{}
err = json.Unmarshal(bytes, res)

if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions x-pack/heartbeat/monitors/browser/synthexec/synthexec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestJsonToSynthEvent(t *testing.T) {
},
{
name: "a valid line",
line: `{"@timestamp":7165676811882692608,"type":"step/end","journey":{"name":"inline","id":"inline"},"step":{"name":"Go to home page","index":0},"payload":{"source":"async ({page, params}) => {await page.goto('http://www.elastic.co')}","duration_ms":3472,"url":"https://www.elastic.co/","status":"succeeded"},"url":"https://www.elastic.co/","package_version":"0.0.1"}`,
line: `{"@timestamp":7165676811882692608,"type":"step/end","journey":{"name":"inline","id":"inline"},"step":{"name":"Go to home page","index":0,"status":"succeeded"},"payload":{"source":"async ({page, params}) => {await page.goto('http://www.elastic.co')}","duration_ms":3472,"url":"https://www.elastic.co/","status":"succeeded"},"url":"https://www.elastic.co/","package_version":"0.0.1"}`,
synthEvent: &SynthEvent{
TimestampEpochMicros: 7165676811882692608,
Type: "step/end",
Expand All @@ -64,8 +64,9 @@ func TestJsonToSynthEvent(t *testing.T) {
Id: "inline",
},
Step: &Step{
Name: "Go to home page",
Index: 0,
Name: "Go to home page",
Index: 0,
Status: "succeeded",
},
Payload: map[string]interface{}{
"source": "async ({page, params}) => {await page.goto('http://www.elastic.co')}",
Expand Down
10 changes: 6 additions & 4 deletions x-pack/heartbeat/monitors/browser/synthexec/synthtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ func (se *SynthError) toMap() common.MapStr {
}

type Step struct {
Name string `json:"name"`
Index int `json:"index"`
Name string `json:"name"`
Index int `json:"index"`
Status string `json:"status"`
}

func (s *Step) ToMap() common.MapStr {
return common.MapStr{
"name": s.Name,
"index": s.Index,
"name": s.Name,
"index": s.Index,
"status": s.Status,
}
}

Expand Down

0 comments on commit 98a1cf7

Please sign in to comment.