-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Metrics with Prometheus #2069
Metrics with Prometheus #2069
Conversation
Generated by 🚫 dangerJS |
I would like to have tests for this. But I do not know is it possible to run service tests with 'use strict'
const ServiceTester = require('../service-tester')
const t = new ServiceTester({ id: 'metrics', title: 'Prometheus metrics', pathPrefix: '' })
module.exports = t
t.create('metric are disabled by default')
.get('/metrics')
.expectStatus(404)
// below test will fail, we have to set config.metrics.prometheus.enabled = true
// const config = require('../../lib/server-config')
// config.metrics.prometheus.enabled = true
t.create('metric can be enabled by feature flag')
.get('/metrics')
.expectStatus(200)
.expectBodyContains('nodejs_version_info') Both tests requires change in diff --git a/services/service-tester.js b/services/service-tester.js
index 91223be..17009af 100644
--- a/services/service-tester.js
+++ b/services/service-tester.js
@@ -62,12 +62,18 @@ class ServiceTester {
})
// eslint-disable-next-line mocha/prefer-arrow-callback
.finally(function() {
+ let content;
+ try {
+ content = JSON.parse(this._response.body)
+ } catch(e) {
+ content = this._response.body;
+ }
// `this` is the IcedFrisby instance.
trace.logTrace(
'outbound',
emojic.shield,
'Response',
- JSON.parse(this._response.body)
+ content
)
})
I've tried with separate test files for both cases, but server is started only once for all tests. |
The approach I'd probably take to testing this is to test it with a lower-level unit test. I just did something similar for the GitHub token acceptor in https://github.com/badges/shields/pull/2021/files#diff-e852a48eb7b4b8dcdf24b0bb30321a60. The module exposes a function We have to trust that the wiring in There's some similar code for the github admin route and its test: https://github.com/badges/shields/blob/master/services/github/auth/admin.js |
I've refactored the code and I've added an access limit. @paulmelnikow thanks for the hints about testing! :-) |
class PrometheusMetrics { | ||
constructor(config = {}) { | ||
this.enabled = config.enabled || false | ||
const matchNothing = /(?!)/ |
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.
👍
Can we merge it? |
Let's merge it! I'll make sure @espadrine is aware of it before we turn it on in production. |
Idea behind this change is described in #2068
This change contains:
/metrics
resource with access limit with default metrics (disabled by default)METRICS_PROMETHEUS_ENABLED
environment variable to enable metricsMETRICS_PROMETHEUS_ALLOWED_IPS
env variable for controlling allowed IP adresses