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

fix: added ID field to analytics parsing #1354

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions handlers/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
0xcadams marked this conversation as resolved.
Show resolved Hide resolved
Type string `json:"type"`
Timestamp int64 `json:"timestamp"`

// Heartbeat event
Errors *int `json:"errors"`
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion handlers/analytics/log_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -28,6 +29,7 @@ type LogProcessor struct {

type LogDataEvent struct {
// Heartbeat event
Id *string `json:"id,omitempty"`
0xcadams marked this conversation as resolved.
Show resolved Hide resolved
Errors *int `json:"errors,omitempty"`
AutoplayStatus *string `json:"autoplay_status,omitempty"`
StalledCount *int `json:"stalled_count,omitempty"`
Expand Down
13 changes: 9 additions & 4 deletions handlers/analytics_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -55,6 +56,7 @@ func TestHandleLog(t *testing.T) {
"uid": "abcdef",
"events": [
{
"id": "dcba4321",
"type": "heartbeat",
"timestamp": 1234567895,
"errors": 0,
Expand Down Expand Up @@ -83,6 +85,7 @@ func TestHandleLog(t *testing.T) {
"some_field": "some value"
},
{
"id": "abcde12345",
0xcadams marked this conversation as resolved.
Show resolved Hide resolved
"type": "error",
"timestamp": 1234567895,
"error_message": "error message",
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
},
Expand Down
Loading