Skip to content

Commit 33d90ec

Browse files
authoredFeb 5, 2021
docs: set_export documentation (#180)
1 parent 6c9b9b8 commit 33d90ec

File tree

3 files changed

+105
-70
lines changed

3 files changed

+105
-70
lines changed
 

‎README.md

+40-25
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,46 @@ via configuration.
164164
},
165165
})
166166
```
167-
3. After role initialization, default metrics will be enabled and the global
167+
168+
3. To view metrics via API endpoints, use `set_export`.
169+
**NOTE** that `set_export` has lower priority than clusterwide config and won't work if metrics config is present.
170+
171+
```lua
172+
local metrics = require('cartridge.roles.metrics')
173+
metrics.set_export({
174+
{
175+
path = '/path_for_json_metrics',
176+
format = 'json'
177+
},
178+
{
179+
path = '/path_for_prometheus_metrics',
180+
format = 'prometheus'
181+
},
182+
{
183+
path = '/health',
184+
format = 'health'
185+
}
186+
})
187+
```
188+
You can add several entry points of the same format by different paths,
189+
like this:
190+
191+
```lua
192+
metrics.set_export({
193+
{
194+
path = '/path_for_json_metrics',
195+
format = 'json'
196+
},
197+
{
198+
path = '/another_path_for_json_metrics',
199+
format = 'json'
200+
},
201+
})
202+
```
203+
The metrics will be available on the path specified in `path` in the format
204+
specified in `format`.
205+
206+
4. After role initialization, default metrics will be enabled and the global
168207
label 'alias' will be set. If you need to use the functionality of any metrics
169208
package, you may get it as a Cartridge service and use it like a regular
170209
package after `require`:
@@ -173,30 +212,6 @@ via configuration.
173212
local metrics = cartridge.service_get('metrics')
174213
```
175214

176-
4. To view metrics via API endpoints, use the following configuration
177-
(to learn more about Cartridge configuration, see
178-
[this](https://www.tarantool.io/en/doc/latest/book/cartridge/topics/clusterwide-config/#managing-role-specific-data)):
179-
```yaml
180-
metrics:
181-
export:
182-
- path: '/path_for_json_metrics'
183-
format: 'json'
184-
- path: '/path_for_prometheus_metrics'
185-
format: 'prometheus'
186-
- path: '/health'
187-
format: 'health'
188-
```
189-
190-
You can add several entry points of the same format by different paths, like this:
191-
```yaml
192-
metrics:
193-
export:
194-
- path: '/path_for_json_metrics'
195-
format: 'json'
196-
- path: '/another_path_for_json_metrics'
197-
format: 'json'
198-
```
199-
200215
## Next steps
201216

202217
See:

‎doc/monitoring/getting_started.rst

+50-45
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ Instance health check
7070
-------------------------------------------------------------------------------
7171

7272
In production environments Tarantool Cluster usually has a large number of so called
73-
"routers", Tarantool instances that handle input load and it is required to evenly
74-
distribute the load. Various load-balancers are used for this, but any load-balancer
75-
have to know which "routers" are ready to accept the load at that very moment. Metrics
76-
library has a special plugin that creates an http handler that can be used by the
77-
load-balancer to check the current state of any Tarantool instance. If the instance
78-
is ready to accept the load, it will return a response with a 200 status code, if not,
73+
"routers", Tarantool instances that handle input load and it is required to evenly
74+
distribute the load. Various load-balancers are used for this, but any load-balancer
75+
have to know which "routers" are ready to accept the load at that very moment. Metrics
76+
library has a special plugin that creates an http handler that can be used by the
77+
load-balancer to check the current state of any Tarantool instance. If the instance
78+
is ready to accept the load, it will return a response with a 200 status code, if not,
7979
with a 500 status code.
8080

8181
.. _cartridge-role:
@@ -117,6 +117,47 @@ via configuration.
117117
},
118118
})
119119
120+
#. To view metrics via API endpoints, use ``set_export``.
121+
122+
**NOTE** that ``set_export`` has lower priority than clusterwide config and won't work if metrics config is present.
123+
124+
.. code-block:: lua
125+
126+
local metrics = require('cartridge.roles.metrics')
127+
metrics.set_export({
128+
{
129+
path = '/path_for_json_metrics',
130+
format = 'json'
131+
},
132+
{
133+
path = '/path_for_prometheus_metrics',
134+
format = 'prometheus'
135+
},
136+
{
137+
path = '/health',
138+
format = 'health'
139+
}
140+
})
141+
142+
You can add several entry points of the same format by different paths,
143+
like this:
144+
145+
.. code-block:: yaml
146+
147+
metrics.set_export({
148+
{
149+
path = '/path_for_json_metrics',
150+
format = 'json'
151+
},
152+
{
153+
path = '/another_path_for_json_metrics',
154+
format = 'json'
155+
},
156+
})
157+
158+
The metrics will be available on the path specified in ``path`` in the format
159+
specified in ``format``.
160+
120161
#. Enable role in the interface:
121162

