Exemple #1
0
def build_dashboard(es_url, kibana_url, es_index, template_filename, goal,
                    attribute, backend_metrics_data):
    """
    Build a Kibana dashboard using as template template_filename showing the data for
    an attribute in a goal from the quality model.

    :param es_url: Elasticsearch URL
    :param kibana_url: Kibana URL
    :param es_index: index with the metrics data
    :param template_filename: template to be used to create the dashboard
    :param goal: quality model goal to be included
    :param attribute: atribute in the goal to be included
    :param backend_metrics_data: metrics backend to be used for getting the data
    :return: a dict with the dashboard created
    """

    logging.debug('Building the dashboard for the attribute: %s (goal %s)',
                  attribute, goal)

    # Check that the model and the template dashboard exists

    # Collect metrics to be included in this attribute
    metrics_data = []

    for metric in attribute.metrics.all():
        if metric.data:
            metrics_data.append(metric.data.implementation)
        else:
            logging.warning("The metric %s does not have data", metric.name)

    logging.debug("Metrics to be included: %s", metrics_data)

    # Upload the dashboard created from the template dashboard
    logging.debug("Uploading the template panel %s", template_filename)
    dashboard = VizTemplatesData.read_template(template_filename)

    # An alias is created from the index with the metrics to the template index
    index_pattern_name = dashboard['index_patterns'][0]['id']
    create_alias(es_url, es_index, index_pattern_name)

    # Add the filters to the template dashboard and export it to Kibana
    search_json = json.loads(dashboard['dashboard']['value']
                             ['kibanaSavedObjectMeta']['searchSourceJSON'])
    metric_name = find_metric_name_field(backend_metrics_data)
    search_json['filter'] = build_filters(metrics_data, metric_name)
    dashboard['dashboard']['value']['kibanaSavedObjectMeta'][
        'searchSourceJSON'] = json.dumps(search_json)
    dashboard['dashboard']['value']['title'] = goal.name + "_" + attribute.name
    dashboard['dashboard']['id'] = goal.name + "_" + attribute.name

    feed_dashboard(dashboard, es_url, kibana_url)

    logging.info('Created the attribute dashboard %s',
                 dashboard['dashboard']['value']['title'])

    return dashboard
Exemple #2
0
def build_dashboards(es_url, kibana_url, es_index, template_file,
                     template_assess_file, model_name, backend_metrics_data,
                     from_date, to_date):
    """
    Create all the dashboards needed to viz a Quality Model

    :param es_url: Elasticsearch URL
    :param kibana_url: Kibana URL
    :param es_index: index in elasticsearch with the metrics data
    :param template_file: template file to be used for building the attribute dashboards
    :param template_assess_file: template file to be used for the assessment dashboard
    :param model_name: quality model to use
    :param backend_metrics_data: backend to use to collect the metrics data
    :param from_date: date since which the metrics must be computed
    :param to_date: date until which the metrics must be computed
    :return:
    """

    logging.debug('Building the dashboards for the model: %s', model_name)

    if not template_assess_file:
        template_assess_file = ASSESS_PANEL

    qm_menu = {}  # Kibana menu for accessing the Quality Model dashboards
    assess_menu = {}  # Kibana menu for accessing the assessment dashboard

    # Check that the model and the template dashboard exists
    model_orm = None
    try:
        model_orm = QualityModel.objects.get(name=model_name)
    except QualityModel.DoesNotExist:
        logging.error('Can not find the metrics model %s', model_name)
        raise RuntimeError("Can not find the metrics model " + model_name)

    # Build a new dashboard for each attribute in the quality model
    for goal in model_orm.goals.all():
        for attribute in goal.attributes.all():
            dash_json = build_dashboard(es_url, kibana_url, es_index,
                                        template_file, goal, attribute,
                                        backend_metrics_data)
            qm_menu[dash_json['dashboard']['value']
                    ['title']] = dash_json['dashboard']['id']

    # Project assessment is included also in the viz
    assess(es_url, es_index, model_name, backend_metrics_data, from_date,
           to_date)
    # Upload the radar viz to show the assessment
    assess_dash = VizTemplatesData.read_template(template_assess_file)
    feed_dashboard(assess_dash, es_url, kibana_url)
    assess_menu[assess_dash['dashboard']['value']
                ['title']] = assess_dash['dashboard']['id']

    build_menu(es_url, qm_menu, assess_menu)