From ecaa8c419cc1ef571e6e82640370030d88a69fcd Mon Sep 17 00:00:00 2001 From: miguelreiswildlife Date: Thu, 30 May 2024 14:25:22 -0300 Subject: [PATCH 1/3] Fix metric label building --- extensions/datadog_statsd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/datadog_statsd.go b/extensions/datadog_statsd.go index 125974b..8640c7d 100644 --- a/extensions/datadog_statsd.go +++ b/extensions/datadog_statsd.go @@ -132,7 +132,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", From 302e7e41406a2233ac719d0c9581ed91a81281f0 Mon Sep 17 00:00:00 2001 From: miguelreiswildlife Date: Thu, 30 May 2024 16:45:30 -0300 Subject: [PATCH 2/3] Fix labels and add timing metric for actual request --- extensions/datadog_statsd.go | 13 +++++++++++++ extensions/handler/message_handler.go | 9 +++++++++ interfaces/stats_reporter.go | 1 + 3 files changed, 23 insertions(+) diff --git a/extensions/datadog_statsd.go b/extensions/datadog_statsd.go index 8640c7d..fdf1a3f 100644 --- a/extensions/datadog_statsd.go +++ b/extensions/datadog_statsd.go @@ -142,6 +142,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 4a0f48b..79b8e29 100644 --- a/interfaces/stats_reporter.go +++ b/interfaces/stats_reporter.go @@ -37,4 +37,5 @@ type StatsReporter interface { ReportMetricGauge(metric string, value float64, game string, platform string) ReportMetricCount(metric string, value int64, game string, platform string) ReportSendNotificationLatency(latencyMs time.Duration, game string, platform string, labels ...string) + ReportFirebaseLatency(latencyMs time.Duration, game string, labels ...string) } From 9a8eee7b89c7b6997d07b1ccd3c28259b517593c Mon Sep 17 00:00:00 2001 From: miguelreiswildlife Date: Thu, 30 May 2024 17:46:02 -0300 Subject: [PATCH 3/3] Fix tests --- e2e/fcm_e2e_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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{