Skip to content

Commit

Permalink
Slightly better metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvolp12 committed Mar 23, 2024
1 parent 04f1d94 commit 1706055
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sonar/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var rebasesProcessedCounter = promauto.NewCounterVec(prometheus.CounterOpts{
var recordsProcessedCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "sonar_records_processed_total",
Help: "The total number of records processed by Sonar",
}, []string{"record_type", "socket_url"})
}, []string{"action", "socket_url", "record_type"})

var quoteRepostsProcessedCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "sonar_quote_reposts_processed_total",
Expand Down
26 changes: 17 additions & 9 deletions sonar/sonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,43 +226,51 @@ func (s *Sonar) HandleRepoCommit(ctx context.Context, evt *comatproto.SyncSubscr
break
}

labelValues := []string{op.Action, s.SocketURL}

var recCreatedAt time.Time
var parseError error

// Unpack the record and process it
switch rec := rec.(type) {
case *bsky.FeedPost:
recordsProcessedCounter.WithLabelValues("feed_post", s.SocketURL).Inc()
labelValues = append(labelValues, "feed_post")
if rec.Embed != nil && rec.Embed.EmbedRecord != nil && rec.Embed.EmbedRecord.Record != nil {
quoteRepostsProcessedCounter.WithLabelValues(s.SocketURL).Inc()
}
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.FeedLike:
recordsProcessedCounter.WithLabelValues("feed_like", s.SocketURL).Inc()
labelValues = append(labelValues, "feed_like")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.FeedRepost:
recordsProcessedCounter.WithLabelValues("feed_repost", s.SocketURL).Inc()
labelValues = append(labelValues, "feed_repost")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.GraphBlock:
recordsProcessedCounter.WithLabelValues("graph_block", s.SocketURL).Inc()
labelValues = append(labelValues, "graph_block")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.GraphFollow:
recordsProcessedCounter.WithLabelValues("graph_follow", s.SocketURL).Inc()
labelValues = append(labelValues, "graph_follow")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.ActorProfile:
recordsProcessedCounter.WithLabelValues("actor_profile", s.SocketURL).Inc()
labelValues = append(labelValues, "actor_profile")
case *bsky.FeedGenerator:
recordsProcessedCounter.WithLabelValues("feed_generator", s.SocketURL).Inc()
labelValues = append(labelValues, "feed_generator")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.GraphList:
recordsProcessedCounter.WithLabelValues("graph_list", s.SocketURL).Inc()
labelValues = append(labelValues, "graph_list")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.GraphListitem:
recordsProcessedCounter.WithLabelValues("graph_listitem", s.SocketURL).Inc()
labelValues = append(labelValues, "graph_listitem")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.FeedThreadgate:
labelValues = append(labelValues, "feed_threadgate")
recCreatedAt, parseError = dateparse.ParseAny(rec.CreatedAt)
case *bsky.LabelerService:
labelValues = append(labelValues, "labeler_service")
default:
log.Warn("unknown record type", "rec", rec)
}
recordsProcessedCounter.WithLabelValues(labelValues...).Inc()
if parseError != nil {
s.Logger.Error("error parsing time", "err", parseError)
continue
Expand Down

0 comments on commit 1706055

Please sign in to comment.