122163
.. image:: images/role-enable.png
@@ -137,9 +178,10 @@ via configuration.
137178
local cartridge = require('cartridge')
138179
local metrics = cartridge.service_get('metrics')
139180
140-
#. To view metrics via API endpoints, use the following configuration
181+
#. To change metrics HTTP path in **runtime**, you may use the following configuration
141182
(to learn more about Cartridge configuration, see
142-
`this <https://www.tarantool.io/en/doc/latest/book/cartridge/topics/clusterwide-config/#managing-role-specific-data>`_):
183+
`this <https://www.tarantool.io/en/doc/latest/book/cartridge/topics/clusterwide-config/#managing-role-specific-data>`_).
184+
We don't recommend to use it to set up metrics role, use ``set_export`` instead.
143185

144186
.. code-block:: yaml
145187
@@ -155,40 +197,3 @@ via configuration.
155197
.. image:: images/role-config.png
156198
:align: center
157199

158-
**OR**
159-
160-
Use ``set_export``:
161-
162-
**NOTE** that ``set_export`` has lower priority than clusterwide config and won't work if metrics config is present.
163-
164-
.. code-block:: lua
165-
166-
metrics.set_export({
167-
{
168-
path = '/path_for_json_metrics',
169-
format = 'json'
170-
},
171-
{
172-
path = '/path_for_prometheus_metrics',
173-
format = 'prometheus'
174-
},
175-
{
176-
path = '/health',
177-
format = 'health'
178-
}
179-
})
180-
181-
The metrics will be available on the path specified in ``path`` in the format
182-
specified in ``format``.
183-
184-
You can add several entry points of the same format by different paths,
185-
like this:
186-
187-
.. code-block:: yaml
188-
189-
metrics:
190-
export:
191-
- path: '/path_for_json_metrics'
192-
format: 'json'
193-
- path: '/another_path_for_json_metrics'
194-
format: 'json'

‎test/integration/cartridge_role_test.lua

+15
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,18 @@ g.test_non_empty_clusterwide_config_overrides_set_export = function()
274274
resp = server:http_request('get', '/new-metrics', {raise = false})
275275
t.assert_equals(resp.status, 404)
276276
end
277+
278+
g.test_set_export_from_require_role = function()
279+
local server = g.cluster.main_server
280+
server.net_box:eval([[
281+
local metrics = require('cartridge.roles.metrics')
282+
metrics.set_export(...)
283+
]], {{
284+
{
285+
path = '/metrics',
286+
format = 'json',
287+
},
288+
}})
289+
local resp = server:http_request('get', '/metrics', {raise = false})
290+
t.assert_equals(resp.status, 200)
291+
end

0 commit comments

Comments
 (0)
Please sign in to comment.