-
Notifications
You must be signed in to change notification settings - Fork 170
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
[prometheus] exporter prototype #629
Conversation
cfa4364
to
2aa9754
Compare
gateway/config/development.lua
Outdated
@@ -28,5 +28,6 @@ return { | |||
lua_code_cache = 'on', | |||
configuration_loader = 'lazy', | |||
configuration_cache = 0, | |||
configuration = data_url('application/json', configuration) | |||
configuration = data_url('application/json', configuration), | |||
port = { metrics = 9100 }, |
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.
@mikz maybe reserve a port for the APIcast endpoint so we can publish it on the Prometheus Default Port Allocation list?
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 we should agree how we want to proceed first.
We are not going to reserve a port for every app we have, right? We need some generic port for openresty exporter?
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.
Got It, I thought that at least for APICast we were willing to create a specific "exporter" but yes makes more sense to create a generic port for openresty exporter.
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.
To me it doesn't really make sense to reserve a port for each APP, but this is not a /generic/ openresty prometheus exporter, so, should we define a port for the "APIcast framework" and reuse that one in all our applications?
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.
That makes sense if we want to converge all our proxies running on the "APIcast framework".
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.
Reserved 9421.
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.
We should converge them all, now with policies it should be easier ;)
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.
👍
70e7c6e
to
6749c54
Compare
CHANGELOG.md
Outdated
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |||
- Error loading policy chain configuration JSON with null value [PR #626](https://github.com/3scale/apicast/pull/626) | |||
- Splitted `resolv.conf` in lines,to avoid commented lines [PR #618](https://github.com/3scale/apicast/pull/618) | |||
|
|||
## Addwed |
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.
Typo
6749c54
to
780f029
Compare
@@ -106,6 +106,24 @@ http { | |||
{% include "conf.d/apicast.conf" %} | |||
} | |||
|
|||
{% if port.metrics %} | |||
lua_shared_dict prometheus_metrics 16M; |
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.
Should this be configurable?
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.
Probably, but I'd wait with some real operations use to see if it is really needed.
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.
Hah. This just gave me an idea for another exporter: shmem dict stats about free space.
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.
content_by_lua_block { require('apicast.executor'):metrics() } | ||
} | ||
|
||
location /nginx_status { |
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.
Why is this needed?
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.
It is used in https://github.com/3scale/apicast-cloud-hosted/pull/5/files#diff-047b1780b0ffeb4eba7b3d05beb76d5eR77 to extract the connection stats.
There is no easy way to add that location from customization, so I added it here as this will become part of upstream at some point.
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.
👍
@@ -28,5 +28,6 @@ return { | |||
lua_code_cache = 'on', | |||
configuration_loader = 'lazy', | |||
configuration_cache = 0, | |||
configuration = data_url('application/json', configuration) | |||
configuration = data_url('application/json', configuration), | |||
port = { metrics = 9421 }, -- see https://github.com/prometheus/prometheus/wiki/Default-port-allocations |
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.
👍
@@ -13,7 +13,7 @@ local PHASES = { | |||
'rewrite', 'access', | |||
'content', 'balancer', | |||
'header_filter', 'body_filter', | |||
'post_action', 'log' | |||
'post_action', 'log', 'metrics', |
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.
We should add new phases to the policies doc: https://github.com/3scale/apicast/blob/master/doc/policies.md#policies
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.
Done in c44b062
@@ -58,4 +59,11 @@ function _M:context(phase) | |||
return shared_build_context(self) | |||
end | |||
|
|||
local metrics = _M.metrics | |||
--- Render metrics from all policies. | |||
function _M:metrics(...) |
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.
Maybe we should add a test for this. Define 2 policies with only a metrics phase that incr some counter and make sure that this returns the sum, or something similar.
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.
Yeah but this does not really "return" anything. It renders the output.
I'll definitely do that when moving some policies with metrics to upstream from 3scale/apicast-cloud-hosted#5.
|
||
local metrics = { } | ||
local __call = function(_, type, name, ...) | ||
local metric_name = assert(name, 'missing metric name') |
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.
Why do we check name
and type
? Can't we delegate this to the Prometheus lib?
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.
Because we actually use it. The type gets a function that is later called and the name is used as a key to store the metric. I had few tricky errors so decided to go for explicit ones.
spec/prometheus_spec.lua
Outdated
prometheus = assert(require('apicast.prometheus')) | ||
end) | ||
|
||
it('can be called', function() |
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.
Should we change this to test that it delegates counter
, gauge
, etc. to the Prometheus lib?
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.
Yep, makes sense.
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.
Done.
c44b062
to
619bc40
Compare
Example
See for policy changes and metrics examples:
3scale/apicast-cloud-hosted#5