forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd-api-server): support grpc web services hyperledger-cacti#1189
WORK IN PROGRESS! Fixes hyperledger-cacti#1189 Signed-off-by: Peter Somogyvari <[email protected]>
- Loading branch information
Showing
9 changed files
with
1,376 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/cactus-cmd-api-server/src/main/proto/healthcheck.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
|
||
package org.hyperledger.cactus.cmd_api_server; | ||
|
||
service Healthcheck { | ||
// Obtains the memory usage statistics of the API server's NodeJS process. | ||
rpc GetHealtcheck(HealthcheckRequest) returns (stream HealthcheckResponse) {} | ||
} | ||
|
||
message MemoryUsage { | ||
int64 rss = 1; | ||
int64 heapTotal = 2; | ||
int64 heapUsed = 3; | ||
int64 external = 4; | ||
int64 arrayBuffers = 5; | ||
} | ||
|
||
message HealthcheckRequest { | ||
} | ||
|
||
message HealthcheckResponse { | ||
bool success = 1; | ||
string createdAt = 2; | ||
MemoryUsage memoryUsage = 3; | ||
} |
864 changes: 864 additions & 0 deletions
864
packages/cactus-cmd-api-server/src/main/typescript/generated/proto/pbjs.js
Large diffs are not rendered by default.
Oops, something went wrong.
361 changes: 361 additions & 0 deletions
361
packages/cactus-cmd-api-server/src/main/typescript/generated/proto/pbts.d.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...tus-cmd-api-server/src/main/typescript/web-services/grpc/watch-healthcheck-v1-endpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Socket as SocketIoSocket } from "socket.io"; | ||
|
||
import { Logger, Checks } from "@hyperledger/cactus-common"; | ||
import { LogLevelDesc, LoggerProvider } from "@hyperledger/cactus-common"; | ||
|
||
import { org } from "../../generated/proto/pbts"; | ||
import { WatchHealthcheckV1 } from "../../generated/openapi/typescript-axios/api"; | ||
|
||
const { HealthcheckResponse } = org.hyperledger.cactus.cmd_api_server; | ||
|
||
export interface IWatchHealthcheckV1EndpointOptions { | ||
logLevel?: LogLevelDesc; | ||
socket: SocketIoSocket; | ||
process: NodeJS.Process; | ||
} | ||
|
||
export class WatchHealthcheckV1Endpoint { | ||
public static readonly CLASS_NAME = "WatchHealthcheckV1Endpoint"; | ||
|
||
private readonly log: Logger; | ||
private readonly process: NodeJS.Process; | ||
|
||
public get className(): string { | ||
return WatchHealthcheckV1Endpoint.CLASS_NAME; | ||
} | ||
|
||
constructor(public readonly options: IWatchHealthcheckV1EndpointOptions) { | ||
const fnTag = `${this.className}#constructor()`; | ||
Checks.truthy(options, `${fnTag} arg options`); | ||
Checks.truthy(options.process, `${fnTag} arg options.process`); | ||
|
||
this.process = options.process; | ||
|
||
const level = this.options.logLevel || "INFO"; | ||
const label = this.className; | ||
this.log = LoggerProvider.getOrCreate({ level, label }); | ||
} | ||
|
||
public async subscribe(): Promise<void> { | ||
const { log } = this; | ||
log.debug(`${WatchHealthcheckV1.Subscribe} => FIXME - connection ID here`); | ||
|
||
const timerId = setInterval(() => { | ||
try { | ||
const next: org.hyperledger.cactus.cmd_api_server.IHealthcheckResponse = HealthcheckResponse.create( | ||
{ | ||
createdAt: new Date().toJSON(), | ||
memoryUsage: this.process.memoryUsage(), | ||
success: true, | ||
}, | ||
); | ||
|
||
const validationMessage = HealthcheckResponse.verify(next); | ||
if (validationMessage) { | ||
// socket.emit(WatchHealthcheckV1.Error, validationMessage); | ||
} else { | ||
// socket.emit(WatchHealthcheckV1.Next, next); | ||
} | ||
} catch (ex) { | ||
log.error(`Failed to construct health check response:`, ex); | ||
// socket.emit(WatchHealthcheckV1.Error, ex); | ||
clearInterval(timerId); | ||
} | ||
}, 1000); | ||
|
||
// socket.on("disconnect", async (reason: string) => { | ||
// log.debug("WebSocket:disconnect reason=%o", reason); | ||
// clearInterval(timerId); | ||
// }); | ||
|
||
// socket.on(WatchHealthcheckV1.Unsubscribe, () => { | ||
// clearInterval(timerId); | ||
// }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2703,6 +2703,21 @@ | |
npmlog "^4.1.2" | ||
write-file-atomic "^3.0.3" | ||
|
||
"@mapbox/node-pre-gyp@^1.0.5": | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.5.tgz#2a0b32fcb416fb3f2250fd24cb2a81421a4f5950" | ||
integrity sha512-4srsKPXWlIxp5Vbqz5uLfBN+du2fJChBoYn/f2h991WLdk7jUvcSk/McVLSv/X+xQIPI8eGD5GjrnygdyHnhPA== | ||
dependencies: | ||
detect-libc "^1.0.3" | ||
https-proxy-agent "^5.0.0" | ||
make-dir "^3.1.0" | ||
node-fetch "^2.6.1" | ||
nopt "^5.0.0" | ||
npmlog "^4.1.2" | ||
rimraf "^3.0.2" | ||
semver "^7.3.4" | ||
tar "^6.1.0" | ||
|
||
"@multiformats/base-x@^4.0.1": | ||
version "4.0.1" | ||
resolved "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz" | ||
|
@@ -10151,6 +10166,11 @@ google-p12-pem@^3.0.3: | |
dependencies: | ||
node-forge "^0.10.0" | ||
|
||
google-protobuf@^3.15.5: | ||
version "3.17.3" | ||
resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.17.3.tgz#f87595073545a77946c8f0b67c302c5f7646d700" | ||
integrity sha512-OVPzcSWIAJ+d5yiHyeaLrdufQtrvaBrF4JQg+z8ynTkbO3uFcujqXszTumqg1cGsAsjkWnI+M5B1xZ19yR4Wyg== | ||
|
||
[email protected], got@^9.6.0: | ||
version "9.6.0" | ||
resolved "https://registry.npmjs.org/got/-/got-9.6.0.tgz" | ||
|
@@ -10237,6 +10257,13 @@ [email protected]: | |
resolved "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz" | ||
integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== | ||
|
||
[email protected]: | ||
version "1.11.2" | ||
resolved "https://registry.yarnpkg.com/grpc-tools/-/grpc-tools-1.11.2.tgz#22d802d40012510ccc6591d11f9c94109ac07aab" | ||
integrity sha512-4+EgpnnkJraamY++oyBCw5Hp9huRYfgakjNVKbiE3PgO9Tv5ydVlRo7ZyGJ0C0SEiA7HhbVc1sNNtIyK7FiEtg== | ||
dependencies: | ||
"@mapbox/node-pre-gyp" "^1.0.5" | ||
|
||
gtoken@^5.0.4: | ||
version "5.3.0" | ||
resolved "https://registry.yarnpkg.com/gtoken/-/gtoken-5.3.0.tgz#6536eb2880d9829f0b9d78f756795d4d9064b217" | ||
|
@@ -16584,9 +16611,9 @@ proto-list@~1.2.1: | |
resolved "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz" | ||
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= | ||
|
||
protobufjs@^6.10.0, protobufjs@^6.10.2, protobufjs@^6.11.2: | ||
protobufjs@6.11.2, protobufjs@^6.10.0, protobufjs@^6.10.2, protobufjs@^6.11.2: | ||
version "6.11.2" | ||
resolved "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.2.tgz" | ||
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.2.tgz#de39fabd4ed32beaa08e9bb1e30d08544c1edf8b" | ||
integrity sha512-4BQJoPooKJl2G9j3XftkIXjoC9C0Av2NOrWmbLWT1vH32GcSUHjM0Arra6UfTsVyfMAuFzaLucXn1sadxJydAw== | ||
dependencies: | ||
"@protobufjs/aspromise" "^1.1.2" | ||
|
@@ -19624,6 +19651,13 @@ [email protected]: | |
source-map-support "^0.5.6" | ||
yn "^3.0.0" | ||
|
||
[email protected]: | ||
version "0.15.0" | ||
resolved "https://registry.yarnpkg.com/ts-protoc-gen/-/ts-protoc-gen-0.15.0.tgz#2fec5930b46def7dcc9fa73c060d770b7b076b7b" | ||
integrity sha512-TycnzEyrdVDlATJ3bWFTtra3SCiEP0W0vySXReAuEygXCUr1j2uaVyL0DhzjwuUdQoW5oXPwk6oZWeA0955V+g== | ||
dependencies: | ||
google-protobuf "^3.15.5" | ||
|
||
tsconfig-paths@^3.9.0: | ||
version "3.10.1" | ||
resolved "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.10.1.tgz" | ||
|