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

[explorer/nodewatch] task: add new route #343

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open

Conversation

AnthonyLaw
Copy link
Member

What was the issue?

  • to replace the statistics service, node watch is missing some endpoints, used in wallet and explorer.

What's the fix?

  • add a few properties in the nodedescriptor: isHealthy, isHttpsEnable, isWssEnable, restVersion
  • added a new endpoint
/api/symbol/nodes (query params ssl, limit, order)
/api/symbol/nodes/mainPublicKey/<main_public_key>
/api/symbol/nodes/nodePublicKey/<node_public_key>

@AnthonyLaw AnthonyLaw force-pushed the task/new-route branch 4 times, most recently from 14473d1 to d655a86 Compare March 28, 2023 08:51
@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #343 (1310d05) into dev (e08fb73) will decrease coverage by 0.02%.
The diff coverage is 98.80%.

❗ Current head 1310d05 differs from pull request most recent head 3f743cd. Consider uploading reports for the commit 3f743cd to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #343      +/-   ##
==========================================
- Coverage   98.91%   98.89%   -0.02%     
==========================================
  Files          54       54              
  Lines        1850     1909      +59     
  Branches       72       72              
==========================================
+ Hits         1830     1888      +58     
- Misses         20       21       +1     
Flag Coverage Δ
explorer-nodewatch 98.38% <98.80%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
explorer/nodewatch/nodewatch/__init__.py 96.03% <96.55%> (+0.03%) ⬆️
explorer/nodewatch/nodewatch/NetworkRepository.py 100.00% <100.00%> (ø)
explorer/nodewatch/nodewatch/RoutesFacade.py 96.74% <100.00%> (+0.66%) ⬆️

@AnthonyLaw AnthonyLaw force-pushed the task/new-route branch 2 times, most recently from 3f743cd to 1310d05 Compare March 30, 2023 01:31
Comment on lines 27 to 28
is_https_enable=None,
is_wss_enable=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

enable => enabled (x2)

Copy link
Contributor

Choose a reason for hiding this comment

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

do we actually need BOTH of these?

Copy link
Member Author

@AnthonyLaw AnthonyLaw Mar 31, 2023

Choose a reason for hiding this comment

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

For the explorer, we will need the is_https_enable, for the wallet it needs is_wss_enable.

Can we consider if https enable, we can assume wss is enable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we consider if https enable, we can assume wss is enable?

yes, i would.
cc: @gimre-xymcity

explorer/nodewatch/nodewatch/RoutesFacade.py Outdated Show resolved Hide resolved
explorer/nodewatch/nodewatch/RoutesFacade.py Outdated Show resolved Hide resolved
explorer/nodewatch/tests/test_RoutesFacade.py Outdated Show resolved Hide resolved
explorer/nodewatch/tests/test_RoutesFacade.py Show resolved Hide resolved
] == list(map(lambda descriptor: descriptor['name'], response_json))


def test_get_api_symbol_nodes(client): # pylint: disable=redefined-outer-name
# Act:
response = client.get('/api/symbol/nodes')
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need a new /nodes route in addition to nodes/peer and nodes/api?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about this as well, but not sure it's a good idea, here is my thought.

purpose

  • the endpoint mainly returns all nodes and displays them on explorer.
  • this endpoint added SSL, limit, and order filters, which will use to init explorer, and wallet to pull all healthy nodes.

calling 1 request instead of 2 to get all node lists.

But I didn't think that is the problem called 2 requests to get the node list, I can apply query params in the 2 endpoints as well.

what will you recommand?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can apply query params in the 2 endpoints as well

I think I would prefer this approach, but also ask @gimre-xymcity his opinion.

