Skip to content

Commit

Permalink
add zone label
Browse files Browse the repository at this point in the history
Fix promtool version

Set promtool version=2.25.0

Set promtool to latest

Fix promtool #4

Fix promtool #5

Fix promtool #6

Fix promtool #7

Fix promtool #8

Fix promtool #9

Fix promtool #11

Fix review comments

Fix check_cartridge_version() helper

CI: Add Cartridge 2.5.0 to test matrix
  • Loading branch information
Yaroslav Shumakov authored and yngvar-antonsson committed Mar 17, 2021
1 parent a2d783e commit 7188d6b
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- "2.5"
- "2.6"
- "2.7.0"
cartridge: [ "", "1.2.0", "2.1.2" ]
cartridge: [ "", "1.2.0", "2.1.2", "2.4.0", "2.5.0" ]
runs-on: ubuntu-latest
container:
image: tarantool/tarantool:${{ matrix.tarantool }}
Expand Down Expand Up @@ -52,15 +52,16 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: install Taranool
- name: install Tarantool
run: |
curl -L https://tarantool.io/aYJZbH/release/2.3/installer.sh | bash
curl -L https://tarantool.io/installer.sh | sudo VER=2.4 bash
sudo apt install -y tarantool-dev
- uses: actions/setup-go@v2
with:
go-version: '1.15'

- name: promtool test
run: |
go get github.com/prometheus/prometheus/cmd/promtool
GO111MODULE=on go get github.com/prometheus/prometheus/cmd/promtool@a6be548dbc17780d562a39c0e4bd0bd4c00ad6e2
make test_promtool
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- zone label support for Tarantool Cartridge >= '2.4.0'

## [0.7.0] - 2021-02-09
### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ via configuration.
local metrics = cartridge.service_get('metrics')
```

5. There is an ability in Tarantool Cartridge >= '2.4.0' to set a zone for each
server in cluster. If zone was set for the server 'zone' label for all metrics
of this server will be added.

## Next steps

See:
Expand Down
14 changes: 12 additions & 2 deletions cartridge/roles/metrics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ local handlers = {
end,
}

local function init()
local function set_labels()
local params, err = argparse.parse()
assert(params, err)
metrics.set_global_labels({alias = params.alias or params.instance_name})
local this_instance = cartridge.admin_get_servers(box.info.uuid)
local zone
if this_instance and this_instance[1] then
zone = this_instance[1].zone
end
metrics.set_global_labels({alias = params.alias or params.instance_name, zone = zone})
end

local function init()
set_labels()
metrics.enable_default_metrics()
metrics.enable_cartridge_metrics()
end
Expand Down Expand Up @@ -118,6 +127,7 @@ local function apply_config(conf)
end
metrics_config_present = false
end
set_labels()
apply_routes(metrics_conf.export)
end

Expand Down
4 changes: 4 additions & 0 deletions doc/monitoring/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ via configuration.
local cartridge = require('cartridge')
local metrics = cartridge.service_get('metrics')
#. There is an ability in Tarantool Cartridge >= ``'2.4.0'`` to set a zone for each
server in cluster. If zone was set for the server ``'zone'`` label for all metrics
of this server will be added.

#. To change metrics HTTP path in **runtime**, you may use the following configuration
(to learn more about Cartridge configuration, see
`this <https://www.tarantool.io/en/doc/latest/book/cartridge/topics/clusterwide-config/#managing-role-specific-data>`_).
Expand Down
65 changes: 65 additions & 0 deletions test/integration/cartridge_role_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local t = require('luatest')
local yaml = require('yaml')
local g = t.group()

local utils = require('test.utils')
local helpers = require('test.helper')

local function set_export(export)
Expand Down Expand Up @@ -289,3 +290,67 @@ g.test_set_export_from_require_role = function()
local resp = server:http_request('get', '/metrics', {raise = false})
t.assert_equals(resp.status, 200)
end

local function set_zones(zones)
local servers = {}
for k, v in pairs(zones) do
table.insert(servers, {uuid = k, zone = v})
end
return g.cluster.main_server.net_box:eval([[
local servers = ...
local ret, err = require('cartridge').admin_edit_topology({
servers = servers,
})
if ret == nil then
return nil, err
end
return true
]], {servers})
end

local function check_cartridge_version(version)
local cartridge_version = require('cartridge.VERSION')
t.skip_if(cartridge_version == 'unknown',
'Cartridge version is unknown, must be 2.0.2 or greater')
t.skip_if(utils.is_version_less(cartridge_version, version),
string.format('Cartridge version is must be %s or greater', version))
end

g.test_zone_label_present = function()
check_cartridge_version('2.4.0')
local server = g.cluster.main_server

local ok, err = set_zones({
[server.instance_uuid] = 'z1',
})
t.assert_equals({ok, err}, {true, nil})
assert_upload_metrics_config('/metrics')

local resp = server:http_request('get', '/metrics', {raise = false})
t.assert_equals(resp.status, 200)
for _, obs in pairs(resp.json) do
t.assert_equals(
'z1', obs.label_pairs['zone'],
('Alias label is present in metric %s'):format(obs.metric_name)
)
end
end

g.test_zone_label_changes_in_runtime = function()
check_cartridge_version('2.4.0')
local server = g.cluster.main_server

local ok, err = set_zones({
[server.instance_uuid] = 'z2',
})
t.assert_equals({ok, err}, {true, nil})

local resp = server:http_request('get', '/metrics', {raise = false})
t.assert_equals(resp.status, 200)
for _, obs in pairs(resp.json) do
t.assert_equals(
'z2', obs.label_pairs['zone'],
('Alias label is present in metric %s'):format(obs.metric_name)
)
end
end

0 comments on commit 7188d6b

Please sign in to comment.