-
Notifications
You must be signed in to change notification settings - Fork 329
/
Copy pathevent_stats.go
67 lines (57 loc) · 2.1 KB
/
event_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package reporting
import (
"context"
"strconv"
"github.com/rudderlabs/rudder-go-kit/stats"
"github.com/rudderlabs/rudder-server/jobsdb"
. "github.com/rudderlabs/rudder-server/utils/tx" //nolint:staticcheck
"github.com/rudderlabs/rudder-server/utils/types"
)
type EventStatsReporter struct {
stats stats.Stats
configSubscriber *configSubscriber
}
const EventStream = "event-stream"
func NewEventStatsReporter(configSubscriber *configSubscriber, stats stats.Stats) *EventStatsReporter {
return &EventStatsReporter{
stats: stats,
configSubscriber: configSubscriber,
}
}
const EventsProcessedMetricName = "events_processed_total"
func (es *EventStatsReporter) Record(metrics []*types.PUReportedMetric) {
for index := range metrics {
sourceCategory := metrics[index].ConnectionDetails.SourceCategory
if sourceCategory == "" {
sourceCategory = EventStream
}
terminal := strconv.FormatBool(metrics[index].PUDetails.TerminalPU)
status := metrics[index].StatusDetail.Status
if status == jobsdb.Aborted.State {
terminal = "true"
}
tags := stats.Tags{
"workspaceId": es.configSubscriber.WorkspaceIDFromSource(metrics[index].ConnectionDetails.SourceID),
"sourceId": metrics[index].ConnectionDetails.SourceID,
"destinationId": metrics[index].ConnectionDetails.DestinationID,
"reportedBy": metrics[index].PUDetails.PU,
"sourceCategory": sourceCategory,
"statusCode": strconv.Itoa(metrics[index].StatusDetail.StatusCode),
"terminal": terminal,
"destinationType": es.configSubscriber.GetDestDetail(metrics[index].ConnectionDetails.DestinationID).destType,
"status": status,
}
es.stats.NewTaggedStat(EventsProcessedMetricName, stats.CountType, tags).Count(int(metrics[index].StatusDetail.Count))
}
}
func (es *EventStatsReporter) Report(_ context.Context, metrics []*types.PUReportedMetric, tx *Tx) error {
tx.AddSuccessListener(func() {
es.Record(metrics)
})
return nil
}
func (es *EventStatsReporter) Stop() {
}
func (es *EventStatsReporter) DatabaseSyncer(c types.SyncerConfig) types.ReportingSyncer {
return func() {}
}