Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSET-4559: Group By fields are part of SessionInfo #62

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ go 1.19

require (
github.com/scalyr/dataset-go v0.0.0
go.uber.org/zap v1.24.0
go.uber.org/zap v1.26.0
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.4.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
)

Expand Down
3 changes: 3 additions & 0 deletions examples/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -26,8 +27,10 @@ go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
Expand Down
6 changes: 3 additions & 3 deletions examples/readme/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ go 1.19

require (
github.com/scalyr/dataset-go v0.0.0
go.uber.org/zap v1.24.0
go.uber.org/zap v1.26.0
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.4.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
)

Expand Down
3 changes: 3 additions & 0 deletions examples/readme/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -26,8 +27,10 @@ go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
Expand Down
14 changes: 6 additions & 8 deletions pkg/api/add_events/add_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ import (
)

const (
AttrBundleKey = "bundle_key"
AttrSessionKey = "session_key"
AttrServerHost = "serverHost"
AttrOrigServerHost = "__origServerHost"
AttrLogFile = "logfile"
)

type EventAttrs = map[string]interface{}
type (
EventAttrs = map[string]interface{}
SessionInfo = map[string]interface{}
)

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

type SessionInfo struct {
ServerType string `json:"serverType,omitempty"`
ServerId string `json:"serverId,omitempty"`
Region string `json:"region,omitempty"`
}

// AddEventsRequestParams represents a represents a AddEvent DataSet REST API request parameters, see https://app.scalyr.com/help/api#addEvents.
type AddEventsRequestParams struct {
Session string `json:"session,omitempty"`
Expand Down
27 changes: 0 additions & 27 deletions pkg/api/add_events/event_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

package add_events

import (
"crypto/md5"
"encoding/hex"
"fmt"
)

// EventBundle represents a single DataSet event wrapper structure (see https://app.scalyr.com/help/api#addEvents)
// Event - Zero or more events (log messages) to upload.
// Thread - Optional. Lets you create a readable name for each thread in Event.
Expand All @@ -32,24 +26,3 @@ type EventBundle struct {
Thread *Thread
Log *Log
}

func (bundle *EventBundle) Key(groupBy []string) string {
// construct key
key := ""
for _, k := range groupBy {
val, ok := bundle.Event.Attrs[k]
if ok {
key += fmt.Sprintf("%s:%s", k, val)
}
}

// use md5 to shorten the key
hash := md5.Sum([]byte(key))
bundleKey := hex.EncodeToString(hash[:])

// add the key as attribute
bundle.Event.Attrs[AttrBundleKey] = bundleKey

// return the key
return bundleKey
}
37 changes: 0 additions & 37 deletions pkg/api/add_events/event_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,3 @@
*/

package add_events

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestEventBundle(t *testing.T) {
event := &Event{
Thread: "5",
Sev: 3,
Ts: "0",
Attrs: map[string]interface{}{
"foo": "a",
"bar": "b",
"baz": "a",
},
}
bundle := &EventBundle{Event: event}

keyFoo := bundle.Key([]string{"foo"})
keyBar := bundle.Key([]string{"bar"})
keyBaz := bundle.Key([]string{"baz"})
keyNotThere1 := bundle.Key([]string{"notThere1"})
keyNotThere2 := bundle.Key([]string{"notThere2"})

assert.Equal(t, "ef9faec68698672038857b2647429002", keyFoo)
assert.Equal(t, "55a2f7ebf2af8927837c599131d32d07", keyBar)
assert.Equal(t, "6dd515483537f552fd5fa604cd60f0d9", keyBaz)
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", keyNotThere1)
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", keyNotThere2)

// although the value is same, key should be different because attributes differ
assert.NotEqual(t, keyBaz, keyFoo)
// non-existing attributes should have the same key
assert.Equal(t, keyNotThere1, keyNotThere2)
}
12 changes: 6 additions & 6 deletions pkg/buffer/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func createTestBundle() add_events.EventBundle {

func createEmptyBuffer() *Buffer {
sessionInfo := &add_events.SessionInfo{
ServerId: "serverId",
ServerType: "serverType",
Region: "region",
"serverId": "serverId",
"serverType": "serverType",
"region": "region",
}
session := "session"
token := "token"
Expand Down Expand Up @@ -136,9 +136,9 @@ func TestPayloadFull(t *testing.T) {

func TestPayloadInjection(t *testing.T) {
sessionInfo := &add_events.SessionInfo{
ServerId: "serverId\",\"sI\":\"I",
ServerType: "serverType\",\"sT\":\"T",
Region: "region\",\"r\":\"R",
"serverId": "serverId\",\"sI\":\"I",
"serverType": "serverType\",\"sT\":\"T",
"region": "region\",\"r\":\"R",
}
session := "session\",\"s\":\"S"
token := "token\",\"events\":[{}],\"foo\":\"bar"
Expand Down
Loading