diff --git a/views/bigquery.go b/views/bigquery.go index ee92988..3d7f925 100644 --- a/views/bigquery.go +++ b/views/bigquery.go @@ -80,8 +80,8 @@ type ViewershipEventRow struct { // metric data - ViewCount int64 `bigquery:"view_count"` - PlaytimeMins float64 `bigquery:"playtime_mins"` + ViewCount bigquery.NullInt64 `bigquery:"view_count"` + PlaytimeMins bigquery.NullFloat64 `bigquery:"playtime_mins"` TtffMs bigquery.NullFloat64 `bigquery:"ttff_ms"` RebufferRatio bigquery.NullFloat64 `bigquery:"rebuffer_ratio"` ErrorRate bigquery.NullFloat64 `bigquery:"error_rate"` @@ -92,9 +92,9 @@ type ViewSummaryRow struct { PlaybackID bigquery.NullString `bigquery:"playback_id"` DStorageURL bigquery.NullString `bigquery:"d_storage_url"` - ViewCount int64 `bigquery:"view_count"` - LegacyViewCount bigquery.NullInt64 `bigquery:"legacy_view_count"` - PlaytimeMins float64 `bigquery:"playtime_mins"` + ViewCount bigquery.NullInt64 `bigquery:"view_count"` + LegacyViewCount bigquery.NullInt64 `bigquery:"legacy_view_count"` + PlaytimeMins bigquery.NullFloat64 `bigquery:"playtime_mins"` } type BigQuery interface { diff --git a/views/client.go b/views/client.go index a224cee..4cc6700 100644 --- a/views/client.go +++ b/views/client.go @@ -40,8 +40,8 @@ type Metric struct { // metric data - ViewCount int64 `json:"viewCount"` - PlaytimeMins float64 `json:"playtimeMins"` + ViewCount data.Nullable[int64] `json:"viewCount,omitempty"` + PlaytimeMins data.Nullable[float64] `json:"playtimeMins,omitempty"` TtffMs data.Nullable[float64] `json:"ttffMs,omitempty"` RebufferRatio data.Nullable[float64] `json:"rebufferRatio,omitempty"` ErrorRate data.Nullable[float64] `json:"errorRate,omitempty"` @@ -97,7 +97,7 @@ func (c *Client) Deprecated_GetTotalViews(ctx context.Context, id string) ([]Tot return []TotalViews{{ ID: asset.PlaybackID, - StartViews: startViews, + StartViews: data.ToNullable[int64](startViews, true, true), }}, nil } @@ -126,9 +126,9 @@ func viewershipSummaryToMetric(playbackID string, summary *ViewSummaryRow) *Metr return &Metric{ PlaybackID: toStringPtr(summary.PlaybackID, summary.PlaybackID.Valid), DStorageURL: toStringPtr(summary.DStorageURL, summary.DStorageURL.Valid), - ViewCount: summary.ViewCount, + ViewCount: toInt64Ptr(summary.ViewCount, summary.ViewCount.Valid), LegacyViewCount: data.ToNullable[int64](legacyViewCount, true, true), - PlaytimeMins: summary.PlaytimeMins, + PlaytimeMins: toFloat64Ptr(summary.PlaytimeMins, summary.PlaytimeMins.Valid), } } @@ -187,8 +187,8 @@ func viewershipEventsToMetrics(rows []ViewershipEventRow, spec QuerySpec) []Metr Subdivision: toStringPtr(row.Subdivision, spec.hasBreakdownBy("subdivision")), TimeZone: toStringPtr(row.TimeZone, spec.hasBreakdownBy("timezone")), GeoHash: toStringPtr(row.GeoHash, spec.hasBreakdownBy("geohash")), - ViewCount: row.ViewCount, - PlaytimeMins: row.PlaytimeMins, + ViewCount: toInt64Ptr(row.ViewCount, spec.Detailed), + PlaytimeMins: toFloat64Ptr(row.PlaytimeMins, spec.Detailed), TtffMs: toFloat64Ptr(row.TtffMs, spec.Detailed), RebufferRatio: toFloat64Ptr(row.RebufferRatio, spec.Detailed), ErrorRate: toFloat64Ptr(row.ErrorRate, spec.Detailed), @@ -205,6 +205,10 @@ func viewershipEventsToMetrics(rows []ViewershipEventRow, spec QuerySpec) []Metr return metrics } +func toInt64Ptr(bqInt bigquery.NullInt64, asked bool) data.Nullable[int64] { + return data.ToNullable(bqInt.Int64, bqInt.Valid, asked) +} + func toFloat64Ptr(bqFloat bigquery.NullFloat64, asked bool) data.Nullable[float64] { return data.ToNullable(bqFloat.Float64, bqFloat.Valid, asked) } diff --git a/views/prometheus.go b/views/prometheus.go index 9033597..8ad0e4a 100644 --- a/views/prometheus.go +++ b/views/prometheus.go @@ -7,14 +7,15 @@ import ( "github.com/golang/glog" livepeer "github.com/livepeer/go-api-client" + "github.com/livepeer/livepeer-data/pkg/data" promClient "github.com/prometheus/client_golang/api" prometheus "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" ) type TotalViews struct { - ID string `json:"id"` - StartViews int64 `json:"startViews"` + ID string `json:"id"` + StartViews data.Nullable[int64] `json:"startViews"` } type Prometheus struct {