Skip to content

Commit d30b470

Browse files
authored
EmitAPIOutgoingEnvelopes per API method (#1765)
Label xmtp_api_outgoing_envelopes_total counter by API method Changes apiOutgoingEnvelopesTotal in pkg/metrics/api.go from a plain Counter to a CounterVec with a method label, so envelope counts are broken down per API procedure. Updates EmitAPIOutgoingEnvelopes (renamed from EmitApiOutgoingEnvelopes) to accept a method string parameter and call WithLabelValues(method) before incrementing. Updates all call sites in pkg/api/message/service.go and pkg/api/message/subscribe_topics.go to pass the procedure from the request or stream spec. Also renames EmitApiWaitForGatewayPublish and EmitApiStagedEnvelopeProcessingDelay to follow the EmitAPI… naming convention. Behavioral Change: existing dashboards or alerts querying xmtp_api_outgoing_envelopes_total without a method label filter will need to be updated to aggregate across the new label dimension.
1 parent 32bbca0 commit d30b470

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

pkg/api/message/publish_worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (p *publishWorker) start() {
117117
time.Sleep(p.sleepOnFailureTime)
118118
}
119119
p.lastProcessed.Store(stagedEnv.ID)
120-
metrics.EmitApiStagedEnvelopeProcessingDelay(time.Since(stagedEnv.OriginatorTime))
120+
metrics.EmitAPIStagedEnvelopeProcessingDelay(time.Since(stagedEnv.OriginatorTime))
121121
}
122122
}
123123
}

pkg/api/message/service.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (s *Service) sendEnvelopes(
302302
)
303303
}
304304

305-
metrics.EmitApiOutgoingEnvelopes(len(batch))
305+
metrics.EmitAPIOutgoingEnvelopes(stream.Conn().Spec().Procedure, len(batch))
306306

307307
batchWireBytes = 0
308308
batch = batch[:0]
@@ -434,7 +434,7 @@ func (s *Service) QueryEnvelopes(
434434
response.Msg.Envelopes = append(response.Msg.Envelopes, originatorEnv)
435435
}
436436

437-
metrics.EmitApiOutgoingEnvelopes(len(response.Msg.GetEnvelopes()))
437+
metrics.EmitAPIOutgoingEnvelopes(req.Spec().Procedure, len(response.Msg.GetEnvelopes()))
438438

439439
return response, nil
440440
}
@@ -975,7 +975,7 @@ func (s *Service) GetNewestEnvelope(
975975
sent++
976976
}
977977

978-
metrics.EmitApiOutgoingEnvelopes(sent)
978+
metrics.EmitAPIOutgoingEnvelopes(req.Spec().Procedure, sent)
979979

980980
return response, nil
981981
}
@@ -1149,7 +1149,7 @@ func (s *Service) waitForGatewayPublish(
11491149

11501150
startTime := time.Now()
11511151
defer func() {
1152-
metrics.EmitApiWaitForGatewayPublish(time.Since(startTime))
1152+
metrics.EmitAPIWaitForGatewayPublish(time.Since(startTime))
11531153
}()
11541154

11551155
timeout := time.After(30 * time.Second)

pkg/api/message/subscribe_topics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (s *Service) sendTopicEnvelopes(
348348
)
349349
}
350350

351-
metrics.EmitApiOutgoingEnvelopes(len(envs))
351+
metrics.EmitAPIOutgoingEnvelopes(stream.Conn().Spec().Procedure, len(envs))
352352

353353
return nil
354354
}

pkg/metrics/api.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var apiWaitForGatewayPublish = prometheus.NewHistogram(
9696
},
9797
)
9898

99-
func EmitApiWaitForGatewayPublish(
99+
func EmitAPIWaitForGatewayPublish(
100100
duration time.Duration,
101101
) {
102102
apiWaitForGatewayPublish.Observe(duration.Seconds())
@@ -109,17 +109,18 @@ var apiStagedEnvelopeProcessingDelay = prometheus.NewHistogram(
109109
},
110110
)
111111

112-
func EmitApiStagedEnvelopeProcessingDelay(duration time.Duration) {
112+
func EmitAPIStagedEnvelopeProcessingDelay(duration time.Duration) {
113113
apiStagedEnvelopeProcessingDelay.Observe(duration.Seconds())
114114
}
115115

116-
var apiOutgoingEnvelopesTotal = prometheus.NewCounter(
116+
var apiOutgoingEnvelopesTotal = prometheus.NewCounterVec(
117117
prometheus.CounterOpts{
118118
Name: "xmtp_api_outgoing_envelopes_total",
119119
Help: "Total number of envelopes delivered to clients via subscribe and query APIs",
120120
},
121+
[]string{"method"},
121122
)
122123

123-
func EmitApiOutgoingEnvelopes(n int) {
124-
apiOutgoingEnvelopesTotal.Add(float64(n))
124+
func EmitAPIOutgoingEnvelopes(method string, n int) {
125+
apiOutgoingEnvelopesTotal.WithLabelValues(method).Add(float64(n))
125126
}

0 commit comments

Comments
 (0)