diff --git a/e2e/fcm_e2e_test.go b/e2e/fcm_e2e_test.go index 86315ac..db5dbb0 100644 --- a/e2e/fcm_e2e_test.go +++ b/e2e/fcm_e2e_test.go @@ -122,6 +122,10 @@ func (s *FcmE2ETestSuite) TestSimpleNotification() { Timing("send_notification_latency", gomock.Any(), gomock.Any(), gomock.Any()). Return(nil) + statsdClientMock.EXPECT(). + Timing("firebase_latency", gomock.Any(), gomock.Any(), gomock.Any()). + Return(nil) + err = producer.Produce(&kafka.Message{ TopicPartition: kafka.TopicPartition{ Topic: &topic, @@ -186,6 +190,11 @@ func (s *FcmE2ETestSuite) TestMultipleNotifications() { Times(notificationsToSend). Return(nil) + statsdClientMock.EXPECT(). + Timing("firebase_latency", gomock.Any(), gomock.Any(), gomock.Any()). + Times(notificationsToSend). + Return(nil) + for i := 0; i < notificationsToSend; i++ { err = producer.Produce(&kafka.Message{ TopicPartition: kafka.TopicPartition{ diff --git a/extensions/datadog_statsd.go b/extensions/datadog_statsd.go index e8c6a58..b715bb6 100644 --- a/extensions/datadog_statsd.go +++ b/extensions/datadog_statsd.go @@ -141,7 +141,7 @@ func (s *StatsD) ReportGoStats( func (s *StatsD) ReportSendNotificationLatency(latencyMs time.Duration, game string, platform string, labels ...string) { metricLabels := []string{fmt.Sprintf("platform:%s", platform), fmt.Sprintf("game:%s", game)} for i := 0; i < len(labels); i += 2 { - metricLabels = append(labels, fmt.Sprintf("%s:%s", labels[i], labels[i+1])) + metricLabels = append(metricLabels, fmt.Sprintf("%s:%s", labels[i], labels[i+1])) } s.Client.Timing( "send_notification_latency", @@ -151,6 +151,19 @@ func (s *StatsD) ReportSendNotificationLatency(latencyMs time.Duration, game str ) } +func (s *StatsD) ReportFirebaseLatency(latencyMs time.Duration, game string, labels ...string) { + metricLabels := []string{fmt.Sprintf("game:%s", game)} + for i := 0; i < len(labels); i += 2 { + metricLabels = append(metricLabels, fmt.Sprintf("%s:%s", labels[i], labels[i+1])) + } + s.Client.Timing( + "firebase_latency", + latencyMs, + metricLabels, + 1, + ) +} + // ReportMetricGauge reports a metric as a Gauge with hostname, game and platform // as tags func (s *StatsD) ReportMetricGauge( diff --git a/extensions/handler/message_handler.go b/extensions/handler/message_handler.go index e491da5..ca9edd2 100644 --- a/extensions/handler/message_handler.go +++ b/extensions/handler/message_handler.go @@ -112,7 +112,10 @@ func (h *messageHandler) sendPush(ctx context.Context, msg interfaces.Message) { h.sendPushConcurrencyControl <- l }() + before := time.Now() err := h.client.SendPush(ctx, msg) + h.reportFirebaseLatency(time.Since(before)) + h.handleNotificationSent() h.responsesChannel <- struct { @@ -228,6 +231,12 @@ func (h *messageHandler) reportLatency(latency time.Duration) { } } +func (h *messageHandler) reportFirebaseLatency(latency time.Duration) { + for _, statsReporter := range h.statsReporters { + statsReporter.ReportFirebaseLatency(latency, h.app) + } +} + func translateToPushError(err error) *pushErrors.PushError { if pusherError, ok := err.(*pushErrors.PushError); ok { return pusherError diff --git a/interfaces/stats_reporter.go b/interfaces/stats_reporter.go index 02315ca..b665246 100644 --- a/interfaces/stats_reporter.go +++ b/interfaces/stats_reporter.go @@ -39,4 +39,5 @@ type StatsReporter interface { ReportMetricCount(metric string, value int64, game string, platform string) NotificationRateLimitReached(game string, platform string) ReportSendNotificationLatency(latencyMs time.Duration, game string, platform string, labels ...string) + ReportFirebaseLatency(latencyMs time.Duration, game string, labels ...string) }