Skip to content

Commit

Permalink
Improve metrics names, add internal-api auth call metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Oct 21, 2019
1 parent cd9394b commit 47bcf99
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func stream(uri string, w http.ResponseWriter, req *http.Request) {
duration := time.Now().Sub(start).Seconds()

if err != nil {
metrics.PlayerFailureSeconds.Observe(duration)
metrics.PlayerFailedDurations.Observe(duration)
if err.Error() == "paid stream" {
w.WriteHeader(http.StatusPaymentRequired)
} else {
Expand All @@ -37,7 +37,7 @@ func stream(uri string, w http.ResponseWriter, req *http.Request) {
w.Write([]byte(err.Error()))
}
} else {
metrics.PlayerResponseSeconds.Observe(duration)
metrics.PlayerSuccessDurations.Observe(duration)
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ func (c *Caller) call(rawQuery []byte) (*jsonrpc.RPCResponse, CallError) {

queryStartTime := time.Now()
r, err := c.sendQuery(q)
execTime := time.Now().Sub(queryStartTime).Seconds()
duration := time.Now().Sub(queryStartTime).Seconds()
if err != nil {
return r, NewInternalError(err)
}

if r.Error != nil {
metrics.ProxyCallFailureDurations.WithLabelValues(q.Method()).Observe(execTime)
metrics.ProxyCallFailedDurations.WithLabelValues(q.Method()).Observe(duration)
c.service.logger.LogFailedQuery(q.Method(), q.Params(), r.Error)
} else {
metrics.ProxyCallDurations.WithLabelValues(q.Method()).Observe(execTime)
c.service.logger.LogSuccessfulQuery(q.Method(), execTime, q.Params())
metrics.ProxyCallDurations.WithLabelValues(q.Method()).Observe(duration)
c.service.logger.LogSuccessfulQuery(q.Method(), duration, q.Params())
}

r, err = processResponse(q.Request, r)
Expand Down
13 changes: 11 additions & 2 deletions app/users/remote.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package users

import (
"github.com/lbryio/lbry.go/v2/extras/lbryinc"
"time"

"github.com/lbryio/lbrytv/config"
"github.com/lbryio/lbrytv/internal/metrics"

"github.com/lbryio/lbry.go/v2/extras/lbryinc"
)

// RemoteUser encapsulates internal-apis user data
Expand All @@ -18,12 +22,17 @@ func getRemoteUser(token string, remoteIP string) (*RemoteUser, error) {
RemoteIP: remoteIP,
})

start := time.Now()
r, err := c.UserMe()
duration := time.Now().Sub(start).Seconds()

if err != nil {
// Conn.Logger.LogF(monitor.F{monitor.TokenF: token}).Error("internal-api responded with an error: ", err)
// No user found in internal-apis database, give up at this point
metrics.IAPIAuthFailedDurations.Observe(duration)
return nil, err
}
metrics.IAPIAuthSuccessDurations.Observe(duration)

u.ID = int(r["id"].(float64))
if r["primary_email"] != nil {
u.Email = r["primary_email"].(string)
Expand Down
30 changes: 16 additions & 14 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,52 @@ const nsProxy = "proxy"

var (
PlayerStreamsRunning = promauto.NewGauge(prometheus.GaugeOpts{
Name: "player_streams_running",
Help: "Number of streams currently playing",
Namespace: nsPlayer,
Subsystem: "streams",
Name: "running",
Help: "Number of streams currently playing",
})
PlayerResponseSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
PlayerSuccessDurations = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: nsPlayer,
Subsystem: "response",
Name: "success_seconds",
Help: "Time to successful response",
})
PlayerFailureSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
PlayerFailedDurations = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: nsPlayer,
Subsystem: "failure_response",
Name: "seconds",
Subsystem: "response",
Name: "failed_seconds",
Help: "Time to failed response",
})

IAPIAuthSuccessSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
IAPIAuthSuccessDurations = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: nsIAPI,
Subsystem: "auth",
Name: "success_seconds",
Help: "Time to successful authentication",
})
IAPIAuthFailureSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
IAPIAuthFailedDurations = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: nsIAPI,
Subsystem: "auth",
Name: "failure_seconds",
Name: "failed_seconds",
Help: "Time to failed authentication response",
})

ProxyCallDurations = promauto.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: nsProxy,
Subsystem: "calls_durations",
Name: "seconds",
Subsystem: "calls",
Name: "successful_seconds",
Help: "Method call latency distributions",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
[]string{"method"},
)
ProxyCallFailureDurations = promauto.NewSummaryVec(
ProxyCallFailedDurations = promauto.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: nsProxy,
Subsystem: "failed_calls_durations",
Name: "seconds",
Subsystem: "calls",
Name: "failed_seconds",
Help: "Failed method call latency distributions",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
Expand Down

0 comments on commit 47bcf99

Please sign in to comment.