Skip to content

Commit

Permalink
Merge dea01ec into 32c2934
Browse files Browse the repository at this point in the history
  • Loading branch information
cosminrentea committed Mar 20, 2017
2 parents 32c2934 + dea01ec commit f9f065e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/fcm/fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (f *fcm) HandleResponse(request connector.Request, responseIface interface{
if err != nil && !isValidResponseError(err) {
logger.WithField("error", err.Error()).Error("Error sending message to FCM")
mTotalSendErrors.Add(1)
pSendErrors.Inc()
if *f.IntervalMetrics && metadata != nil {
addToLatenciesAndCountsMaps(currentTotalErrorsLatenciesKey, currentTotalErrorsKey, metadata.Latency)
}
Expand All @@ -98,6 +99,7 @@ func (f *fcm) HandleResponse(request connector.Request, responseIface interface{
response, ok := responseIface.(*gcm.Response)
if !ok {
mTotalResponseErrors.Add(1)
pResponseErrors.Inc()
return fmt.Errorf("Invalid FCM Response")
}

Expand All @@ -110,6 +112,7 @@ func (f *fcm) HandleResponse(request connector.Request, responseIface interface{
}
if response.Ok() {
mTotalSentMessages.Add(1)
pSent.Inc()
if *f.IntervalMetrics && metadata != nil {
addToLatenciesAndCountsMaps(currentTotalMessagesLatenciesKey, currentTotalMessagesKey, metadata.Latency)
}
Expand All @@ -123,6 +126,7 @@ func (f *fcm) HandleResponse(request connector.Request, responseIface interface{
logger.Debug("Removing not registered FCM subscription")
f.Manager().Remove(subscriber)
mTotalResponseNotRegisteredErrors.Add(1)
pResponseNotRegisteredErrors.Inc()
return response.Error
case "InvalidRegistration":
logger.WithField("jsonError", errText).Error("InvalidRegistration of FCM subscription")
Expand All @@ -132,10 +136,12 @@ func (f *fcm) HandleResponse(request connector.Request, responseIface interface{

if response.CanonicalIDs != 0 {
mTotalReplacedCanonicalErrors.Add(1)
pResponseReplacedCanonicalErrors.Inc()
// we only send to one receiver, so we know that we can replace the old id with the first registration id (=canonical id)
return f.replaceCanonical(request.Subscriber(), response.Results[0].RegistrationID)
}
mTotalResponseOtherErrors.Add(1)
pResponseOtherErrors.Inc()
return nil
}

Expand Down
54 changes: 54 additions & 0 deletions server/fcm/fcm_prometheus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fcm

import (
"github.com/prometheus/client_golang/prometheus"
)

var (
pSent = prometheus.NewCounter(prometheus.CounterOpts{
Name: "fcm_sent",
Help: "Number of messages sent to FCM",
})

pSendErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "fcm_send_errors",
Help: "Number of FCM errors when trying to send",
})

pResponseErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "fcm_response_errors",
Help: "Number of FCM errors received as responses",
})

pResponseInternalErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "fcm_response_internal_errors",
Help: "Number of internal errors related to FCM responses",
})

pResponseNotRegisteredErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "fcm_response_not_registered_errors",
Help: "Number of errors related to not registered states in FCM connector",
})

pResponseReplacedCanonicalErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "fcm_response_replaced_canonical_errors",
Help: "Number of errors related to canonical IDs in FCM connector",
})

pResponseOtherErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "fcm_response_other_errors",
Help: "Number of other errors related to responses in the FCM connector",
})
)

func init() {
prometheus.MustRegister(
pSent,
pSendErrors,
pResponseErrors,
pResponseInternalErrors,
pResponseNotRegisteredErrors,
pResponseReplacedCanonicalErrors,
pResponseOtherErrors,
)
}

0 comments on commit f9f065e

Please sign in to comment.