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

Add peer info route #1918

Merged
merged 4 commits into from
Jun 11, 2020
Merged

Conversation

iulianpascalau
Copy link
Contributor

  • added peer info route that will output information for a provided peer (or part of a peer) like: known addresses, its hex public key, if is black listed or not.
    Usage: http://127.0.0.1:8080/node/peerinfo?pid=[part of the pid]

@iulianpascalau iulianpascalau added the type:feature New feature or request label Jun 10, 2020
@iulianpascalau iulianpascalau self-assigned this Jun 10, 2020
@sasurobert sasurobert self-requested a review June 10, 2020 18:37
@andreibancioiu andreibancioiu self-requested a review June 10, 2020 20:38
}

queryVals := c.Request.URL.Query()
pids := queryVals["pid"]
Copy link
Contributor

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"

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@@ -20,9 +20,17 @@ type FacadeHandler interface {
TpsBenchmark() *statistics.TpsBenchmark
StatusMetrics() external.StatusMetricsHandler
GetQueryHandler(name string) (debug.QueryHandler, error)
GetPeerInfo(pid string) ([]interface{}, error)
Copy link
Contributor

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{} ?

Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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,
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, EN-6756

Copy link
Contributor

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

Copy link
Contributor Author

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.

}

queryVals := c.Request.URL.Query()
pids := queryVals["pid"]
Copy link
Collaborator

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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()
Copy link
Collaborator

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 :)

Copy link
Contributor Author

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pInfo -> peerInfo

@@ -20,9 +20,17 @@ type FacadeHandler interface {
TpsBenchmark() *statistics.TpsBenchmark
StatusMetrics() external.StatusMetricsHandler
GetQueryHandler(name string) (debug.QueryHandler, error)
GetPeerInfo(pid string) ([]interface{}, error)
Copy link
Collaborator

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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"`
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@LucianMincu LucianMincu merged commit aedd680 into release-candidate Jun 11, 2020
@LucianMincu LucianMincu deleted the EN-6752-add-peer-info-route branch June 11, 2020 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants