{

<% if not geo %>
    <% set geo = "[sas,man,vla]" %>
<% endif %>
<% if not panels %>
  <% set panels = "[error,quantile,attempts,service_per_dc]" %>
<% endif %>
<% if not prj %>
    <% set prj = "l7-balancer" %>
<% endif %>
<% if not service %>
  <% set service = "service_total" %>
<% endif %>

<% if service_req %>
  <% set panels = "[error,quantile,attempts,service_per_dc,succ_requests_to_geo,fail_requests_to_geo]" %>
<% endif %>

<% if lights %>
  <% set lights = 1 %>
<% else %>
  <% set lights = 0 %>
<% endif %>


<% set title = "knoss search " + geo|from_json|join(',') %>

    "charts": [
<% set col_shift = 0 %>
<% set row_shift = 0 %>
<% set width = 9 %>
<% set height = 1 %>

<% set geo = geo|from_json %>
<% set panels = panels|from_json %>

<% for location in geo %>
    <% if not loop.first %>
        ,
    <% endif %>

    <% if location == "sas" %>
        <% set ctype = "prestable" %>
        <% set metrics_alert = "gen.ASEARCH.metricsimport_self.aver_unistat-metrics-judged-pfound-sas-yandex-ru-849_avvv_" %>
    <% endif %>
    <% if location == "man" %>
        <% set ctype = "prod" %>
        <% set metrics_alert = "gen.ASEARCH.metricsimport_self.aver_unistat-metrics-judged-pfound-man-yandex-ru-1173_avvv_" %>
    <% endif %>
    <% if location == "vla" %>
        <% set ctype = "prod" %>
        <% set metrics_alert = "gen.ASEARCH.metricsimport_self.aver_unistat-metrics-judged-pfound-vla-yandex-ru-6246_avvv_" %>
    <% endif %>


    <% for panel in panels %>
        <% if not loop.first %>
            ,
        <% endif %>

        <% if "error" == panel %>
            <% if lights %>
                {"name": "L7_alerts.self.<< prj >>.<< location >>.total_fails",
                 "col": << col_shift + 9 >>,
                 "width": 1,
                 "height": 0.5,
                 "type": "alert",
                 "row": << row_shift + 1 >>,
                 "title": "<< location >> total fails"
                },
                {"name": "L7_backend_alerts.<< service >>.<< location >>.backend_fail",
                 "col": << col_shift + 9 >>,
                 "width": 1,
                 "height": 0.5,
                 "type": "alert",
                 "row": << row_shift + 1.5 >>,
                 "title": "<< location >> backend fails"
                },
            <% endif %>
            {
                "title": "ERROR on << location >>",
                "col": << col_shift + 1 >>,
                "row": << row_shift + 1 >>,
                "width": << width - lights >>,
                "height": << height >>,
                "signals": [
                    {
                        "color": "#D894FA",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-conn_refused_summ",
                        "title": "connection refused"
                    },
                    {
                        "color": "#8C86F4",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-conn_timeout_summ",
                        "title": "connection timeout"
                    },
                    {
                        "color": "#F45000",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-conn_fail_summ",
                        "title": "connection fail"
                    },
                    {
                        "color": "#86B2F4",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-backend_timeout_summ",
                        "title": "backend timeout"
                    },
                    {
                        "color": "#A0ECF3",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-backend_error_summ",
                        "title": "backend error"
                    },
                    {
                        "color": "#A0F3AF",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-backend_fail_summ",
                        "title": "backend fail"
                    },
                    {
                        "color": "#EBEE77",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-client_error_summ",
                        "title": "client error"
                    },
                    {
                        "color": "#F3C13F",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-client_fail_summ",
                        "title": "client fail"
                    },
                    {
                        "color": "#791511",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "sum(balancer_report-report-<< service >>_requests_to_pumpkin-inprog_ammv,balancer_report-report-<< service >>_requests_to_pumpkin-succ_summ,balancer_report-report-<< service >>_requests_to_pumpkin-fail_summ)",
                        "title": "requests to pumpkin"
                    },
                    {
                        "color": "#EFA87B",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-sc_1xx_summ",
                        "title": "1xx backends resp"
                    },
                    {
                        "color": "#F292C1",
                        "host": "ASEARCH",
                        "yAxis": 1,
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-sc_3xx_summ",
                        "title": "3xx backends resp"
                    },
                    {
                        "color": "#CB92F2",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-sc_4xx_summ",
                        "title": "4xx backends resp"
                    },
                    {
                        "color": "#4D41E6",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-sc_5xx_summ",
                        "title": "5xx backends resp"
                    },
                    {
                        "color": "#000000",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-fail_summ",
                        "title": "FAILS"
                    },
                    {
                        "color": "#FF0000",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-limited_backend_attempt_summ",
                        "title": "rate limiter"
                    },
                    {
                        "color": "#CF0C19",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "perc(balancer_report-report-<< service >>-fail_summ,sum(balancer_report-report-<< service >>-fail_summ,balancer_report-report-<< service >>-succ_summ))",
                        "title": "% fails"
                    },
                ],
                "consts": [],
                "type": "graphic",
                "normalize": true,
                "stacked": false
            }
            <% set row_shift = row_shift + height  %>
        <% elif "quantile" == panel %>
            <% if lights %>
                {"name": "L7_alerts.self.<< prj >>.<< location >>.worker_cpu_q95",
                 "col": << col_shift + 9 >>,
                 "width": 1,
                 "height": << height >>,
                 "type": "alert",
                 "row": << row_shift + 1 >>,
                 "title": "CPU quant_95"
                },
            <% endif %>
            {
                "title": "CPU workers quantile on << location >>",
                "col": << col_shift + 1 >>,
                "row": << row_shift + 1 >>,
                "width": << width - lights >>,
                "height": << height >>,
                "signals": [
                    {
                        "color": "#F6AB31",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "quant(balancer_report-worker-cpu_usage_hgram, 95)",
                        "title": "quant_95"
                    },
                    {
                        "color": "#FF0000",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>, experiment;prj=<< prj >>;geo=<< location >>",
                        "name": "quant(balancer_report-worker-cpu_usage_hgram, 99)",
                        "title": "quant_99"
                    },
                ],
                "consts": [],
                "type": "graphic",
                "normalize": true,
                "stacked": false
            }
            <% set row_shift = row_shift + height  %>
        <% elif "attempts" == panel %>
            {
                "title": "success + retry << location >> ",
                "col": << col_shift + 1 >>,
                "row": << row_shift + 1 >>,
                "width": << width >>,
                "height": << height >>,
                "signals": [
                    {
                        "color": "#1EC6EB",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-backend_attempt_summ",
                        "title": "retry"
                    },
                    {
                        "color": "#EBAC1E",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-sc_2xx_summ",
                        "title": "2xx"
                    },
                    {
                        "color": "#BA55D3",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-report-<< service >>-succ_summ",
                        "title": "success"
                    },
                ],
                "consts": [],
                "type": "graphic",
                "normalize": true,
                "stacked": false
            }
            <% set row_shift = row_shift + height  %>
        <% elif "service_per_dc" == panel %>
            {
                "title": "service per dc << location >> ",
                "col": << col_shift + 1 >>,
                "row": << row_shift + 1 >>,
                "width": << width >>,
                "height": << height >>,
                "signals": [
                    {
                        "color": "#5BBC20",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "quant(balancer_report-report-<< service >>-externalunknown_hgram, 99)",
                        "title": "quant_99"
                    },
                    {
                        "color": "#1EC6EB",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "quant(balancer_report-report-<< service >>-externalunknown_hgram, 95)",
                        "title": "quant_95"
                    },
                    {
                        "color": "#BA55D3",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "quant(balancer_report-report-<< service >>-externalunknown_hgram, 75)",
                        "title": "quant_75"
                    },
                    {
                        "color": "#E11414",
                        "host": "ASEARCH",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "quant(balancer_report-report-<< service >>-externalunknown_hgram, 50)",
                        "title": "quant_50"
                    },
                ],
                "consts": [],
                "type": "graphic",
                "normalize": true,
                "stacked": false
            }
            <% set row_shift = row_shift + height  %>
        <% elif "succ_requests_to_geo" == panel %>
            <% for loc in ("sas","man","vla") %>
                <% if not loop.first %>
                    ,
                <% endif %>
                {
                    "title": "<< location >>-<< loc >> succ requests",
                    "col": << col_shift + 1 >>,
                    "row": << row_shift + 1 >>,
                    "width": << 3 >>,
                    "height": << height >>,
                    "signals": [
                        {
                            "color": "#94ADFA",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-succ_summ",
                            "title": "success requests to << loc >>"
                        },
                    ],
                    "consts": [],
                    "type": "graphic",
                    "normalize": true,
                    "stacked": false
                }
            <% endfor %>
            <% set row_shift = row_shift + height  %>
        <% elif "fail_requests_to_geo" == panel %>
            <% if lights %>
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.sas_backend_fail",
                    "col": << col_shift + 1 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "backend fails"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.sas_backend_error",
                    "col": << col_shift + 2 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "backend error"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.sas_conn_error",
                    "col": << col_shift + 3 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "conn error"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.man_backend_fail",
                    "col": << col_shift + 4 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "backend fails"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.man_backend_error",
                    "col": << col_shift + 5 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "backend error"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.man_conn_error",
                    "col": << col_shift + 6 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "conn error"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.vla_backend_fail",
                    "col": << col_shift + 7 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "backend fails"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.vla_backend_error",
                    "col": << col_shift + 8 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "backend error"
                },
                {
                    "name": "L7_backend_alerts.<< service_req >>.<< location >>.vla_conn_error",
                    "col": << col_shift + 9 >>,
                    "width": 1,
                    "height": 0.5,
                    "type": "alert",
                    "row": << row_shift + 2 >>,
                    "title": "conn error"
                },

            <% endif %>
            <% for loc in ("sas","man","vla") %>
                <% if not loop.first %>
                    ,
                <% endif %>
                {
                    "title": "<< location >>-<< loc >> fail requests",
                    "col": << col_shift + 1 >>,
                    "row": << row_shift + 1 >>,
                    "width": << 3 >>,
                    "height": << height >>,
                    "signals": [
                        {
                            "color": "#1EC6EB",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-fail_summ",
                            "title": "<< location >> to << loc >> fail_summ"
                        },
                        {
                            "color": "#AF7CE9",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-client_fail_summ",
                            "title": "<< location >> to << loc >> client_fail_summ"
                        },
                        {
                            "color": "#EEA03A",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-conn_error_summ",
                            "title": "<< location >> to << loc >> conn_error_summ"
                        },
                        {
                            "color": "#E6566E",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-conn_fail_summ",
                            "title": "<< location >> to << loc >> conn_fail_summ"
                        },
                        {
                            "color": "#E77CE9",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-conn_refused_summ",
                            "title": "<< location >> to << loc >> conn_refused_summ"
                        },
                        {
                            "color": "#EEDF3A",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-conn_timeout_summ",
                            "title": "<< location >> to << loc >> conn_timeout_summ"
                        },
                        {
                            "color": "#81E34A",
                            "host": "ASEARCH",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-backend_refused_summ",
                            "title": "<< location >> to << loc >> backend_refused_summ"
                        },
                    ],
                    "consts": [],
                    "type": "graphic",
                    "normalize": true,
                    "stacked": false
                }
            <% endfor %>
            <% set row_shift = row_shift + height  %>
        <% endif %>
    <% endfor %>
    <% set col_shift = col_shift + 9 %>
<% endfor %>
    ],
    "type": "panel"
}
