Skip to content

Commit

Permalink
Annotate purple pages metrics with error description
Browse files Browse the repository at this point in the history
  • Loading branch information
boreq committed Nov 15, 2023
1 parent 4a5020a commit 2369545
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions service/adapters/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/boreq/errors"
"github.com/planetary-social/nos-crossposting-service/internal/logging"
"github.com/planetary-social/nos-crossposting-service/service/adapters"
"github.com/planetary-social/nos-crossposting-service/service/adapters/twitter"
"github.com/planetary-social/nos-crossposting-service/service/app"
"github.com/planetary-social/nos-crossposting-service/service/domain"
Expand Down Expand Up @@ -123,7 +124,7 @@ func NewPrometheus(logger logging.Logger) (*Prometheus, error) {
Name: "purple_pages_lookups",
Help: "Number of purple pages lookups.",
},
[]string{labelResult},
[]string{labelResult, labelErrorDescription},
)
tweetCreatedCountPerAccountGauge := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down Expand Up @@ -257,11 +258,13 @@ func (p *Prometheus) ReportSubscriptionQueueLength(topic string, n int) {
}

func (p *Prometheus) ReportPurplePagesLookupResult(err *error) {
var labels prometheus.Labels
if *err == nil {
labels = prometheus.Labels{labelResult: labelResultValueSuccess}
} else {
labels = prometheus.Labels{labelResult: labelResultValueError}
labels := prometheus.Labels{
labelResult: labelResultValueSuccess,
labelErrorDescription: "none",
}
if *err != nil {
labels[labelResult] = labelResultValueError
labels[labelErrorDescription] = p.getPurplePagesErrorDescription(*err)
}
p.purplePagesLookupResultCounter.With(labels).Inc()
}
Expand Down Expand Up @@ -297,6 +300,14 @@ func (p *Prometheus) getTwitterErrorDescription(err error) string {
return "unknown"
}

func (p *Prometheus) getPurplePagesErrorDescription(err error) string {
if errors.Is(err, adapters.ErrRelayListNotFoundInPurplePages) {
return "notFound"
}

return "unknown"
}

type ApplicationCall struct {
handlerName string
p *Prometheus
Expand Down

0 comments on commit 2369545

Please sign in to comment.