Skip to content

Commit 29d4782

Browse files
DSET-4559: Group By fields are part of SessionInfo (#62)
* DSET-4559: Group By fields are part of SessionInfo * DSET-4559: Move grouped attributes to session info * Adjust code so that it looks in the UI as expected * Incorporate comments from PR
1 parent 5f915d0 commit 29d4782

File tree

19 files changed

+636
-266
lines changed

19 files changed

+636
-266
lines changed

examples/client/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ go 1.19
44

55
require (
66
github.com/scalyr/dataset-go v0.0.0
7-
go.uber.org/zap v1.24.0
7+
go.uber.org/zap v1.26.0
88
)
99

1010
require (
1111
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
1212
github.com/cskr/pubsub v1.0.2 // indirect
13-
github.com/google/uuid v1.3.0 // indirect
13+
github.com/google/uuid v1.4.0 // indirect
1414
go.uber.org/atomic v1.7.0 // indirect
15-
go.uber.org/multierr v1.6.0 // indirect
15+
go.uber.org/multierr v1.10.0 // indirect
1616
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
1717
)
1818

examples/client/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
1111
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1212
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
1313
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
14+
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1415
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
1516
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1617
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -26,8 +27,10 @@ go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
2627
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
2728
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
2829
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
30+
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
2931
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
3032
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
33+
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
3134
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
3235
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
3336
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=

examples/readme/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ go 1.19
44

55
require (
66
github.com/scalyr/dataset-go v0.0.0
7-
go.uber.org/zap v1.24.0
7+
go.uber.org/zap v1.26.0
88
)
99

1010
require (
1111
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
1212
github.com/cskr/pubsub v1.0.2 // indirect
13-
github.com/google/uuid v1.3.0 // indirect
13+
github.com/google/uuid v1.4.0 // indirect
1414
go.uber.org/atomic v1.7.0 // indirect
15-
go.uber.org/multierr v1.6.0 // indirect
15+
go.uber.org/multierr v1.10.0 // indirect
1616
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
1717
)
1818

examples/readme/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
1111
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1212
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
1313
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
14+
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1415
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
1516
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1617
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -26,8 +27,10 @@ go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
2627
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
2728
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
2829
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
30+
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
2931
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
3032
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
33+
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
3134
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
3235
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
3336
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=

pkg/api/add_events/add_events.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ import (
2727
)
2828

2929
const (
30-
AttrBundleKey = "bundle_key"
30+
AttrSessionKey = "session_key"
3131
AttrServerHost = "serverHost"
3232
AttrOrigServerHost = "__origServerHost"
33+
AttrLogFile = "logfile"
3334
)
3435

35-
type EventAttrs = map[string]interface{}
36+
type (
37+
EventAttrs = map[string]interface{}
38+
SessionInfo = map[string]interface{}
39+
)
3640

3741
// Event represents DataSet REST API event structure (see https://app.scalyr.com/help/api#addEvents)
3842
type Event struct {
@@ -68,12 +72,6 @@ type Log struct {
6872
Attrs map[string]interface{} `json:"attrs"`
6973
}
7074

71-
type SessionInfo struct {
72-
ServerType string `json:"serverType,omitempty"`
73-
ServerId string `json:"serverId,omitempty"`
74-
Region string `json:"region,omitempty"`
75-
}
76-
7775
// AddEventsRequestParams represents a represents a AddEvent DataSet REST API request parameters, see https://app.scalyr.com/help/api#addEvents.
7876
type AddEventsRequestParams struct {
7977
Session string `json:"session,omitempty"`

pkg/api/add_events/event_bundle.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616

1717
package add_events
1818

19-
import (
20-
"crypto/md5"
21-
"encoding/hex"
22-
"fmt"
23-
)
24-
2519
// EventBundle represents a single DataSet event wrapper structure (see https://app.scalyr.com/help/api#addEvents)
2620
// Event - Zero or more events (log messages) to upload.
2721
// Thread - Optional. Lets you create a readable name for each thread in Event.
@@ -32,24 +26,3 @@ type EventBundle struct {
3226
Thread *Thread
3327
Log *Log
3428
}
35-
36-
func (bundle *EventBundle) Key(groupBy []string) string {
37-
// construct key
38-
key := ""
39-
for _, k := range groupBy {
40-
val, ok := bundle.Event.Attrs[k]
41-
if ok {
42-
key += fmt.Sprintf("%s:%s", k, val)
43-
}
44-
}
45-
46-
// use md5 to shorten the key
47-
hash := md5.Sum([]byte(key))
48-
bundleKey := hex.EncodeToString(hash[:])
49-
50-
// add the key as attribute
51-
bundle.Event.Attrs[AttrBundleKey] = bundleKey
52-
53-
// return the key
54-
return bundleKey
55-
}

pkg/api/add_events/event_bundle_test.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,3 @@
1515
*/
1616

1717
package add_events
18-
19-
import (
20-
"testing"
21-
22-
"github.com/stretchr/testify/assert"
23-
)
24-
25-
func TestEventBundle(t *testing.T) {
26-
event := &Event{
27-
Thread: "5",
28-
Sev: 3,
29-
Ts: "0",
30-
Attrs: map[string]interface{}{
31-
"foo": "a",
32-
"bar": "b",
33-
"baz": "a",
34-
},
35-
}
36-
bundle := &EventBundle{Event: event}
37-
38-
keyFoo := bundle.Key([]string{"foo"})
39-
keyBar := bundle.Key([]string{"bar"})
40-
keyBaz := bundle.Key([]string{"baz"})
41-
keyNotThere1 := bundle.Key([]string{"notThere1"})
42-
keyNotThere2 := bundle.Key([]string{"notThere2"})
43-
44-
assert.Equal(t, "ef9faec68698672038857b2647429002", keyFoo)
45-
assert.Equal(t, "55a2f7ebf2af8927837c599131d32d07", keyBar)
46-
assert.Equal(t, "6dd515483537f552fd5fa604cd60f0d9", keyBaz)
47-
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", keyNotThere1)
48-
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", keyNotThere2)
49-
50-
// although the value is same, key should be different because attributes differ
51-
assert.NotEqual(t, keyBaz, keyFoo)
52-
// non-existing attributes should have the same key
53-
assert.Equal(t, keyNotThere1, keyNotThere2)
54-
}

pkg/buffer/buffer_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ func createTestBundle() add_events.EventBundle {
8282

8383
func createEmptyBuffer() *Buffer {
8484
sessionInfo := &add_events.SessionInfo{
85-
ServerId: "serverId",
86-
ServerType: "serverType",
87-
Region: "region",
85+
"serverId": "serverId",
86+
"serverType": "serverType",
87+
"region": "region",
8888
}
8989
session := "session"
9090
token := "token"
@@ -136,9 +136,9 @@ func TestPayloadFull(t *testing.T) {
136136

137137
func TestPayloadInjection(t *testing.T) {
138138
sessionInfo := &add_events.SessionInfo{
139-
ServerId: "serverId\",\"sI\":\"I",
140-
ServerType: "serverType\",\"sT\":\"T",
141-
Region: "region\",\"r\":\"R",
139+
"serverId": "serverId\",\"sI\":\"I",
140+
"serverType": "serverType\",\"sT\":\"T",
141+
"region": "region\",\"r\":\"R",
142142
}
143143
session := "session\",\"s\":\"S"
144144
token := "token\",\"events\":[{}],\"foo\":\"bar"

0 commit comments

Comments
 (0)