explorer/nodewatch/tests/test_app.py Outdated Show resolved Hide resolved
explorer/nodewatch/tests/test_app.py Outdated Show resolved Hide resolved
explorer/nodewatch/tests/test_app.py Outdated Show resolved Hide resolved
@AnthonyLaw AnthonyLaw requested a review from Jaguar0625 April 1, 2023 07:19
explorer/nodewatch/nodewatch/__init__.py Outdated Show resolved Hide resolved
explorer/nodewatch/nodewatch/__init__.py Outdated Show resolved Hide resolved
explorer/nodewatch/nodewatch/__init__.py Outdated Show resolved Hide resolved
explorer/nodewatch/nodewatch/__init__.py Outdated Show resolved Hide resolved
explorer/nodewatch/nodewatch/__init__.py Outdated Show resolved Hide resolved
[2, 3],
list(map(lambda descriptor: descriptor['roles'], node_descriptors)))

def test_can_generate_nodes_json_filtered_order_random_limit_2(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

also would rename to random_subset

@@ -361,15 +371,15 @@ def test_can_generate_nodes_json(self):
facade.reload_all(Path('tests/resources'), True)

# Act:
node_descriptors = facade.json_nodes(1)
node_descriptors = facade.json_nodes(role=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

based on naming of test, this test should probably have no filter

list(map(lambda descriptor: descriptor['name'], node_descriptors)))
self.assertEqual(
[7, 3, 3, 5, 3],
[7, 3, 3, 5, 3, 3, 3],
list(map(lambda descriptor: descriptor['roles'], node_descriptors)))

def test_can_generate_nodes_json_filtered(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

would add _by_role to this test and next

self.assertEqual(2, len(node_descriptors))
for name in random_node_names:
self.assertIn(name, full_node_names)

Copy link
Contributor

Choose a reason for hiding this comment

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

would add test with limit but without random

for name in random_node_names:
self.assertIn(name, full_node_names)

def test_can_generate_node_json_given_main_public_key(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

consider test names:

can_find_known_node_by_main_public_key
can_find_known_node_by_node_public_key

cannot_find_unknown_node_by_main_public_key
cannot_find_unknown_node_by_node_public_key

Copy link
Member Author

Choose a reason for hiding this comment

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

Those names actually cause pylint error (name too long), but I'm ok with that name. so I used # pylint: disable=invalid-name

@AnthonyLaw AnthonyLaw requested a review from Jaguar0625 April 13, 2023 20:13

def custom_filter(descriptor):
role_condition = True

if role is not None:
role_condition = role == descriptor.roles if exact_match else role == (role & descriptor.roles)

if ssl is not None:
if only_ssl is True:
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need "is True" ?

nodes = nodes[:limit]

return nodes
return nodes if limit == 0 else nodes[:limit]
Copy link
Contributor

Choose a reason for hiding this comment

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

if not limit. ?

Copy link
Member Author

Choose a reason for hiding this comment

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

full_api_node_names = [
'Allnodes250', 'Allnodes251'
]
actual_names = list(map(lambda descriptor: descriptor['name'], response_json))

# Assert:
_assert_symbol_node_response(response, actual_names)
Copy link
Contributor

Choose a reason for hiding this comment

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

assert len(actual_names) == 1

@@ -232,9 +233,9 @@ def test_get_api_symbol_nodes_peer_order_random_limit_2(client): # pylint: disa
assert name in full_node_names
Copy link
Contributor

Choose a reason for hiding this comment

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

assert length of actual names is 2

@@ -226,7 +226,7 @@ def test_can_reload_all(self):
self.assertEqual(True, result)
self.assertEqual(facade.last_reload_time, facade.last_refresh_time)

self.assertEqual(6, len(facade.repository.node_descriptors))
self.assertEqual(9, len(facade.repository.node_descriptors))
Copy link
Contributor

Choose a reason for hiding this comment

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

consider adding a comment

[2, 2, 7, 3, 3],
list(map(lambda descriptor: descriptor['roles'], node_descriptors)))

def can_find_known_node_by_main_public_key(self): # pylint: disable=invalid-name
Copy link
Contributor

Choose a reason for hiding this comment

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

test need to start with test_ prefix or they will not be detected as tests (x4)

nodes = nodes[:limit]

return nodes
return nodes if limit == 0 else nodes[:limit]

def json_node(self, filter_field, public_key):
Copy link
Contributor

Choose a reason for hiding this comment

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

you might want to consider checking if public_key is proper public key and returning 400 if not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants