Skip to content

Commit

Permalink
feat(admin-api): add call dumpNetworkStats (#184)
Browse files Browse the repository at this point in the history
* remove unneded error throw

* update network info type

* add networkstats call

* udpate changelog

* fix test
  • Loading branch information
jost-s committed Apr 15, 2023
1 parent e352b95 commit bb7c654
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- New Admin API endpoint `storageInfo`.
- New Admin API endpoint 'updateCoordinators' to update coordinator zomes in an already installed hApp.
- New Admin API endpoint `dumpNetworkStats`.
- New Admin API endpoint `updateCoordinators` to update coordinator zomes in an already installed hApp.
### Changed
- Updated response type `NetworkInfo`.
### Fixed
### Removed

Expand Down
2 changes: 1 addition & 1 deletion docs/client.dnaproperties.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<b>Signature:</b>

```typescript
export declare type DnaProperties = any;
export declare type DnaProperties = unknown;
```
11 changes: 11 additions & 0 deletions docs/client.networkinfo.arc_size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [NetworkInfo](./client.networkinfo.md) &gt; [arc\_size](./client.networkinfo.arc_size.md)

## NetworkInfo.arc\_size property

<b>Signature:</b>

```typescript
arc_size: number;
```
11 changes: 11 additions & 0 deletions docs/client.networkinfo.bytes_since_last_time_queried.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [NetworkInfo](./client.networkinfo.md) &gt; [bytes\_since\_last\_time\_queried](./client.networkinfo.bytes_since_last_time_queried.md)

## NetworkInfo.bytes\_since\_last\_time\_queried property

<b>Signature:</b>

```typescript
bytes_since_last_time_queried: number;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [NetworkInfo](./client.networkinfo.md) &gt; [completed\_rounds\_since\_last\_time\_queried](./client.networkinfo.completed_rounds_since_last_time_queried.md)

## NetworkInfo.completed\_rounds\_since\_last\_time\_queried property

<b>Signature:</b>

```typescript
completed_rounds_since_last_time_queried: number;
```
11 changes: 11 additions & 0 deletions docs/client.networkinfo.current_number_of_peers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [NetworkInfo](./client.networkinfo.md) &gt; [current\_number\_of\_peers](./client.networkinfo.current_number_of_peers.md)

## NetworkInfo.current\_number\_of\_peers property

<b>Signature:</b>

```typescript
current_number_of_peers: number;
```
5 changes: 5 additions & 0 deletions docs/client.networkinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ export interface NetworkInfo

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [arc\_size](./client.networkinfo.arc_size.md) | | number | |
| [bytes\_since\_last\_time\_queried](./client.networkinfo.bytes_since_last_time_queried.md) | | number | |
| [completed\_rounds\_since\_last\_time\_queried](./client.networkinfo.completed_rounds_since_last_time_queried.md) | | number | |
| [current\_number\_of\_peers](./client.networkinfo.current_number_of_peers.md) | | number | |
| [fetch\_pool\_info](./client.networkinfo.fetch_pool_info.md) | | [FetchPoolInfo](./client.fetchpoolinfo.md) | |
| [total\_network\_peers](./client.networkinfo.total_network_peers.md) | | number | |

11 changes: 11 additions & 0 deletions docs/client.networkinfo.total_network_peers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [NetworkInfo](./client.networkinfo.md) &gt; [total\_network\_peers](./client.networkinfo.total_network_peers.md)

## NetworkInfo.total\_network\_peers property

<b>Signature:</b>

```typescript
total_network_peers: number;
```
14 changes: 14 additions & 0 deletions src/api/admin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,16 @@ export type StorageInfoRequest = void;
*/
export type StorageInfoResponse = StorageInfo;

/**
* @public
*/
export type DumpNetworkStatsRequest = void;

/**
* @public
*/
export type DumpNetworkStatsResponse = string;

/**
* @public
*/
Expand Down Expand Up @@ -827,4 +837,8 @@ export interface AdminApi {
GrantZomeCallCapabilityResponse
>;
storageInfo: Requester<StorageInfoRequest, StorageInfoResponse>;
dumpNetworkStats: Requester<
DumpNetworkStatsRequest,
DumpNetworkStatsResponse
>;
}
7 changes: 7 additions & 0 deletions src/api/admin/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
DisableAppResponse,
DumpFullStateRequest,
DumpFullStateResponse,
DumpNetworkStatsRequest,
DumpNetworkStatsResponse,
DumpStateRequest,
DumpStateResponse,
EnableAppRequest,
Expand Down Expand Up @@ -260,6 +262,11 @@ export class AdminWebsocket implements AdminApi {
storageInfo: Requester<StorageInfoRequest, StorageInfoResponse> =
this._requester("storage_info");

dumpNetworkStats: Requester<
DumpNetworkStatsRequest,
DumpNetworkStatsResponse
> = this._requester("dump_network_stats");

// zome call signing related methods

/**
Expand Down
8 changes: 1 addition & 7 deletions src/api/app-agent/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,7 @@ export class AppAgentWebsocket implements AppAgentClient {
request: AppAgentCallZomeRequest,
timeout?: number
): Promise<CallZomeResponse> {
if ("provenance" in request) {
if ("role_name" in request && request.role_name) {
throw new Error(
"Cannot find other agent's cells based on role name. Use cell id when providing a provenance."
);
}
} else {
if (!("provenance" in request)) {
request = {
...request,
provenance: this.myPubKey,
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export type CellId = [DnaHash, AgentPubKey];
/**
* @public
*/
export type DnaProperties = any;
export type DnaProperties = unknown;
/**
* @public
*/
Expand Down Expand Up @@ -124,6 +124,11 @@ export interface HoloHashed<T> {
*/
export interface NetworkInfo {
fetch_pool_info: FetchPoolInfo;
current_number_of_peers: number;
arc_size: number;
total_network_peers: number;
bytes_since_last_time_queried: number;
completed_rounds_since_last_time_queried: number;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ test(
new Date("2022-02-11T23:05:19.470323Z").getTime(),
"dna definition: origin time matches"
);
assert(Buffer.isBuffer(dnaDefinition.modifiers.properties));
t.equal(
decode(dnaDefinition.modifiers.properties),
null,
Expand Down Expand Up @@ -964,6 +965,18 @@ test(
})
);

test(
"can fetch network stats",
withConductor(ADMIN_PORT, async (t: Test) => {
const { admin } = await installAppAndDna(ADMIN_PORT);

const response = await admin.dumpNetworkStats();

t.ok(typeof response === "string", "response is string");
t.ok(JSON.parse(response), "response is valid JSON");
})
);

test(
"can update coordinators of an app",
withConductor(ADMIN_PORT, async (t: Test) => {
Expand Down

0 comments on commit bb7c654

Please sign in to comment.