<% set default_geo_regions = ('man', 'sas', 'vla') %>

<% set succ_charts = (
    ('requests', 'summ', 0),
    ('inprog', 'ammv', 1),
) %>

<% set fail_charts = (
    ('client_fail', 0),
    ('backend_fail', 2),
    ('other_fail', 2),
    ('backend_error', 1),
    ('backend_timeout', 1),
    ('conn_refused', 1),
    ('conn_timeout', 1),
    ('conn_other_error', 1),
) %>

<% set default_timeline_charts = (999,998,995,99,98,95) %>

<% set default_signal = 'service_total' %>

<% set codes_charts = (
    ('101', 2),
    ('1xx', 2),
    ('2xx', 0),
    ('3xx', 0),
    ('4xx', 2),
    ('404', 2),
    ('5xx', 1),
) %>

<% set default_request_to_signals = ('succ_summ', 'fail_summ') %>

<% set signals = (signal|default(default_signal)|string).split(',') %>

{
    "title": "<< prj >> << signal|default(default_signal) >>",
    "type": "panel",
    "charts": [
    <% for geo in locations|default(default_geo_regions) %>
        {
            "normalize": "true",
            "title": "<< geo >> << signal|default(default_signal) >> requests",
            "type": "graphic",
            "width": 4,
            "height": 2,
            "row": 1,
            "col": << 4 * loop.index0  + 1 >>,
            "yAxis": [{"minValue":0},{"minValue":0}],
            "signals": [
        <% for sig in signals %>
            <% for item in succ_charts %>
                {
                    "tag": "itype=balancer;prj=<< prj >>;geo=<< geo >>",
                    "host": "<< host | default('ASEARCH') >>",
                    "name": "balancer_report-report-<< sig >>-<< item[0] >>_<< item[1] >>",
                    "title": "<< sig >> << item[0] >>",
                    "yAxis": << item[2] >>
                },
            <% endfor %>
        <% endfor %>
            ]
        },
    <% endfor %>

    <% for geo in locations|default(default_geo_regions) %>
        {
            "normalize": "true",
            "title": "<< geo >> << signal|default(default_signal) >> errors / reqs * 10000",
            "type": "graphic",
            "width": 4,
            "height": 2,
            "row": 3,
            "col": << 4 * loop.index0  + 1 >>,
            "yAxis": [{"minValue":0},{"minValue":0},{"minValue":0}],
            "signals": [
        <% for sig in signals %>
            <% for item in fail_charts %>
                {
                    "tag": "itype=balancer;prj=<< prj >>;geo=<< geo >>",
                    "host": "<< host | default('ASEARCH') >>",
                    "name": "div(mul(const(10000),balancer_report-report-<< sig >>-<< item[0] >>_summ),max(balancer_report-report-<< sig >>-requests_summ, const(1)))",
                    "title": "<< sig >> << item[0] >> / reqs * 10000",
                    "yAxis": << item[1] >>
                },
            <% endfor %>
        <% endfor %>
            ]
        },
    <% endfor %>

    <% for geo in locations|default(default_geo_regions) %>
        {
            "normalize": "true",
            "title": "<< geo >> << signal|default('default_signal') >> outgoing codes / reqs * 10000",
            "type": "graphic",
            "width": 4,
            "height": 2,
            "row": 5,
            "col": << 4 * loop.index0  + 1 >>,
            "yAxis": [{"minValue":0},{"minValue":0},{"minValue":0}],
            "signals": [
        <% for sig in signals %>
            <% for code in codes_charts %>
                {
                    "tag": "itype=balancer;prj=<< prj >>;geo=<< geo >>",
                    "host": "<< host | default('ASEARCH') >>",
                    "name": "div(mul(const(10000),balancer_report-report-<< sig >>-outgoing_<< code[0] >>_summ),balancer_report-report-<< sig >>-requests_summ)",
                    "title": "<< sig >> << code[0] >> / reqs * 10000",
                    "yAxis": << code[1] >>
                },
            <% endfor %>
        <% endfor %>
            ]
        },
    <% endfor %>

    <% if weighted is defined %>
        <% for geo in locations|default(default_geo_regions) %>
            {
                "normalize": "true",
                "title": "<< geo >> << signal|default('default_signal') >> request to geo answers",
                "type": "graphic",
                "width": 4,
                "height": 2,
                "row": 7,
                "col": << 4 * loop.index0  + 1 >>,
                "signals": [
            <% for sig in signals %>
                <% for to_geo in locationsto|default(default_geo_regions) %>
                    <% for line in request_to_signals|default(default_request_to_signals) %>
                    {
                        "tag": "itype=balancer;prj=<< prj >>;geo=<< geo >>",
                        "host": "<< host | default('ASEARCH') >>",
                        "name": "balancer_report-report-<< sig >>_requests_to_<< to_geo >>-<< line >>",
                        "title": "<< sig >>_requests_to_<< to_geo >>-<< line >>"
                    },
                    <% endfor %>
                <% endfor %>
            <% endfor %>
                ]
            },
        <% endfor %>
    <% endif %>

    <% for geo in locations|default(default_geo_regions) %>
        {
            "normalize": "true",
            "title": "<< geo >> << signal|default('default_signal') >> processing time distribution",
            "type": "graphic",
            "width": 4,
            "height": 2,
            "row": 3,
            "col": << 4 * loop.index0  + 1 >>,
            "signals": [
        <% for sig in signals %>
            <% for t in timelines|default(default_timeline_charts) %>
                {
                    "tag": "itype=balancer;prj=<< prj >>;geo=<< geo >>",
                    "host": "<< host | default('ASEARCH') >>",
                    "name": "quant(balancer_report-report-<< sig >>-processing_time_hgram,<< t >>)",
                    "title": "<< sig >> << t >>%"
                },
            <% endfor %>
        <% endfor %>
            ]
        },
    <% endfor %>
    ]
}
