Skip to content

Commit

Permalink
Simplify metrics tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
boreq committed Nov 1, 2023
1 parent 70e184f commit 3ec6b46
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
17 changes: 5 additions & 12 deletions service/adapters/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,12 @@ func (p *Prometheus) ReportNumberOfPublicKeyDownloaderRelays(publicKey domain.Pu
p.numberOfPublicKeyDownloaderRelaysGauge.With(prometheus.Labels{labelPublicKey: publicKey.Hex()}).Set(float64(n))
}

func (p *Prometheus) ReportRelayConnectionState(relayAddress domain.RelayAddress, state app.RelayConnectionState) {
switch state {
case app.RelayConnectionStateDisconnected:
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: app.RelayConnectionStateInitializing.String()}).Set(0)
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: app.RelayConnectionStateConnected.String()}).Set(0)
case app.RelayConnectionStateConnected:
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: app.RelayConnectionStateInitializing.String()}).Set(0)
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: app.RelayConnectionStateDisconnected.String()}).Set(0)
case app.RelayConnectionStateInitializing:
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: app.RelayConnectionStateDisconnected.String()}).Set(0)
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: app.RelayConnectionStateConnected.String()}).Set(0)
func (p *Prometheus) ReportRelayConnectionState(m map[domain.RelayAddress]app.RelayConnectionState) {
p.relayConnectionStateGauge.Reset()

for relayAddress, state := range m {
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: state.String()}).Set(1)
}
p.relayConnectionStateGauge.With(prometheus.Labels{labelRelayAddress: relayAddress.String(), labelState: state.String()}).Set(1)
}

func (p *Prometheus) ReportCallingTwitterAPIToPostATweet(err error) {
Expand Down
4 changes: 3 additions & 1 deletion service/adapters/relay_event_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ func (d *RelayEventDownloader) storeMetrics() {
d.connectionsLock.Lock()
defer d.connectionsLock.Unlock()

m := make(map[domain.RelayAddress]app.RelayConnectionState)
for _, connection := range d.connections {
d.metrics.ReportRelayConnectionState(connection.Address(), connection.State())
m[connection.Address()] = connection.State()
}
d.metrics.ReportRelayConnectionState(m)
}

func (r *RelayEventDownloader) getConnection(relayAddress domain.RelayAddress) *RelayConnection {
Expand Down
4 changes: 2 additions & 2 deletions service/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ type Metrics interface {
StartApplicationCall(handlerName string) ApplicationCall
ReportNumberOfPublicKeyDownloaders(n int)
ReportNumberOfPublicKeyDownloaderRelays(publicKey domain.PublicKey, n int)
ReportRelayConnectionState(relayAddress domain.RelayAddress, state RelayConnectionState)
ReportRelayConnectionState(m map[domain.RelayAddress]RelayConnectionState)
ReportCallingTwitterAPIToPostATweet(err error)
ReportCallingTwitterAPIToGetAUser(err error)
ReportSubscriptionQueueLength(topic string, n int)
ReportPurplePagesLookupResult(err *error)
ReportTweetCreatedCountPerAccount(map[accounts.AccountID]int)
ReportTweetCreatedCountPerAccount(m map[accounts.AccountID]int)
}

type ApplicationCall interface {
Expand Down

0 comments on commit 3ec6b46

Please sign in to comment.