Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try goroutines for metrics #92

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions service/adapters/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,41 +237,43 @@ func (p *Prometheus) StartApplicationCall(handlerName string) app.ApplicationCal
}

func (p *Prometheus) ReportNumberOfRelayDownloaders(n int) {
p.relayDownloadersGauge.Set(float64(n))
go p.relayDownloadersGauge.Set(float64(n))
}

func (p *Prometheus) ReportRelayConnectionsState(m map[domain.RelayAddress]relays.RelayConnectionState) {
p.relayConnectionStateGauge.Reset()
for address, state := range m {
p.relayConnectionStateGauge.With(
prometheus.Labels{
labelConnectionState: state.String(),
labelAddress: address.String(),
},
).Set(1)
}
go func() {
p.relayConnectionStateGauge.Reset()
for address, state := range m {
p.relayConnectionStateGauge.With(
prometheus.Labels{
labelConnectionState: state.String(),
labelAddress: address.String(),
},
).Set(1)
}
}()
}

func (p *Prometheus) ReportReceivedEvent(address domain.RelayAddress) {
p.receivedEventsCounter.With(prometheus.Labels{labelAddress: address.String()}).Inc()
go p.receivedEventsCounter.With(prometheus.Labels{labelAddress: address.String()}).Inc()
}

func (p *Prometheus) ReportQueueLength(topic string, n int) {
p.subscriptionQueueLengthGauge.With(prometheus.Labels{labelTopic: topic}).Set(float64(n))
go p.subscriptionQueueLengthGauge.With(prometheus.Labels{labelTopic: topic}).Set(float64(n))
}

func (p *Prometheus) ReportQueueOldestMessageAge(topic string, age time.Duration) {
p.subscriptionQueueOldestMessageAgeGauge.With(prometheus.Labels{labelTopic: topic}).Set(age.Seconds())
go p.subscriptionQueueOldestMessageAgeGauge.With(prometheus.Labels{labelTopic: topic}).Set(age.Seconds())
}

func (p *Prometheus) ReportNumberOfSubscriptions(address domain.RelayAddress, n int) {
p.relayConnectionSubscriptionsGauge.With(prometheus.Labels{
go p.relayConnectionSubscriptionsGauge.With(prometheus.Labels{
labelAddress: address.String(),
}).Set(float64(n))
}

func (p *Prometheus) ReportRateLimitBackoffMs(address domain.RelayAddress, n int) {
p.relayRateLimitBackoffMsGauge.With(prometheus.Labels{
go p.relayRateLimitBackoffMsGauge.With(prometheus.Labels{
labelAddress: address.HostWithoutPort(),
}).Set(float64(n))
}
Expand All @@ -282,34 +284,34 @@ func (p *Prometheus) ReportMessageReceived(address domain.RelayAddress, messageT
labelMessageType: messageType.String(),
}
setResultLabel(labels, err)
p.relayConnectionReceivedMessagesCounter.With(labels).Inc()
go p.relayConnectionReceivedMessagesCounter.With(labels).Inc()
}

func (p *Prometheus) ReportRelayDisconnection(address domain.RelayAddress, err error) {
p.relayConnectionDisconnectionsCounter.With(prometheus.Labels{
go p.relayConnectionDisconnectionsCounter.With(prometheus.Labels{
labelAddress: address.String(),
labelReason: p.getDisconnectionReason(err),
}).Inc()
}

func (p *Prometheus) ReportNumberOfStoredRelayAddresses(n int) {
p.storedRelayAddressesGauge.Set(float64(n))
go p.storedRelayAddressesGauge.Set(float64(n))
}

func (p *Prometheus) ReportNumberOfStoredEvents(n int) {
p.storedEventsGauge.Set(float64(n))
go p.storedEventsGauge.Set(float64(n))
}

func (p *Prometheus) ReportEventSentToRelay(address domain.RelayAddress, decision app.SendEventToRelayDecision, result app.SendEventToRelayResult) {
p.eventsSentToRelayCounter.With(prometheus.Labels{
go p.eventsSentToRelayCounter.With(prometheus.Labels{
labelAddress: address.String(),
labelDecision: decision.String(),
labelResult: result.String(),
}).Inc()
}

func (p *Prometheus) ReportNotice(address domain.RelayAddress, noticeType relays.NoticeType) {
p.noticeTypeCounter.With(prometheus.Labels{
go p.noticeTypeCounter.With(prometheus.Labels{
labelAddress: address.String(),
labelNoticeType: string(noticeType),
}).Inc()
Expand Down Expand Up @@ -361,7 +363,7 @@ func (a *ApplicationCall) End(err *error) {

labels := a.getLabels(err)
a.p.applicationHandlerCallsCounter.With(labels).Inc()
a.p.applicationHandlerCallDurationHistogram.With(labels).Observe(duration.Seconds())
go a.p.applicationHandlerCallDurationHistogram.With(labels).Observe(duration.Seconds())
}

func (a *ApplicationCall) getLabels(err *error) prometheus.Labels {
Expand Down
Loading