-
Notifications
You must be signed in to change notification settings - Fork 314
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
feat: track event delivery stats #3974
Merged
Merged
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7fc3394
feat: track event delivery stats
gane5hvarma a9bc0b0
change package name
gane5hvarma 98e2a1f
resolve merge conflicts
gane5hvarma a30f696
add basic test to check metrics
gane5hvarma 1708089
rm fmt
gane5hvarma a64b907
make fmt
gane5hvarma 58439a5
make fmt
gane5hvarma a99bc70
fix setup test
gane5hvarma 14c097a
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma 1118a95
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma ba2ba50
Merge branch 'master' into feat.unifiedPipelineMetrics
fracasula 14932f9
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma a4053c9
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma 4e2fde9
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma b0f9a4b
add tx listener to caputre event stats
gane5hvarma 91a9275
Merge branch 'feat.unifiedPipelineMetrics' of github.com:rudderlabs/r…
gane5hvarma 2c633fe
remove unused imports
gane5hvarma f785db0
fmt file
gane5hvarma 1c7ecbc
fix tests in reporting
gane5hvarma d0ba83b
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma 736e784
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma 8dcef04
resolve pr comments
gane5hvarma 259adc8
Merge branch 'feat.unifiedPipelineMetrics' of github.com:rudderlabs/r…
gane5hvarma 5bde9ad
resolve pr comments
gane5hvarma 7129cfb
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma 68232c4
fix count in aborted test
gane5hvarma 04e0934
Merge branch 'feat.unifiedPipelineMetrics' of github.com:rudderlabs/r…
gane5hvarma 582628f
fix database syncer return
gane5hvarma 08bb132
fix delegate setup test
gane5hvarma 4564996
add status as label and capture only one metric
gane5hvarma 1a4a5bb
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma b9c99a5
remove terminal in labels and only capture terminal status except mig…
gane5hvarma fbd3b9d
Merge branch 'feat.unifiedPipelineMetrics' of github.com:rudderlabs/r…
gane5hvarma 0619473
fix test in event stats
gane5hvarma d3d5a2f
nit pick case and constants
gane5hvarma b4589e7
add terminal in metric label
gane5hvarma 1bcc5fd
add migrated status back
gane5hvarma 51e5266
Merge branch 'master' into feat.unifiedPipelineMetrics
gane5hvarma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package reporting | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/rudderlabs/rudder-go-kit/stats" | ||
"github.com/rudderlabs/rudder-server/utils/types" | ||
) | ||
|
||
const ( | ||
EventsDeliveredMetricName = "events_delivered_total" | ||
EventsAbortedMetricName = "events_aborted_total" | ||
) | ||
atzoum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
type EventStatsReporter struct { | ||
stats stats.Stats | ||
configSubscriber *configSubscriber | ||
} | ||
|
||
func NewEventStatsReporter(configSubscriber *configSubscriber, stats stats.Stats) *EventStatsReporter { | ||
return &EventStatsReporter{ | ||
stats: stats, | ||
configSubscriber: configSubscriber, | ||
} | ||
} | ||
|
||
func (es *EventStatsReporter) Report(metrics []*types.PUReportedMetric, _ *sql.Tx) error { | ||
atzoum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// tracking delivery event stats which has state - succeeded, aborted | ||
for _, metric := range metrics { | ||
metric := metric | ||
gane5hvarma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !(metric.StatusDetail.Status == "aborted" || metric.StatusDetail.Status == "succeeded") { | ||
gane5hvarma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue | ||
} | ||
tags := stats.Tags{ | ||
"workspaceId": es.configSubscriber.WorkspaceIDFromSource(metric.ConnectionDetails.SourceID), | ||
"sourceId": metric.ConnectionDetails.SourceID, | ||
"destinationId": metric.ConnectionDetails.DestinationID, | ||
"reportedBy": metric.PUDetails.PU, | ||
"sourceCategory": metric.ConnectionDetails.SourceCategory, | ||
"terminal": strconv.FormatBool(metric.PUDetails.TerminalPU), | ||
} | ||
fmt.Println(tags) | ||
metricName := EventsDeliveredMetricName | ||
if metric.StatusDetail.Status == "aborted" { | ||
metricName = EventsAbortedMetricName | ||
} | ||
es.stats.NewTaggedStat(metricName, stats.CountType, tags).Count(int(metric.StatusDetail.Count)) | ||
} | ||
return nil | ||
} | ||
|
||
func (es *EventStatsReporter) DatabaseSyncer(types.SyncerConfig) types.ReportingSyncer { | ||
return func() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package reporting | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/rudderlabs/rudder-go-kit/logger" | ||
"github.com/rudderlabs/rudder-go-kit/stats/memstats" | ||
backendconfig "github.com/rudderlabs/rudder-server/backend-config" | ||
mocksBackendConfig "github.com/rudderlabs/rudder-server/mocks/backend-config" | ||
"github.com/rudderlabs/rudder-server/utils/pubsub" | ||
"github.com/rudderlabs/rudder-server/utils/types" | ||
) | ||
|
||
func TestEventStatsReporter(t *testing.T) { | ||
achettyiitr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
workspaceID := "test-workspace-id" | ||
sourceID := "test-source-id" | ||
destinationID := "test-destination-id" | ||
reportedBy := "test-reported-by" | ||
sourceCategory := "test-source-category" | ||
ctrl := gomock.NewController(t) | ||
mockBackendConfig := mocksBackendConfig.NewMockBackendConfig(ctrl) | ||
mockBackendConfig.EXPECT().Subscribe(gomock.Any(), backendconfig.TopicBackendConfig).DoAndReturn(func(ctx context.Context, topic backendconfig.Topic) pubsub.DataChannel { | ||
ch := make(chan pubsub.DataEvent, 1) | ||
ch <- pubsub.DataEvent{ | ||
Data: map[string]backendconfig.ConfigT{ | ||
workspaceID: { | ||
WorkspaceID: workspaceID, | ||
Sources: []backendconfig.SourceT{ | ||
{ | ||
ID: sourceID, | ||
Enabled: true, | ||
SourceDefinition: backendconfig.SourceDefinitionT{ | ||
Category: sourceCategory, | ||
}, | ||
Destinations: []backendconfig.DestinationT{ | ||
{ | ||
ID: destinationID, | ||
Enabled: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Topic: string(backendconfig.TopicBackendConfig), | ||
} | ||
close(ch) | ||
return ch | ||
}).AnyTimes() | ||
|
||
statsStore := memstats.New() | ||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
cs := newConfigSubscriber(logger.NOP) | ||
|
||
subscribeDone := make(chan struct{}) | ||
go func() { | ||
defer close(subscribeDone) | ||
|
||
cs.Subscribe(ctx, mockBackendConfig) | ||
}() | ||
|
||
testReports := []*types.PUReportedMetric{ | ||
{ | ||
ConnectionDetails: types.ConnectionDetails{ | ||
SourceID: sourceID, | ||
DestinationID: destinationID, | ||
SourceCategory: sourceCategory, | ||
}, | ||
PUDetails: types.PUDetails{ | ||
PU: reportedBy, | ||
TerminalPU: true, | ||
}, | ||
StatusDetail: &types.StatusDetail{ | ||
Count: 10, | ||
Status: "succeeded", | ||
}, | ||
}, | ||
{ | ||
ConnectionDetails: types.ConnectionDetails{ | ||
SourceID: sourceID, | ||
DestinationID: destinationID, | ||
SourceCategory: sourceCategory, | ||
}, | ||
PUDetails: types.PUDetails{ | ||
PU: reportedBy, | ||
TerminalPU: false, | ||
}, | ||
StatusDetail: &types.StatusDetail{ | ||
Count: 10, | ||
Status: "aborted", | ||
}, | ||
}, | ||
// { | ||
// ConnectionDetails: types.ConnectionDetails{ | ||
// SourceID: "momentum", | ||
// DestinationID: destinationID, | ||
// SourceCategory: sourceCategory, | ||
// }, | ||
// PUDetails: types.PUDetails{ | ||
// PU: reportedBy, | ||
// TerminalPU: false, | ||
// }, | ||
// StatusDetail: &types.StatusDetail{ | ||
// Count: 10, | ||
// Status: "momentum", | ||
// }, | ||
// }, | ||
} | ||
esr := NewEventStatsReporter(cs, statsStore) | ||
err := esr.Report(testReports, nil) | ||
require.NoError(t, err) | ||
require.Equal(t, statsStore.Get(EventsDeliveredMetricName, map[string]string{ | ||
"workspaceId": workspaceID, | ||
"sourceId": sourceID, | ||
"destinationId": destinationID, | ||
"reportedBy": reportedBy, | ||
"sourceCategory": sourceCategory, | ||
"terminal": "true", | ||
}).LastValue(), float64(10)) | ||
require.Equal(t, statsStore.Get(EventsAbortedMetricName, map[string]string{ | ||
"workspaceId": workspaceID, | ||
"sourceId": sourceID, | ||
"destinationId": destinationID, | ||
"reportedBy": reportedBy, | ||
"sourceCategory": sourceCategory, | ||
"terminal": "false", | ||
}).LastValue(), float64(10)) | ||
// require.Equal(t, statsStore.Get(EventsAbortedMetricName, map[string]string{ | ||
// "workspaceId": workspaceID, | ||
// "sourceId": "momentum", | ||
// "destinationId": destinationID, | ||
// "reportedBy": reportedBy, | ||
// "sourceCategory": sourceCategory, | ||
// "terminal": "false", | ||
// }), nil) | ||
} | ||
gane5hvarma marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import ( | |
"context" | ||
"database/sql" | ||
|
||
"github.com/rudderlabs/rudder-go-kit/stats" | ||
|
||
"golang.org/x/sync/errgroup" | ||
|
||
"github.com/rudderlabs/rudder-go-kit/config" | ||
|
@@ -18,11 +20,13 @@ type Mediator struct { | |
g *errgroup.Group | ||
ctx context.Context | ||
reporters []types.Reporting | ||
stats stats.Stats | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably skip setting in the struct since it's being used in the constructor only. wdyt? |
||
} | ||
|
||
func NewReportingMediator(ctx context.Context, log logger.Logger, enterpriseToken string, backendConfig backendconfig.BackendConfig) *Mediator { | ||
gane5hvarma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rm := &Mediator{ | ||
log: log, | ||
log: log, | ||
stats: stats.Default, | ||
} | ||
rm.g, rm.ctx = errgroup.WithContext(ctx) | ||
|
||
|
@@ -52,6 +56,7 @@ func NewReportingMediator(ctx context.Context, log logger.Logger, enterpriseToke | |
errorIndexReporter := NewErrorIndexReporter(rm.ctx, config.Default, rm.log, configSubscriber) | ||
rm.reporters = append(rm.reporters, errorIndexReporter) | ||
} | ||
rm.reporters = append(rm.reporters, NewEventStatsReporter(configSubscriber, rm.stats)) | ||
|
||
return rm | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion, would it be better if we use a single metric instead?
And have
status
as label/tag.It would make it more convenient in the future if we want to capture other categories, plus the summary (delivered+aborted) is a useful number and can be used on it own or to create percentages