Skip to content

Commit

Permalink
Emit subscribed topics metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Normore committed Dec 29, 2023
1 parent 816d956 commit c43a2f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1140,14 +1140,6 @@ github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0
github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xmtp/go-msgio v0.2.1-0.20220510223757-25a701b79cd3 h1:wzUffJGCTBGXIDyNU+1UBu1fn2Nzo+OQzM1pLrheh58=
github.com/xmtp/go-msgio v0.2.1-0.20220510223757-25a701b79cd3/go.mod h1:bJREWk+NDnZYjgLQdAi8SUWuq/5pkMme4GqiffEhUF4=
github.com/xmtp/proto/v3 v3.27.0 h1:G70006UEffkCmWvp9G/7Dywosj1sLm9StR5HWEb891U=
github.com/xmtp/proto/v3 v3.27.0/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY=
github.com/xmtp/proto/v3 v3.29.1-0.20231019020501-b49bc6ffb5eb h1:q2lR64lGFehm8m0FtcdRDMeH8MlkMyU4sz235+Ufq9E=
github.com/xmtp/proto/v3 v3.29.1-0.20231019020501-b49bc6ffb5eb/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY=
github.com/xmtp/proto/v3 v3.29.1-0.20231019022514-1cc4b0d5a51a h1:kDEPyzhqQO9YdRAfvl21ysitvzWjdu4Ai8YCvHwqqbY=
github.com/xmtp/proto/v3 v3.29.1-0.20231019022514-1cc4b0d5a51a/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY=
github.com/xmtp/proto/v3 v3.29.1-0.20231019163152-2a17d00f45f4 h1:Mxnc833msN9gX8DJyELd+E7oUJNHlhbIsZlTd88kg5M=
github.com/xmtp/proto/v3 v3.29.1-0.20231019163152-2a17d00f45f4/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY=
github.com/xmtp/proto/v3 v3.30.0 h1:x6LGCWpO2HTQNhUiTXfE0l+u2HSL3Z35p41xhgy6hlw=
github.com/xmtp/proto/v3 v3.30.0/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/message/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ func (s *Service) Subscribe(req *proto.SubscribeRequest, stream proto.MessageApi
// See: https://github.com/xmtp/libxmtp/pull/58
_ = stream.SendHeader(metadata.Pairs("subscribed", "true"))

metrics.EmitSubscribeTopicsLength(stream.Context(), log, len(req.ContentTopics))

var streamLock sync.Mutex
for _, topic := range req.ContentTopics {
subject := topic
Expand Down Expand Up @@ -278,6 +280,8 @@ func (s *Service) Subscribe2(stream proto.MessageApi_Subscribe2Server) error {
}
log.Info("updating subscription", zap.Int("num_content_topics", len(req.ContentTopics)))

metrics.EmitSubscribeTopicsLength(stream.Context(), log, len(req.ContentTopics))

topics := map[string]bool{}
for _, topic := range req.ContentTopics {
topics[topic] = true
Expand Down
14 changes: 14 additions & 0 deletions pkg/metrics/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ func EmitAPIRequest(ctx context.Context, log *zap.Logger, fields []zapcore.Field
apiRequests.With(labels).Inc()
}

var subscribeTopicsLength = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "xmtp_subscribe_topics_length",
Help: "Number of subscribed topics per request",
Buckets: []float64{1, 2, 4, 8, 16, 50, 100, 10000, 100000},
},
appClientVersionTagKeys,
)

func EmitSubscribeTopicsLength(ctx context.Context, log *zap.Logger, topics int) {
labels := contextLabels(ctx)
subscribeTopicsLength.With(labels).Observe(float64(topics))
}

var publishedEnvelopeSize = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "xmtp_published_envelope",
Expand Down

0 comments on commit c43a2f7

Please sign in to comment.