Skip to content

Commit

Permalink
Add received to Event (#85)
Browse files Browse the repository at this point in the history
Co-authored-by: kruskall <[email protected]>
  • Loading branch information
endorama and kruskall authored Jun 23, 2023
1 parent e3ce836 commit 6dfa24c
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 44 deletions.
4 changes: 4 additions & 0 deletions model/internal/modeljson/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ func (t Time) MarshalFastJSON(w *fastjson.Writer) error {
w.RawByte('"')
return nil
}

func (t Time) isZero() bool {
return time.Time(t).IsZero()
}
1 change: 1 addition & 0 deletions model/internal/modeljson/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Event struct {
Dataset string `json:"dataset,omitempty"`
Kind string `json:"kind,omitempty"`
Category string `json:"category,omitempty"`
Received Time `json:"received,omitempty"`
Type string `json:"type,omitempty"`
SuccessCount SummaryMetric `json:"success_count,omitempty"`
Duration int64 `json:"duration,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions model/internal/modeljson/marshal_fastjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 58 additions & 42 deletions model/modelpb/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion model/modelpb/event.pb.json.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package modelpb

import "github.com/elastic/apm-data/model/internal/modeljson"
import (
"github.com/elastic/apm-data/model/internal/modeljson"
)

func (e *Event) toModelJSON(out *modeljson.Event) {
*out = modeljson.Event{
Expand All @@ -36,4 +38,7 @@ func (e *Event) toModelJSON(out *modeljson.Event) {
Sum: e.SuccessCount.Sum,
}
}
if e.Received.IsValid() {
out.Received = modeljson.Time(e.Received.AsTime())
}
}
15 changes: 14 additions & 1 deletion model/modelpb/event.pb.json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
)

const (
testTime = "2006-01-02T15:04:05Z"
)

func TestEventToModelJSON(t *testing.T) {
now, err := time.Parse(time.RFC3339, testTime)
require.NoError(t, err)

testCases := map[string]struct {
proto *Event
expected *modeljson.Event
Expand All @@ -50,6 +58,7 @@ func TestEventToModelJSON(t *testing.T) {
},
Duration: durationpb.New(3 * time.Second),
Severity: 4,
Received: timestamppb.New(now),
},
expected: &modeljson.Event{
Outcome: "outcome",
Expand All @@ -64,14 +73,18 @@ func TestEventToModelJSON(t *testing.T) {
},
Duration: int64(3 * time.Second),
Severity: 4,
Received: modeljson.Time(now),
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
var out modeljson.Event
tc.proto.toModelJSON(&out)
diff := cmp.Diff(*tc.expected, out)
diff := cmp.Diff(*tc.expected, out,
cmp.Comparer(func(a modeljson.Time, b modeljson.Time) bool {
return time.Time(a).Equal(time.Time(b))
}))
require.Empty(t, diff)
})
}
Expand Down
77 changes: 77 additions & 0 deletions model/modelpb/event_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions model/proto/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ syntax = "proto3";
package elastic.apm.v1;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "metricset.proto";

option go_package = "github.com/elastic/apm-data/model/modelpb";
Expand All @@ -36,4 +37,6 @@ message Event {
SummaryMetric success_count = 7;
google.protobuf.Duration duration = 8;
int64 severity = 9;

google.protobuf.Timestamp received = 10;
}

0 comments on commit 6dfa24c

Please sign in to comment.