-
Notifications
You must be signed in to change notification settings - Fork 198
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
Add peer info route #1918
Add peer info route #1918
Conversation
api/node/routes.go
Outdated
} | ||
|
||
queryVals := c.Request.URL.Query() | ||
pids := queryVals["pid"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move magic strings to constants "pid", "info" "succesful" "internal error"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess they will be replaced anyway when @bogdan-rosianu's PR will enter development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced magic sting "pid", the other remained as they will be replaced.
api/node/routes.go
Outdated
@@ -20,9 +20,17 @@ type FacadeHandler interface { | |||
TpsBenchmark() *statistics.TpsBenchmark | |||
StatusMetrics() external.StatusMetricsHandler | |||
GetQueryHandler(name string) (debug.QueryHandler, error) | |||
GetPeerInfo(pid string) ([]interface{}, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this be changed from []interface{} ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to use the explicit struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remained from the usage of map[string]interface{} . Will change to an array of DTO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, tricky when testing because gin somehow transforms []core.QueryP2PPeerInfo into map[string]map[string]interface{} automatically when it interprets the response ⚔️
@@ -180,6 +182,7 @@ func (psm *PeerShardMapper) getPeerInfoSearchingPidInFallbackCache(pid core.Peer | |||
return &core.P2PPeerInfo{ | |||
PeerType: core.UnknownPeer, | |||
ShardID: 0, | |||
PkBytes: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for nil initialization. delete from every space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, removed 👍
node/node.go
Outdated
@@ -60,6 +62,15 @@ var _ facade.NodeHandler = (*Node)(nil) | |||
// over the None struct. | |||
type Option func(*Node) error | |||
|
|||
// QueryP2PPeerInfo represents a DTO used in exporting p2p peer info after a query | |||
type QueryP2PPeerInfo struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move to a DTO package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, moved in core
IsInterfaceNil() bool | ||
} | ||
|
||
// TODO remove this struct, use shared.GenericAPIResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add a task in JIRA to make the updates after Bogdan's PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, EN-6756
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? it's just a merge which I have to do anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not quite, you will merge it into development, this will be merged in release-candidate which will go into master and then (through a merge that will be done automatically as there won't be conflicts) into dev. If this merge will be done after you merged into dev the generic api response, will miss working on TODOs. Task can be safely closed afterwords if you make the changes but we won't forget to do it.
api/node/routes.go
Outdated
} | ||
|
||
queryVals := c.Request.URL.Query() | ||
pids := queryVals["pid"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess they will be replaced anyway when @bogdan-rosianu's PR will enter development.
|
||
facade := &mock.WrongFacade{} | ||
ws := startNodeServerWithFacade(facade) | ||
req, _ := http.NewRequest("GET", "/node/peerinfo?pid=asasdasd", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use a prettier dummy string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
sort.Slice(pidsFound, func(i, j int) bool { | ||
return pidsFound[i].Pretty() < pidsFound[j].Pretty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally a nice feature of go, this built-in string comparison operator :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
node/node.go
Outdated
IsBlacklisted: n.peerBlackListHandler.Has(p), | ||
} | ||
|
||
pInfo := n.networkShardingCollector.GetPeerInfo(p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps rename to peerInfo
? This name triggers awful memories of lpSomethingSomething
from Win32 API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pInfo -> peerInfo
api/node/routes.go
Outdated
@@ -20,9 +20,17 @@ type FacadeHandler interface { | |||
TpsBenchmark() *statistics.TpsBenchmark | |||
StatusMetrics() external.StatusMetricsHandler | |||
GetQueryHandler(name string) (debug.QueryHandler, error) | |||
GetPeerInfo(pid string) ([]interface{}, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to use the explicit struct.
@@ -60,6 +68,7 @@ func Routes(router *wrapper.RouterWrapper) { | |||
router.RegisterHandler(http.MethodGet, "/status", StatusMetrics) | |||
router.RegisterHandler(http.MethodGet, "/p2pstatus", P2pStatusMetrics) | |||
router.RegisterHandler(http.MethodPost, "/debug", QueryDebug) | |||
router.RegisterHandler(http.MethodGet, "/peerinfo", PeerInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always on? Or just for debugging purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always on, it will be a neat feature of the node
node/node.go
Outdated
Pid string `json:"pid"` | ||
Addresses []string `json:"addresses"` | ||
Pk string `json:"pk"` | ||
IsBlacklisted bool `json:"isblacklisted"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the bool field to the top or the bottom (memory allign reasons)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…simplified peer shard mapper
Usage:
http://127.0.0.1:8080/node/peerinfo?pid=[part of the pid]