Skip to content
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

Merged
merged 2 commits into from
Feb 28, 2018
Merged

[prometheus] exporter prototype #629

merged 2 commits into from
Feb 28, 2018

Conversation

mikz
Copy link
Contributor

@mikz mikz commented Feb 27, 2018

  • introduce metrics phase to export metrics
  • executor prints collects the response from prometheus
  • metrics can be also published from any other phase or timer

Example

See for policy changes and metrics examples:
3scale/apicast-cloud-hosted#5

@mikz mikz requested review from maneta and davidor February 27, 2018 17:21
@mikz mikz force-pushed the prometheus-exporter branch from cfa4364 to 2aa9754 Compare February 27, 2018 20:34
@@ -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 },
Copy link

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?

Copy link
Contributor Author

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?

Copy link

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reserved 9421.

Copy link
Contributor

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 ;)

Copy link

@maneta maneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mikz mikz force-pushed the prometheus-exporter branch 5 times, most recently from 70e7c6e to 6749c54 Compare February 28, 2018 08:12
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

@mikz mikz force-pushed the prometheus-exporter branch from 6749c54 to 780f029 Compare February 28, 2018 09:36
@@ -106,6 +106,24 @@ http {
{% include "conf.d/apicast.conf" %}
}

{% if port.metrics %}
lua_shared_dict prometheus_metrics 16M;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be configurable?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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(...)
Copy link
Contributor

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.

Copy link
Contributor Author

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')
Copy link
Contributor

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?

Copy link
Contributor Author

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.

prometheus = assert(require('apicast.prometheus'))
end)

it('can be called', function()
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@mikz mikz force-pushed the prometheus-exporter branch from c44b062 to 619bc40 Compare February 28, 2018 13:57
@mikz mikz merged commit c9df38c into master Feb 28, 2018
@mikz mikz deleted the prometheus-exporter branch February 28, 2018 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants