-
Notifications
You must be signed in to change notification settings - Fork 1
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
[COR-68] Add registry of loaded RPC clients and expose discovery metadata #8
Open
midhilkari
wants to merge
3
commits into
master
Choose a base branch
from
feature/v5.0.0-beta
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+993
−526
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- '6' | ||
- lts/* | ||
- "10" | ||
- lts/* | ||
deploy: | ||
provider: npm | ||
email: [email protected] | ||
|
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 |
---|---|---|
|
@@ -12,17 +12,17 @@ const IPC_MANIFESTS_FOLDER = "ipc_manifests"; | |
const requestDuration = new Histogram({ | ||
name: "http_rpc_client_request_duration_seconds", | ||
help: "Duration of rpc requests from the client", | ||
labelNames: ["service", "method"] | ||
labelNames: ["service", "method"], | ||
}); | ||
const requestCount = new Counter({ | ||
name: "http_rpc_client_requests_total", | ||
help: "The total number of rpc requests from the client", | ||
labelNames: ["service", "method"] | ||
labelNames: ["service", "method"], | ||
}); | ||
const failureCount = new Counter({ | ||
name: "http_rpc_client_failures_total", | ||
help: "The total number of rpc failures from the client", | ||
labelNames: ["service", "method", "type", "status_code"] | ||
labelNames: ["service", "method", "type", "status_code"], | ||
}); | ||
|
||
class RpcResponseError { | ||
|
@@ -31,7 +31,7 @@ class RpcResponseError { | |
configurable: true, | ||
enumerable: false, | ||
value: this.constructor.name, | ||
writable: true | ||
writable: true, | ||
}); | ||
|
||
Object.assign(this, responseBody); | ||
|
@@ -46,9 +46,9 @@ class RpcResponseError { | |
"\n" + | ||
[...this.source] | ||
.reverse() | ||
.map(s => " via " + s) | ||
.map((s) => " via " + s) | ||
.join("\n"), | ||
writable: true | ||
writable: true, | ||
}); | ||
} | ||
|
||
|
@@ -61,12 +61,36 @@ class RpcResponseError { | |
} | ||
} | ||
|
||
exports.load = function(host, serviceName, options) { | ||
const metaPath = getMetaPath(serviceName); | ||
const client = new Client(host, options); | ||
class Registry { | ||
constructor() { | ||
this._registeredServices = {}; | ||
} | ||
|
||
load(host, serviceName, options) { | ||
const metaPath = getMetaPath(serviceName); | ||
const client = new Client(host, options); | ||
|
||
const loadClient = client.load(metaPath); | ||
this._registeredServices[serviceName] = loadClient; | ||
|
||
return loadClient; | ||
} | ||
|
||
createWellKnownHandler() { | ||
return (req, res) => { | ||
const services = Object.keys(this._registeredServices).map((s) => { | ||
return { name: s }; | ||
}); | ||
|
||
res.json({ | ||
services, | ||
}); | ||
}; | ||
} | ||
} | ||
|
||
return client.load(metaPath); | ||
}; | ||
exports.registry = new Registry(); | ||
exports.Registry = Registry; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other PR, this should export |
||
|
||
// exports.createClient = function (host, options) { | ||
// return new Client(host, options); | ||
|
@@ -100,7 +124,7 @@ class Client { | |
Object.assign( | ||
this, | ||
{ | ||
path: "/rpc" | ||
path: "/rpc", | ||
}, | ||
options | ||
); | ||
|
@@ -128,21 +152,21 @@ class Client { | |
.post(requestUrl, { | ||
body: JSON.stringify(params), | ||
headers: { | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
}, | ||
json: true, | ||
retries: 0, | ||
timeout | ||
timeout, | ||
}) | ||
.then(res => res.body) | ||
.catch(err => { | ||
.then((res) => res.body) | ||
.catch((err) => { | ||
failureCount.inc( | ||
Object.assign( | ||
{ | ||
type: | ||
(err.response && err.response.body && err.response.body.type) || | ||
undefined, | ||
status_code: err.statusCode | ||
status_code: err.statusCode, | ||
}, | ||
requestMeta | ||
) | ||
|
@@ -160,16 +184,16 @@ class Client { | |
protocol: this.protocol, | ||
host: this.host, | ||
port: this.port, | ||
pathname: pathname | ||
pathname: pathname, | ||
}); | ||
} | ||
|
||
getMeta() { | ||
const requestUrl = this.formatUrl(); | ||
|
||
return got(requestUrl, { json: true }) | ||
.then(res => res.body) | ||
.catch(err => mapError(this.serviceName, "getMeta", err)); | ||
.then((res) => res.body) | ||
.catch((err) => mapError(this.serviceName, "getMeta", err)); | ||
} | ||
|
||
createInterface(meta) { | ||
|
@@ -179,8 +203,8 @@ class Client { | |
const multiArg = meta.multiArg || false; | ||
const self = this; | ||
|
||
meta.interfaces.forEach(iface => { | ||
rpcInterface[iface.methodName] = function() { | ||
meta.interfaces.forEach((iface) => { | ||
rpcInterface[iface.methodName] = function () { | ||
const args = Array.prototype.slice.call(arguments); | ||
const params = multiArg ? args : args[0]; | ||
if (!multiArg && params && typeof params !== "object") | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
createWellKnownErrorHandler