diff --git a/handlers/analytics.go b/handlers/analytics.go index f6ffceea4..a67087c84 100644 --- a/handlers/analytics.go +++ b/handlers/analytics.go @@ -4,14 +4,15 @@ import ( "crypto/sha256" "encoding/json" "fmt" - "github.com/livepeer/catalyst-api/metrics" - "github.com/ua-parser/uap-go/uaparser" "io" "net" "net/http" "strconv" "time" + "github.com/livepeer/catalyst-api/metrics" + "github.com/ua-parser/uap-go/uaparser" + "github.com/golang/glog" "github.com/julienschmidt/httprouter" cerrors "github.com/livepeer/catalyst-api/errors" @@ -45,8 +46,9 @@ type AnalyticsLog struct { type AnalyticsLogEvent struct { // Shared fields by all events - Type string `json:"type"` - Timestamp int64 `json:"timestamp"` + Id *string `json:"id"` + Type string `json:"type"` + Timestamp int64 `json:"timestamp"` // Heartbeat event Errors *int `json:"errors"` @@ -250,6 +252,7 @@ func (c *AnalyticsHandlersCollection) toAnalyticsData(log *AnalyticsLog, geo Ana EventType: e.Type, EventTimestamp: e.Timestamp, EventData: analytics.LogDataEvent{ + Id: e.Id, Errors: e.Errors, AutoplayStatus: e.AutoplayStatus, StalledCount: e.StalledCount, diff --git a/handlers/analytics/log_processor.go b/handlers/analytics/log_processor.go index 7b9441e5e..07befb5fc 100644 --- a/handlers/analytics/log_processor.go +++ b/handlers/analytics/log_processor.go @@ -4,11 +4,12 @@ import ( "context" "crypto/tls" "encoding/json" + "time" + "github.com/golang/glog" "github.com/livepeer/catalyst-api/metrics" "github.com/segmentio/kafka-go" "github.com/segmentio/kafka-go/sasl/plain" - "time" ) const ( @@ -28,6 +29,7 @@ type LogProcessor struct { type LogDataEvent struct { // Heartbeat event + Id *string `json:"id,omitempty"` Errors *int `json:"errors,omitempty"` AutoplayStatus *string `json:"autoplay_status,omitempty"` StalledCount *int `json:"stalled_count,omitempty"` diff --git a/handlers/analytics_test.go b/handlers/analytics_test.go index 646df43c1..fd71b8064 100644 --- a/handlers/analytics_test.go +++ b/handlers/analytics_test.go @@ -1,14 +1,15 @@ package handlers import ( - "github.com/julienschmidt/httprouter" - "github.com/livepeer/catalyst-api/handlers/analytics" - "github.com/stretchr/testify/require" - "github.com/ua-parser/uap-go/uaparser" "net/http" "net/http/httptest" "strings" "testing" + + "github.com/julienschmidt/httprouter" + "github.com/livepeer/catalyst-api/handlers/analytics" + "github.com/stretchr/testify/require" + "github.com/ua-parser/uap-go/uaparser" ) const userID = "user-id" @@ -55,6 +56,7 @@ func TestHandleLog(t *testing.T) { "uid": "abcdef", "events": [ { + "id": "dcba4321", "type": "heartbeat", "timestamp": 1234567895, "errors": 0, @@ -83,6 +85,7 @@ func TestHandleLog(t *testing.T) { "some_field": "some value" }, { + "id": "abcde12345", "type": "error", "timestamp": 1234567895, "error_message": "error message", @@ -115,6 +118,7 @@ func TestHandleLog(t *testing.T) { EventType: "heartbeat", EventTimestamp: 1234567895, EventData: analytics.LogDataEvent{ + Id: strPtr("dcba4321"), Errors: intPtr(0), AutoplayStatus: strPtr("autoplay"), StalledCount: intPtr(5), @@ -157,6 +161,7 @@ func TestHandleLog(t *testing.T) { EventType: "error", EventTimestamp: 1234567895, EventData: analytics.LogDataEvent{ + Id: strPtr("abcde12345"), ErrorMessage: strPtr("error message"), Category: strPtr("offline"), },