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

Make method* variables public #58

Merged
merged 2 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions app/proxy/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func processQuery(query *jsonrpc.RPCRequest) (processedQuery *jsonrpc.RPCRequest, err error) {
processedQuery = query
switch query.Method {
case methodGet:
case MethodGet:
processedQuery, err = queryProcessorGet(query)
}
return processedQuery, err
Expand All @@ -25,11 +25,11 @@ func processQuery(query *jsonrpc.RPCRequest) (processedQuery *jsonrpc.RPCRequest
func processResponse(query *jsonrpc.RPCRequest, response *jsonrpc.RPCResponse) (processedResponse *jsonrpc.RPCResponse, err error) {
processedResponse = response
switch query.Method {
case methodGet:
case MethodGet:
processedResponse, err = responseProcessorGet(query, response)
case methodFileList:
case MethodFileList:
processedResponse, err = responseProcessorFileList(query, response)
case methodAccountList:
case MethodAccountList:
processedResponse, err = responseProcessorAccountList(query, response)
}
return processedResponse, err
Expand Down
22 changes: 11 additions & 11 deletions app/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ var accountSpecificMethods = []string{
"utxo_release",
}

const methodGet = "get"
const methodFileList = "file_list"
const methodAccountList = "account_list"
const methodAccountBalance = "account_balance"
const methodStatus = "status"
const methodResolve = "resolve"
const methodClaimSearch = "claim_search"
const methodCommentList = "comment_list"
const MethodGet = "get"
const MethodFileList = "file_list"
const MethodAccountList = "account_list"
const MethodAccountBalance = "account_balance"
const MethodStatus = "status"
const MethodResolve = "resolve"
const MethodClaimSearch = "claim_search"
const MethodCommentList = "comment_list"

const paramAccountID = "account_id"
const paramUrls = "urls"

var ignoreLog = []string{
methodAccountBalance,
methodStatus,
MethodAccountBalance,
MethodStatus,
}

var ResolveTime float64
Expand Down Expand Up @@ -211,7 +211,7 @@ func ForwardCall(request jsonrpc.RPCRequest) ([]byte, error) {

// shouldCache returns true if we got a resolve query with more than `cacheResolveLongerThan` urls in it.
func shouldCache(method string, params interface{}) bool {
if method == methodResolve && params != nil {
if method == MethodResolve && params != nil {
paramsMap := params.(map[string]interface{})
if urls, ok := paramsMap[paramUrls].([]interface{}); ok {
if len(urls) > cacheResolveLongerThan {
Expand Down
18 changes: 9 additions & 9 deletions app/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestForwardCall_HTTPError(t *testing.T) {
config.Override("Lbrynet", "http://127.0.0.1:49999")
defer config.RestoreOverridden()

query := jsonrpc.NewRequest(methodAccountBalance)
query := jsonrpc.NewRequest(MethodAccountBalance)
response, err := ForwardCall(*query)
assert.NotNil(t, err)
assert.Nil(t, response)
Expand Down Expand Up @@ -209,18 +209,18 @@ func TestForwardCall_ClientError(t *testing.T) {
}

func TestForwardCall_InvalidResolveParams(t *testing.T) {
r := call(t, methodResolve)
r := call(t, MethodResolve)
assert.NotNil(t, r.Error)
assert.Equal(t, "jsonrpc_resolve() missing 1 required positional argument: 'urls'", r.Error.Message)
}

func TestForwardCall_shouldLog(t *testing.T) {
hook := test.NewLocal(monitor.Logger)

call(t, methodResolve, map[string]interface{}{"urls": "what"})
assert.Equal(t, methodResolve, hook.LastEntry().Data["method"])
call(t, methodAccountBalance)
assert.Equal(t, methodResolve, hook.LastEntry().Data["method"])
call(t, MethodResolve, map[string]interface{}{"urls": "what"})
assert.Equal(t, MethodResolve, hook.LastEntry().Data["method"])
call(t, MethodAccountBalance)
assert.Equal(t, MethodResolve, hook.LastEntry().Data["method"])
}

func TestUnmarshalRequest(t *testing.T) {
Expand All @@ -241,7 +241,7 @@ func TesProxyWithCache(t *testing.T) {

resolveArgs := map[string][110]string{paramUrls: homePageUrls}

query = jsonrpc.NewRequest(methodResolve, resolveArgs)
query = jsonrpc.NewRequest(MethodResolve, resolveArgs)
queryBody, _ := json.Marshal(query)
query, err = UnmarshalRequest(queryBody)
rawResponse, err = ForwardCall(*query)
Expand Down Expand Up @@ -274,7 +274,7 @@ func TesProxyWithCache(t *testing.T) {
}

func BenchmarkResolve(b *testing.B) {
query := jsonrpc.NewRequest(methodResolve, map[string][110]string{paramUrls: homePageUrls})
query := jsonrpc.NewRequest(MethodResolve, map[string][110]string{paramUrls: homePageUrls})

wg := sync.WaitGroup{}

Expand All @@ -299,7 +299,7 @@ func BenchmarkResolve(b *testing.B) {

func BenchmarkDirectResolve(b *testing.B) {
rpcClient := jsonrpc.NewClient(config.GetLbrynet())
query := jsonrpc.NewRequest(methodResolve, map[string][110]string{paramUrls: homePageUrls})
query := jsonrpc.NewRequest(MethodResolve, map[string][110]string{paramUrls: homePageUrls})

wg := sync.WaitGroup{}

Expand Down
2 changes: 1 addition & 1 deletion app/proxy/query_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func getPreconditionedQueryResponse(method string, params interface{}) *jsonrpc.
}
}

if method == methodStatus {
if method == MethodStatus {
var r jsonrpc.RPCResponse
r.Result = getStatusResponse()
return &r
Expand Down
4 changes: 2 additions & 2 deletions app/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (q *Query) paramsForLog() map[string]interface{} {

// cacheHit returns true if we got a resolve query with more than `cacheResolveLongerThan` urls in it.
func (q *Query) isCacheable() bool {
if q.Method() == methodResolve && q.Params() != nil {
if q.Method() == MethodResolve && q.Params() != nil {
paramsMap := q.Params().(map[string]interface{})
if urls, ok := paramsMap[paramUrls].([]interface{}); ok {
if len(urls) > cacheResolveLongerThan {
Expand Down Expand Up @@ -163,7 +163,7 @@ func (q *Query) cacheHit() *jsonrpc.RPCResponse {
}

func (q *Query) predefinedResponse() *jsonrpc.RPCResponse {
if q.Method() == methodStatus {
if q.Method() == MethodStatus {
response := q.newResponse()
response.Result = getStatusResponse()
return response
Expand Down
42 changes: 22 additions & 20 deletions internal/metrics_server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package metrics_server

import (
"fmt"
"net/http"
"runtime"
"sync"
Expand All @@ -16,6 +17,15 @@ import (

var once sync.Once

var monitoredProxyCalls = []string{
proxy.MethodClaimSearch,
proxy.MethodResolve,
proxy.MethodAccountBalance,
proxy.MethodAccountList,
proxy.MethodGet,
proxy.MethodFileList,
}

type Server struct {
monitor.ModuleLogger

Expand All @@ -41,26 +51,18 @@ func (s *Server) Serve() {
}

func (s *Server) registerMetrics() {
if err := prometheus.Register(prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Subsystem: "proxy",
Name: "resolve_time",
Help: "Time to serve a single resolve call.",
},
func() float64 { return s.proxy.GetMetricsValue("resolve").Value },
)); err == nil {
s.Log().Info("gauge 'proxy_resolve_time' registered")
}

if err := prometheus.Register(prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Subsystem: "proxy",
Name: "claim_search_time",
Help: "Time to serve a claim_search call.",
},
func() float64 { return s.proxy.GetMetricsValue("claim_search").Value },
)); err == nil {
s.Log().Info("gauge 'proxy_claim_search' registered")
for _, m := range monitoredProxyCalls {
m := m
if err := prometheus.Register(prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Subsystem: "proxy",
Name: fmt.Sprintf("%v_time", m),
Help: "Time to serve a single resolve call.",
},
func() float64 { return s.proxy.GetMetricsValue(m).Value },
)); err == nil {
s.Log().Infof("gauge 'proxy_%v_time' registered", m)
}
}

if err := prometheus.Register(prometheus.NewGaugeFunc(
Expand Down