Skip to content

Commit

Permalink
fix: upload missing metric (#2947)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvrach committed Feb 7, 2023
1 parent 1f4cfd4 commit cbb4b1a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
26 changes: 14 additions & 12 deletions warehouse/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ func (wh *HandleT) Track(ctx context.Context, warehouse *warehouseutils.Warehous
Now = wh.Now
}

tags := stats.Tags{
"workspaceId": warehouse.WorkspaceID,
"module": moduleName,
"destType": wh.destType,
"warehouseID": misc.GetTagName(
destination.ID,
source.Name,
destination.Name,
misc.TailTruncateStr(source.ID, 6)),
}
statKey := "warehouse_track_upload_missing"
wh.stats.NewTaggedStat(statKey, stats.GaugeType, tags).Gauge(0)

if !source.Enabled || !destination.Enabled {
return nil
}
Expand Down Expand Up @@ -163,19 +176,8 @@ func (wh *HandleT) Track(ctx context.Context, warehouse *warehouseutils.Warehous
warehouseutils.DestinationType, destination.DestinationDefinition.Name,
warehouseutils.WorkspaceID, warehouse.WorkspaceID,
)
wh.stats.NewTaggedStat(statKey, stats.GaugeType, tags).Gauge(1)
}

tags := stats.Tags{
"workspaceId": warehouse.WorkspaceID,
"module": moduleName,
"destType": wh.destType,
"ok": strconv.FormatBool(exists),
"warehouseID": misc.GetTagName(
destination.ID,
source.Name,
destination.Name,
misc.TailTruncateStr(source.ID, 6)),
}
wh.stats.NewTaggedStat("warehouse_successful_upload_exists", stats.GaugeType, tags).Gauge(1)
return nil
}
34 changes: 15 additions & 19 deletions warehouse/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"os"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -38,8 +37,7 @@ func TestHandleT_Track(t *testing.T) {
destID string
destDisabled bool
wantErr error
wantStats bool
ok bool
missing bool
NowSQL string
exclusionWindow map[string]any
uploadBufferTime string
Expand All @@ -54,35 +52,34 @@ func TestHandleT_Track(t *testing.T) {
destDisabled: true,
},
{
name: "successful upload exists",
destID: destID,
wantStats: true,
ok: true,
name: "successful upload exists",
destID: destID,
missing: false,
},
{
name: "successful upload exists with upload buffer time",
destID: destID,
wantStats: true,
ok: true,
missing: false,
uploadBufferTime: "0m",
},
{
name: "exclusion window",
destID: destID,
wantStats: false,
name: "exclusion window",
destID: destID,
missing: false,
exclusionWindow: map[string]any{
"excludeWindowStartTime": "05:09",
"excludeWindowEndTime": "09:07",
},
},
{
name: "no successful upload exists",
destID: "test-destinationID-1",
wantStats: true,
name: "no successful upload exists",
destID: "test-destinationID-1",
missing: true,
},
{
name: "throw error while fetching last upload time",
destID: destID,
missing: false,
NowSQL: "ABC",
wantErr: errors.New("fetching last upload time for source: test-sourceID and destination: test-destinationID: pq: column \"abc\" does not exist"),
},
Expand Down Expand Up @@ -166,22 +163,21 @@ func TestHandleT_Track(t *testing.T) {
}
require.NoError(t, err)

m := store.Get("warehouse_successful_upload_exists", stats.Tags{
m := store.Get("warehouse_track_upload_missing", stats.Tags{
"module": moduleName,
"workspaceId": warehouse.WorkspaceID,
"destType": handle.destType,
"ok": strconv.FormatBool(tc.ok),
"warehouseID": misc.GetTagName(
warehouse.Destination.ID,
warehouse.Source.Name,
warehouse.Destination.Name,
misc.TailTruncateStr(warehouse.Source.ID, 6)),
})

if tc.wantStats {
if tc.missing {
require.EqualValues(t, m.LastValue(), 1)
} else {
require.Nil(t, m)
require.EqualValues(t, m.LastValue(), 0)
}
})
}
Expand Down

0 comments on commit cbb4b1a

Please sign in to comment.