Skip to content

Commit

Permalink
Update node_api_check.py & Documentation (#4835)
Browse files Browse the repository at this point in the history
* update API endpoints and node API check CLI

* cleanup of commented code

* update node_api_check guide
  • Loading branch information
serinko authored Sep 3, 2024
1 parent 4be5af0 commit 3300942
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
15 changes: 10 additions & 5 deletions documentation/operators/src/testing/node-api-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,20 @@ The most common usage may be `./node_api_check.py query_stats <ID_KEY>` where `<

**Optional arguments**

| Flag | Shortcut | Description |
| :--- | :--- | :--- |
| `--markdown` | `-m` | returns output in markdown format |
| `--no_routing_history` | `-n` | returns output without routing history which can be lengthy |
| `--output` | `-o` | exports output to a file, possible to add a target path |
| Flag | Shortcut | Description |
| :--- | :--- | :--- |
| `--markdown` | `-m` | returns output in markdown format |
| `--no_routing_history` | None | returns output without routing history which can be lengthy |
| `--no_verloc_metrics` | None | returns output without verloc measurement which can be lengthy |
| `--output` | `-o` | exports output to a file, possible to add a target path |

#### `version_count`

Another command is `version_count` where at least one `nym-node` version is required. In case of multiple version count, separate the versions with space. We recommend to run this command with `--markdown` flag for a nicer output. This is an example where we want to look up how many registered nodes are on versions `1.1.0`, `1.1.1`, `1.1.2` and `1.1.3`:
```sh
./node_api_check version_count 1.1.0 1.1.1 1.1.2 1.1.3 --markdown
```

```admonish tip
To see a quick overview of `nym-node` version distribution in numbers and graph, visit [Nym Harbourmaster](https://harbourmaster.nymtech.net).
```
2 changes: 1 addition & 1 deletion scripts/api_endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"/status/mixnode/{mix_id}/core-status-count",
"/status/mixnode/{mix_id}/status",
"/status/mixnode/{mix_id}/reward-estimation",
"/status/mixnode/{mix_id}/compute-reward-estimation",
"/status/mixnode/{mix_id}/stake-saturation",
"/status/mixnode/{mix_id}/inclusion-probability",
"/status/mixnode/{mix_id}/avg_uptime"
Expand All @@ -23,6 +22,7 @@

"swagger":[
"/roles",
"/auxiliary-details",
"/build-information",
"/description",
"/host-information",
Expand Down
19 changes: 16 additions & 3 deletions scripts/node_api_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,29 @@ def display_results(self, args):
print(f"Identity Key = {id_key}")
print(f"Host = {host}")
print(f"Version = {version}")
toc = "Swagger page is not accessible. T&Cs are unrecognized and treated as False!"
if swagger_data:
toc = swagger_data["/auxiliary-details"]["accepted_operator_terms_and_conditions"]
print(f"T&Cs = {toc}")

if mix_id:
print(f"Mix ID = {mix_id}")
print("\n\nNODE RESULTS FROM UNFILTERED QUERY\n")

if args.markdown:
node_markdown = self._dataframe_to_markdown(node_df, ["RESULT"], ["API EDNPOINT"])
print(node_markdown, "\n")
else:
self.print_neat_dict(node_dict)
print(f"\n\nNODE RESULTS FROM {self.api_url.upper()}\n")

if args.markdown:
api_df = self._json_to_dataframe(api_data)
node_markdown = self._dataframe_to_markdown(api_df, ["RESULT"], ["API EDNPOINT"])
print(node_markdown, "\n")
else:
self.print_neat_dict(api_data)

if swagger_data:
print(f"\n\nNODE RESULTS FROM SWAGGER PAGE\n")
if args.markdown:
Expand All @@ -61,6 +69,7 @@ def display_results(self, args):
print(swagger_data)
else:
swagger_data = f"\nSwagger API endpoints of node {id_key} hosted on IP: {host} are not responding. Maybe you querying a deprecated version of nym-mixnode or the VPS ports are not open correctly.\n"

if routing_history:
print(f"\n\nNODE UPTIME HISTORY\n")
if args.markdown:
Expand All @@ -71,13 +80,14 @@ def display_results(self, args):
routing_history = self._json_neat_format(routing_history)
else:
routing_history = " "

if args.output or args.output == "":
node_dict = self._json_neat_format(node_dict)
api_data = self._json_neat_format(api_data)
if role:
data_list = [f"Id. Key = {id_key}", f"Host = {host}", f"Type = {mode}", f"Mode = {role}", node_dict, api_data, swagger_data, routing_history]
data_list = [f"Id. Key = {id_key}", f"Host = {host}", f"Type = {mode}", f"Mode = {role}", f"T&Cs = {toc}", node_dict, api_data, swagger_data, routing_history]
else:
data_list = [f"Id. Key = {id_key}", f"Host = {host}", f"Type = {mode}", node_dict, api_data, swagger_data, routing_history]
data_list = [f"Id. Key = {id_key}", f"Host = {host}", f"Type = {mode}", f"T&Cs = {toc}", node_dict, api_data, swagger_data, routing_history]
self.output.concat_to_file(args, data_list)

def collect_all_results(self,args):
Expand Down Expand Up @@ -118,6 +128,8 @@ def get_node_data(self,mode, node_dict, id_key, args):
dicts = json.load(f)
endpoints = dicts[mode]
swagger = dicts["swagger"]
if args.no_verloc_metrics:
swagger.remove("/metrics/verloc")
api_data = {}
swagger_data = {}
routing_history = {}
Expand Down Expand Up @@ -364,7 +376,8 @@ def parser_main(self):

# pull_stats arguments
parser_pull_stats.add_argument("id", help="supply nym-node identity key")
parser_pull_stats.add_argument("-n","--no_routing_history", help="Display node stats without routing history", action="store_true")
parser_pull_stats.add_argument("--no_routing_history", help="Display node stats without routing history", action="store_true")
parser_pull_stats.add_argument("--no_verloc_metrics", help="Display node stats without verloc metrics", action="store_true")
parser_pull_stats.add_argument("-m","--markdown",help="Display results in markdown format", action="store_true")
parser_pull_stats.add_argument("-o","--output",help="Save results to file (in current dir or supply with path without filename)", nargs='?',const="", type=str)
parser_pull_stats.set_defaults(func=self.functions.display_results)
Expand Down

0 comments on commit 3300942

Please sign in to comment.