-
Notifications
You must be signed in to change notification settings - Fork 152
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
feat: add prometheus metrics in dedicated port #1232
Conversation
- Created separate express instance and port for prometheus metrics - Exposing the default prometheus metrics - Created a custom metric of type "counter" that increments in every http error
- Removed the `return` keyword - Added an IIFE inside the callback - Added the `void` operator
- Added a prometheus flag that runs the prometheus server & enables the metrics endpoint - Added a prometheus-port flag so that the user can choose a custom port to run the metrics endpoint - Changed the code in killAll so that there is no `Object is possibly undefined` error
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.
Overall, really good job! Just some nits on global scope, and only have things ran if prometheus is active.
- Added prometheus options and description under help flag - Created metrics app and increased httpErrorCounter only if prometheus flag is true - Moved logger and register inside functions - Added a section for prometheus in the README
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 have a question about the help page/message :
-
If I run
yarn start -h
it shows me the prometheus options that I added so I get the output I expect :usage: main.js [-h] [-v] [-p] [-pp PROMETHEUS_PORT] optional arguments: -h, --help show this help message and exit -v, --version print substrate-api-sidecar version -p, --prometheus enable the prometheus metrics endpoint -pp PROMETHEUS_PORT, --prometheus-port PROMETHEUS_PORT specify the port number on which the prometheus metrics are exposed [default: 9100]
-
If I run
substrate-api-sidecar -h
I only get the help and version options. It probably does not get my local version/folder/branch of sidecar ? thats why ?
You need to run |
} | ||
|
||
listen(): void { | ||
const { logger } = Log; |
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.
This is fine with the Logger since it's only being used in here which makes sense. But that being said as a side note, the logger can be a top level variable since it's only ever instantiated once. The logger file itself has a static this.create
which only gets called the first time the logger is instantiated in the entry file.
Description
Relates to the issue #1008
This PR is a first approach/test on adding prometheus metrics in Sidecar. More specifically this PR :
9100
) where the Prometheus metrics are exposedcounter
that increments in every http errorsas_
that denotes that are "Substrate Api Sidecar" related metrics.Run the Prometheus metrics endpoint
prom-client
installed (you can withyarn add prom-client
)note: if you get an error while adding
prom-client
try to do ayarn dedupe
firstyarn build
yarn start --prometheus
yarn start --prometheus --prometheus-port=<YOUR_CUSTOM_PORT>
http://127.0.0.1:8080
http://127.0.0.1:9100/metrics
orhttp://127.0.0.1:<YOUR_CUSTOM_PORT>/metrics
Testing
http://127.0.0.1:8080/blocks
this will trigger anhttpError
sas_http_errors
(of typecounter
) should be increased by 1 so we should see on the metrics endpoint the following :Additional Notes
Apart
counters
there are other types of metrics that can be added like Histograms, Gauges, etc. More details on metric types can be found in :