Ejemplo n.º 1
0
    def test_select_multi(self):
        owner_id = uuid.uuid1()

        d_id1 = uuid.uuid1()
        d_id2 = uuid.uuid1()
        r = Report.insert(owner_id, 'r')

        res = Layout.select_multi(owner_id, [d_id1, d_id2])
        self.assertEqual([], res)

        tile_config = {
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
        }

        t1 = Tile.insert(owner_id, r.report_id, d_id1, tile_config)
        place_tile(t1)

        res = Layout.select_multi(owner_id, [d_id1, d_id2])
        self.assertEqual(1, len(res))
        self.assertEqual(
            Layout.select(owner_id, d_id1).layout_id, res[0].layout_id)

        t2 = Tile.insert(owner_id, r.report_id, d_id2, tile_config)
        place_tile(t2)
        res = Layout.select_multi(owner_id, [d_id1, d_id2])
        self.assertEqual(2, len(res))
        self.assertEqual(
            Layout.select(owner_id, d_id1).layout_id, res[0].layout_id)
        self.assertEqual(
            Layout.select(owner_id, d_id2).layout_id, res[1].layout_id)
Ejemplo n.º 2
0
    def test_get_dashboards_by_report_id(self):
        od = self.test_inserting()

        res = od.get_dashboards_by_report_id()
        self.assertEqual({}, res)

        r = Report.insert(od.owner_id, 'r')
        r2 = Report.insert(od.owner_id, 'r2')
        r3 = Report.insert(od.owner_id, 'r3')
        tile_config = {
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
        }

        place_tile(Tile.insert(od.owner_id, r.report_id, od.dashboards[3].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r.report_id, od.dashboards[3].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r.report_id, od.dashboards[0].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r2.report_id, od.dashboards[0].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r3.report_id, od.dashboards[1].dashboard_id, tile_config))

        res = od.get_dashboards_by_report_id()
        self.assertEqual(3, len(res))
        self.assertEqual([od.dashboards[0], od.dashboards[3]], res[r.report_id])
        self.assertEqual([od.dashboards[0]], res[r2.report_id])
        self.assertEqual([od.dashboards[1]], res[r3.report_id])
Ejemplo n.º 3
0
    def test_get_dashboards_displaying_report(self):
        od = self.test_inserting()

        res = od.get_dashboards_displaying_report(uuid.uuid4())
        self.assertEqual([], res)

        r = Report.insert(od.owner_id, 'r')
        tile_config = {
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
        }

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual([], res)

        t1 = Tile.insert(od.owner_id, r.report_id, od.dashboards[3].dashboard_id, tile_config)
        place_tile(t1)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(1, len(res))
        self.assertEqual('Dash 4', res[0].dashboard_name)

        t2 = Tile.insert(od.owner_id, r.report_id, od.dashboards[1].dashboard_id, tile_config)
        place_tile(t2)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(2, len(res))
        self.assertEqual('Dash 2', res[0].dashboard_name)
        self.assertEqual('Dash 4', res[1].dashboard_name)

        t3 = Tile.insert(od.owner_id, r.report_id, od.dashboards[1].dashboard_id, tile_config)
        place_tile(t3)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(2, len(res))
        self.assertEqual('Dash 2', res[0].dashboard_name)
        self.assertEqual('Dash 4', res[1].dashboard_name)

        detach_tile(t3)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(2, len(res))
        self.assertEqual('Dash 2', res[0].dashboard_name)
        self.assertEqual('Dash 4', res[1].dashboard_name)

        detach_tile(t2)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(1, len(res))
        self.assertEqual('Dash 4', res[0].dashboard_name)

        od.dashboards[3].delete()

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(0, len(res))
Ejemplo n.º 4
0
    def test_filling_default_options(self):
        rd = new_report_data('points', tags=['ip:192.168.1.1'])

        for tw_type in ('Range', 'Single'):
            ss1 = dataseries.SeriesSpec(2, 0, dict(op='eq', args=['mike']))
            ss1.promote_colnos_to_headers(rd.instances[-1])
            ss1.set_name('mikepoints')
            tile_config = {
                'tw_type':
                tw_type,
                'tags': ['ip:192.168.1.1'],
                'series_spec_list': [
                    ss1,
                    dataseries.SeriesSpec(2, 0, dict(op='eq',
                                                     args=['monique'])),
                ],
                'tile_options': {
                    'colors': ['red', 'blue', 'pink', 'cyan'],
                    'seconds_back':
                    600,
                    'tile_title':
                    'Points by user',
                    'sscs':
                    dataseries.SeriesSpec(2, 0, dict(op='eq',
                                                     args=['monique'])),
                }
            }

            tile = Tile.insert(rd.owner_id, rd.report.report_id,
                               rd.dashboard_id, tile_config)
            dataseries.update_default_options(tile)
            data = tile.get_tile_data()
            self.assertEqual(['red', 'blue'], data['combined_colors'])

            tile_config2 = {
                'tw_type':
                tw_type,
                'tags': ['ip:192.168.1.1'],
                'series_spec_list': [
                    dataseries.guess_series_spec(rd.report, rd.instances[-1],
                                                 1, 2),
                    dataseries.SeriesSpec(2, 0, dict(op='eq',
                                                     args=['monique'])),
                ],
            }
            self.assertEqual('mikepoints',
                             tile_config2['series_spec_list'][0].name())
            tile2 = Tile.insert(rd.owner_id, rd.report.report_id,
                                rd.dashboard_id, tile_config)
            dataseries.update_default_options(tile2)
            data2 = tile2.get_tile_data()
            self.assertEqual('mikepoints', data2['series_data'][0]['name'])
            self.assertEqual(['red', 'blue'], data2['combined_colors'])
Ejemplo n.º 5
0
    def test_promote_first_as_master_losing_sscreated(self):
        rd = ReportData('r')

        ss = dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0']))
        tile_config1 = {
            'series_spec_list': [ss],
            'tags': ['p1:10'],
            'tile_options': {
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['p1:10']),
                'sscs': ss
            }
        }

        tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config1)
        place_tile(tile1)

        ri1 = rd.report.process_input('1\n2\n',
                                      tags=['p1:9'],
                                      handle_tpcreator=False,
                                      handle_sscreator=False).report_instance
        ri2 = rd.report.process_input('1\n2\n3\n',
                                      tags=['p1:12'],
                                      handle_tpcreator=False,
                                      handle_sscreator=False).report_instance

        tpcreator.handle_tpcreator(rd.owner_id,
                                   rd.report_id,
                                   ri1,
                                   make_first_master=False)
        sscreator.handle_sscreator(rd.owner_id, rd.report_id, ri1)
        tpcreator.handle_tpcreator(rd.owner_id,
                                   rd.report_id,
                                   ri2,
                                   make_first_master=False)
        sscreator.handle_sscreator(rd.owner_id, rd.report_id, ri2)

        self.assertEqual(3, len(rd.layout().layout_dict))
        self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs()))

        ri3 = rd.report.process_input('1\n2\n3\n',
                                      tags=['p1:13'],
                                      handle_tpcreator=False).report_instance
        tpcreator.handle_tpcreator(rd.owner_id,
                                   rd.report_id,
                                   ri3,
                                   make_first_master=True)

        self.assertEqual(4, len(rd.layout().layout_dict))
        master_tile = rd.get_tile_by_tags(['p1:9'])
        self.assertTrue(master_tile.is_master_tile())
        self.assertEqual(master_tile.tile_id,
                         rd.get_tile_by_tags(['p1:12']).get_master_tile_id())
        self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs()))

        self.assertEqual(['0', '1', '2'], [
            ss.params['filtering_expr']['args'][0]
            for ss in rd.get_tile_by_tags(['p1:12']).series_specs()
        ])
Ejemplo n.º 6
0
    def test_repack_performance(self):
        rd = ReportData('r')

        tile_config = {
            'tags': ['p1:1'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'p1:1',
                    'prefix': 'p1:'
                }],
            }
        }
        tile = Tile.insert(rd.owner_id, rd.report_id, rd.dashboard_id,
                           tile_config)
        place_tile(tile)

        start = time()
        for i in range(1, 201):
            rd.report.process_input('1', tags=['p1:%s' % i])
        print 'Tiles created in %.1f' % ((time() - start) * 1000)

        start = time()
        layouts.repack(rd.owner_id, rd.dashboard_id)
        print 'Single repack in %.1f' % ((time() - start) * 1000)
Ejemplo n.º 7
0
    def test_get_tile_config(self):
        tile_config = {
            'tw_type':
            'Range',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['ip:192.168.1.1'])
            }
        }
        owner_id = uuid.uuid1()
        report_id = report_data('points').report.report_id
        dashboard_id = report_data('points').dashboard_id

        tile = Tile.insert(owner_id, report_id, dashboard_id, tile_config)
        res = tile.get_tile_config()
        self.assertDictContainsSubset(dictwithout(tile_config, 'tile_options'),
                                      dictwithout(res, 'tile_options'))
        self.assertDictContainsSubset(tile_config['tile_options'],
                                      res['tile_options'])
Ejemplo n.º 8
0
    def test_delete(self):
        tile_config = {
            'tw_type':
            'Range',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['ip:192.168.1.1'])
            }
        }
        owner_id = uuid.uuid1()
        report_id = report_data('points').report.report_id
        dashboard_id = report_data('points').dashboard_id
        tile = Tile.insert(owner_id, report_id, dashboard_id, tile_config)
        place_tile(tile)
        self.assertTrue(self._select_tpcreator_rows(tile))
        self.assertTrue(self._select_sscs_rows(tile))

        tile = tile.select(tile.dashboard_id, tile.tile_id)
        detach_tile(tile)
        deleted_tile = tile.select(tile.dashboard_id, tile.tile_id)
        self.assertIsNone(deleted_tile)
Ejemplo n.º 9
0
def _tile_options_of_tpcreated(master_tile, tpcreator_spec, tags):
    partial_new_tile = Tile.insert(
        master_tile.owner_id,
        master_tile.report_id,
        master_tile.dashboard_id,
        skip_db=True,
        tile_config={
            'tw_type': master_tile.tile_options['tw_type'],
            'tags': tags,
            'series_spec_list': master_tile.series_specs(),
            'tile_options': {
                k: v
                for k, v in master_tile.tile_options.items()
                if k not in {'series_configs', 'tags', 'tile_title'}
            }
        })
    new_tile_options = partial_new_tile.tile_options
    if 'tpcreator_data' not in new_tile_options:
        new_tile_options['tpcreator_data'] = {}

    tile_title = master_tile.tile_options.get('tile_title')
    if tile_title:
        postfix = master_tile.tilewidget.generate_tile_title_postfix()
        if postfix:
            tile_title = tile_title.replace(postfix, '').strip()
        new_tile_options['tpcreator_data']['tile_title_base'] = tile_title

    new_tile_options.pop('tpcreator_uispec', None)
    new_tile_options['tpcreator_data']['master_tile_id'] = master_tile.tile_id
    new_tile_options['tpcreator_data'][
        'master_tpcreator_uispec'] = copy.deepcopy(
            master_tile.tile_options['tpcreator_uispec'])
    new_tile_options['tpcreator_data'][
        'master_tpcreator_spec'] = tpcreator_spec
    return new_tile_options
Ejemplo n.º 10
0
    def test_sscs_override_static_name(self):
        tile_config = {
            'tags': ['ip:192.168.1.1'],
            'tw_type': 'Range',
            'series_spec_list': [
                SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                SeriesSpec(2, 0, dict(op='eq', args=['john'])),
            ],
            'tile_options': {
                'seconds_back': 86400,
                'tile_title': 'Points by user'
            }
        }
        tile_config['series_spec_list'][0].params['static_name'] = 'monique_points'
        self.assertEqual('monique_points', tile_config['series_spec_list'][0].name())
        tile_config['tile_options']['sscs'] = tile_config['series_spec_list'][0]

        rd = new_report_data('points')

        tile = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config)
        layouts.place_tile(tile)

        d = [OrderedDict([('user_name', 'robert'), ('is_active', True), ('points', 128)]),
             OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 210)])]
        res = rd.report.process_input(json.dumps(d), tags=tile_config['tags'])
        tile = rd.only_tile_from_layout()
        self.assertEqual(3, len(tile.series_specs()))
        expected_ss = SeriesSpec(2, 0, dict(op='eq', args=['robert']))
        self.assertEqual('robert', expected_ss.name())
        self.assertEqual('robert', tile.series_specs()[-1].name())
Ejemplo n.º 11
0
def main():
    owner_id = uuid.uuid4()
    report = Report.select_or_insert(owner_id, 'simple_report')
    res = report.process_input('1 2 3')
    assert res.report_instance

    owner_dashboards = OwnerDashboards(
        owner_id, insert_if_no_dashboards='Default Dashboard')
    assert owner_dashboards.dashboards

    tile_config = {
        'series_spec_list': [SeriesSpec(0, -1, {
            'op': 'eq',
            'args': ['0']
        })],
    }
    tile = Tile.insert(owner_id, report.report_id,
                       owner_dashboards.dashboards[0].dashboard_id,
                       tile_config)
    assert tile

    assert tile.get_tile_data()

    print 'Successfully created a dashboard with a tile'

    owner_dashboards.dashboards[0].delete()
Ejemplo n.º 12
0
    def test_layout_sorting_complex_tag_names_2(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()
        rep = reports.Report.insert(owner_id, 'r')
        tile_config = {
            'tags': ['server:web.1'],
            'series_spec_list':
            [dataseries.SeriesSpec(0, -1, {
                'op': 'eq',
                'args': '0'
            })],
            'tile_options': {
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['server:web.1'])
            }
        }
        master_tile = Tile.insert(owner_id, rep.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        rep.process_input('1', tags=['server:worker.1'])
        rep.process_input('1', tags=['server:web.2'])

        layout = layouts.Layout.select(owner_id, dashboard_id)
        tiles = sorted(
            layout.tile_dict,
            key=lambda tile:
            (layout.tile_dict[tile]['y'], layout.tile_dict[tile]['x']))
        tags_lists = [tile.tags for tile in tiles]
        self.assertEqual(
            [['server:web.1'], ['server:web.2'], ['server:worker.1']],
            tags_lists)
Ejemplo n.º 13
0
    def test_sscreator_as_mod(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()

        tile_config = {
            'series_spec_list': [
                SeriesSpec(1, 0, dict(op='eq', args=['label1'])),
            ],
            'tile_options': {
                'sscs': SeriesSpec(1, 0, dict(op='eq', args=['label1']))
            }
        }
        r = Report.insert(owner_id, 'r')
        tile = Tile.insert(owner_id, r.report_id, dashboard_id, tile_config)
        layouts.place_tile(tile)
        ri1 = r.process_input('label1 1',
                              handle_sscreator=False).report_instance
        ri2 = r.process_input('label11 11\nlabel12 12',
                              handle_sscreator=False).report_instance
        ri3 = r.process_input('label21 21\nlabel22 22',
                              handle_sscreator=False).report_instance
        layout_rows = c.dao.LayoutDAO.select_layout_by_report_multi(owner_id, r.report_id,
                                                                    [], 'sscs', 100)
        mods = [sscreator.sscreator_mod(ri1, layout_rows[0]),
                sscreator.sscreator_mod(ri2, layout_rows[0]),
                sscreator.sscreator_mod(ri3, layout_rows[0])]
        layouts.apply_mods(mods, owner_id, dashboard_id, None)

        layout = Layout.select(owner_id, dashboard_id)
        tile = layout.tile_dict.keys()[0]
Ejemplo n.º 14
0
    def test_sscs_virtual_column(self):
        owner_id = uuid.uuid1()
        od = dashboards.OwnerDashboards(owner_id)
        dashboard_id = od.dashboards[0].dashboard_id

        r = Report.insert(owner_id, 'r')
        tile_config = {
            'tw_type': 'Single',
            'series_spec_list': [
                SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {}
        }
        tile_config['tile_options']['sscs'] = tile_config['series_spec_list'][
            0]

        tile = Tile.insert(owner_id, r.report_id, dashboard_id, tile_config)
        layouts.place_tile(tile)

        for inp in ['0', '1', '2\n3', '3\n4\n5\n']:
            res = r.process_input(inp)

        tile = Tile.select(
            dashboard_id,
            Layout.select(owner_id, dashboard_id).layout_dict.keys()[0])
        self.assertEqual(3, len(tile.series_specs()))
        return tile, r
Ejemplo n.º 15
0
    def test_single__text_single_drawer(self):
        rd = new_report_data('points', tags=['ip:192.168.1.1'])

        tile_config = {
            'tw_type':
            'Single',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                'drawer_type':
                'TextSingleDrawer'
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])

        tile = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                           tile_config)
        layouts.place_tile(tile)
        self.assertEqual(tile.tile_options['drawer_type'], 'TextSingleDrawer')

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        pr = rd.report.process_input(json.dumps(d),
                                     tags=['ip:192.168.1.1'],
                                     extra_ri_data={'ed': 88})

        tile = rd.only_tile_from_layout()
        data = tile.get_new_tile_data(pr.report_instance.report_instance_id)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual([], data['series_data'][1]['data_points'])

        data = tile.get_new_tile_data(rd.instances[-1].report_instance_id)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual(128, data['series_data'][1]['data_points'][0].value)

        data = tile.get_new_tile_data(rd.instances[-3].report_instance_id)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual(128, data['series_data'][1]['data_points'][0].value)

        data = tile.get_new_tile_data(None)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual(128, data['series_data'][1]['data_points'][0].value)

        return tile
Ejemplo n.º 16
0
    def test_promote_first_as_master_multiple_masters_one_apply_mods_run(self):
        rd = self.test_repack_dont_put_master_first()

        tile_config = {
            'tags': ['q1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'q1:10',
                    'prefix': 'q1:'
                }],
            }
        }
        r2 = Report.insert(rd.owner_id, 'r2')
        master_tile2 = Tile.insert(rd.owner_id, r2.report_id, rd.dashboard_id,
                                   tile_config)
        layouts.place_tile(master_tile2)

        ri1 = r2.process_input('0', tags=['q1:8'],
                               handle_tpcreator=False).report_instance
        ri2 = r2.process_input('0', tags=['q1:12'],
                               handle_tpcreator=False).report_instance
        ri3 = r2.process_input('0', tags=['q1:6'],
                               handle_tpcreator=False).report_instance
        ri4 = rd.report.process_input('0',
                                      tags=['p1:2'],
                                      handle_tpcreator=False).report_instance

        layout_rows_tpcreator = c.dao.LayoutDAO.select_layout_by_report_multi(
            rd.owner_id, rd.report_id, [], 'tpcreator', 100)
        mods = [
            tpcreator.tpcreator_mod(ri1, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri2, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri3, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri4, layout_rows_tpcreator[0]),
            layouts.repack_mod(put_master_first=False),
            layouts.promote_first_as_master_mod(),
            layouts.if_mod(lambda layout_mod: layout_mod.tile_replacement,
                           layouts.repack_mod())
        ]
        layouts.apply_mods(mods, rd.owner_id, rd.dashboard_id, None)

        self.assertEqual([['p1:2'], ['p1:6'], ['p1:8'], ['p1:10'], ['p1:12'],
                          ['q1:6'], ['q1:8'], ['q1:10'], ['q1:12']],
                         [tile.tags for tile in rd.tiles_sorted_by_vo()])

        master1 = rd.get_tile_by_tags(['p1:2'])
        master2 = rd.get_tile_by_tags(['q1:6'])
        self.assertTrue(master1.is_master_tile())
        self.assertTrue(master2.is_master_tile())
        for tile in rd.tiles_sorted_by_vo():
            if tile.tags[0].startswith(
                    'p') and tile.tile_id != master1.tile_id:
                self.assertEqual(master1.tile_id, tile.get_master_tile_id())
            elif tile.tags[0].startswith(
                    'q') and tile.tile_id != master2.tile_id:
                self.assertEqual(master2.tile_id, tile.get_master_tile_id())
Ejemplo n.º 17
0
    def test_range__chart_range_drawer(self):
        rd = new_report_data('points', tags=['ip:192.168.1.1'])

        tile_config = {
            'tw_type':
            'Range',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])

        tile = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                           tile_config)
        layouts.place_tile(tile)
        self.assertEqual(tile.tile_options['drawer_type'], 'ChartRangeDrawer')

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        rd.report.process_input(json.dumps(d),
                                tags=['ip:192.168.1.1'],
                                extra_ri_data={'ed': 88})

        tile = rd.only_tile_from_layout()
        data = tile.get_tile_data()

        self.assertEqual('points (monique, robert3)',
                         data['generated_tile_title'])
        self.assertEqual('[ip:192.168.1.1]',
                         data['generated_tile_title_postfix'])
        self.assertEqual(0, data['extra_options']['y_axis_min'])
        self.assertIsInstance(data['fetched_from_dt'], datetime.datetime)
        self.assertIsInstance(data['fetched_to_dt'], datetime.datetime)
        self.assertEqual({'ed': 88}, data['latest_extra_ri_data'])
        self.assertEqual('points', data['report_name'])
        self.assertEqual(2, len(data['series_data']))
        for sd in data['series_data']:
            self.assertIsInstance(sd['series_id'], uuid.UUID)
            self.assertEqual('points', data['common_header'])
            self.assertTrue(sd['data_points'])
            for dp in sd['data_points']:
                self.assertIsInstance(dp, tilewidgets.DataPoint)
        self.assertEqual(mqeconfig.DEFAULT_COLORS[:2], data['combined_colors'])
        self.assertEqual('points', data['common_header'])

        return tile
Ejemplo n.º 18
0
 def test_tile_options_validation(self):
     rd = report_data('points')
     tile_config = {
         'tags': ['1', '2', '3', '4'],
         'series_spec_list': [],
     }
     self.assertRaises(
         ValueError, lambda: Tile.insert(rd.owner_id, rd.report.report_id,
                                         rd.dashboard_id, tile_config))
Ejemplo n.º 19
0
    def test_sscs_different_tag(self):
        rd, tile = self.test_sscs()

        tile_config = {
            'tags': [],
            'tw_type':
            'Range',
            'series_spec_list': [
                SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                SeriesSpec(2, 0, dict(op='eq', args=['john'])),
            ],
            'tile_options': {
                'seconds_back': 86400,
                'tile_title': 'Points by user'
            }
        }
        tile_config['tile_options']['sscs'] = tile_config['series_spec_list'][
            1]

        tile2 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config)
        layouts.place_tile(tile2)

        d = [
            OrderedDict([('user_name', 'robert'), ('is_active', True),
                         ('points', 128)]),
            OrderedDict([('user_name', 'monique2'), ('is_active', True),
                         ('points', 210)]),
            OrderedDict([('user_name', 'monique3'), ('is_active', True),
                         ('points', 210)]),
            OrderedDict([('user_name', 'monique4'), ('is_active', True),
                         ('points', 210)]),
            OrderedDict([('user_name', 'robert2'), ('is_active', True),
                         ('points', 210)]),
        ]
        res = rd.report.process_input(json.dumps(d))
        tile2 = rd.tile_from_layout(1, 2)
        self.assertEqual(7, len(tile2.series_specs()))
        self.assertEqual(SeriesSpec(2, 0, dict(op='eq', args=['robert2'])),
                         tile2.series_specs()[-1])

        d = [
            OrderedDict([('user_name', 'monique4'), ('is_active', True),
                         ('points', 128)])
        ]
        res = rd.report.process_input(json.dumps(d), tags=['ip:192.168.1.1'])

        tile2 = rd.tile_from_layout(0, 2)
        self.assertEqual(7, len(tile2.series_specs()))

        tile = rd.tile_from_layout(1, 2)
        self.assertEqual(6, len(tile.series_specs()))
        self.assertEqual(SeriesSpec(2, 0, dict(op='eq', args=['monique4'])),
                         tile.series_specs()[-1])
Ejemplo n.º 20
0
 def test_insert_invalid_report(self):
     tile_config = {
         'tags': ['ip:192.168.1.1'],
         'series_spec_list': [],
         'tile_options': {
             'seconds_back': 86400,
             'tile_title': 'Points by user'
         }
     }
     self.assertRaises(ValueError, lambda: \
         Tile.insert(uuid.uuid1(), uuid.uuid1(), uuid.uuid1(), tile_config))
Ejemplo n.º 21
0
def main():
    vars = tutorial.main()
    owner_id = vars['owner_id']
    owner_dashboards = vars['owner_dashboards']
    dashboard = vars['dashboard']

    SECTION('tags')

    cpu_report = Report.select_or_insert(owner_id, 'cpu_usage')
    metrics = [
        ('user', 92.3),
        ('system', 3.4),
        ('io', 4.4),
    ]
    cpu_report.process_input(json.dumps(metrics),
                             tags=['ip:192.168.1.18', 'warning'])

    tile_config_1 = {
        'tags': ['ip:192.168.1.18'],
        'series_spec_list': [
            SeriesSpec(1, 0, {
                'op': 'eq',
                'args': ['user']
            }),
        ],
    }
    tile_1 = Tile.insert(owner_id, cpu_report.report_id,
                         dashboard.dashboard_id, tile_config_1)

    tile_config_2 = {
        'tags': ['ip:192.168.1.18', 'warning'],
        'series_spec_list': [
            SeriesSpec(1, 0, {
                'op': 'eq',
                'args': ['user']
            }),
        ],
    }
    tile_2 = Tile.insert(owner_id, cpu_report.report_id,
                         dashboard.dashboard_id, tile_config_2)
Ejemplo n.º 22
0
    def test_layout_sorting(self):
        rd = new_report_data('points', ['p1:10'])
        tile_config = {
            'tw_type':
            'Range',
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'm0',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])

        master_tile = Tile.insert(rd.owner_id, rd.report.report_id,
                                  rd.dashboard_id, tile_config)
        layouts.place_tile(master_tile)

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        nums = [30, 20, 12, 11, 40, 98]
        for num in nums:
            rd.report.process_input(json.dumps(d), tags=['p1:%s' % num])

        ld = rd.layout()
        self.assertEqual(len(nums) + 1, len(ld.layout_dict.keys()))
        self.assertEqual(
            len(nums) + 1, len(ld.layout_props['by_tile_id'].keys()))

        layout_items = sorted(ld.layout_dict.items(),
                              key=lambda (tile_id, vo): (vo['y'], vo['x']))

        layout_tags = [
            ld.layout_props['by_tile_id'][tile_id]['tags'][0]
            for (tile_id, vo) in layout_items
        ]
        expected_tags = ['p1:10'] + sorted(['p1:%s' % num for num in nums])
        self.assertEqual(set(expected_tags), set(layout_tags))
        self.assertEqual(expected_tags, layout_tags)
Ejemplo n.º 23
0
    def test_deleting_layout_by_report_row(self):
        owner_id = uuid.uuid1()
        dashboard_id_1 = uuid.uuid1()
        r = reports.Report.insert(owner_id, 'r')
        tile_config = {
            'tw_type':
            'Single',
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {}
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                ['p1:10'])

        master_tile_1 = Tile.insert(owner_id, r.report_id, dashboard_id_1,
                                    tile_config)
        layouts.place_tile(master_tile_1)

        r.process_input('1', tags=['p1:11'])

        self.assertEqual(
            2,
            len(
                Layout.select(master_tile_1.owner_id,
                              master_tile_1.dashboard_id).layout_dict))

        rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            master_tile_1.owner_id, master_tile_1.report_id, [], 'tpcreator',
            100)
        self.assertTrue(rows)

        layouts.detach_tile(master_tile_1)

        r.process_input('1', tags=['p1:12'])

        self.assertEqual(
            1,
            len(
                Layout.select(master_tile_1.owner_id,
                              master_tile_1.dashboard_id).layout_dict))

        rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            master_tile_1.owner_id, master_tile_1.report_id, [], 'tpcreator',
            100)
        self.assertFalse(rows)
Ejemplo n.º 24
0
    def test_layout_sorting_complex_tag_names(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()
        rep = reports.Report.insert(owner_id, 'r')
        tile_config = {
            'tags': ['server0:0', 'service1:search.1'],
            'series_spec_list':
            [dataseries.SeriesSpec(0, -1, {
                'op': 'eq',
                'args': '0'
            })],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'server0:0',
                    'prefix': 'server0:0'
                }, {
                    'tag': 'service1:search.1',
                    'prefix': 'service1:'
                }],
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])
        master_tile = Tile.insert(owner_id, rep.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        for i in range(8, 13):
            rep.process_input(str(i),
                              tags=['server0:0',
                                    'service1:search.%d' % i])

        layout = layouts.Layout.select(owner_id, dashboard_id)
        tiles = sorted(
            layout.tile_dict,
            key=lambda tile:
            (layout.tile_dict[tile]['y'], layout.tile_dict[tile]['x']))
        tags_lists = [tile.tags for tile in tiles]
        self.assertEqual([['server0:0', 'service1:search.1'],
                          ['server0:0', 'service1:search.8'],
                          ['server0:0', 'service1:search.9'],
                          ['server0:0', 'service1:search.10'],
                          ['server0:0', 'service1:search.11'],
                          ['server0:0', 'service1:search.12']], tags_lists)
Ejemplo n.º 25
0
 def test_insert_no_tags(self):
     owner_id = uuid.uuid1()
     report_id = report_data('points').report.report_id
     dashboard_id = report_data('points').dashboard_id
     tile_config = {
         'tw_type':
         'Range',
         'series_spec_list': [
             dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
             dataseries.SeriesSpec(2, 0, dict(op='eq', args=['john'])),
         ],
         'tile_options': {
             'seconds_back': 86400,
             'tile_title': 'Points by user'
         }
     }
     tile = Tile.insert(owner_id, report_id, dashboard_id, tile_config)
     self.assertEqual(tile.tile_options['tags'], [])
Ejemplo n.º 26
0
    def test_tile_options_default_tw(self):
        rd = report_data('points')
        tile_config = {
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [],
        }
        tile = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                           tile_config)
        self.assertEqual('Range', tile.tile_options['tw_type'])
        self.assertIsInstance(tile.tilewidget, tilewidgets.TilewidgetForRange)

        tile_config['tw_type'] = 'Single'
        tile = tile.insert_similar(tile_config)
        self.assertEqual('Single', tile.tile_options['tw_type'])

        del tile_config['tw_type']
        tile = tile.insert_similar(tile_config)
        self.assertEqual('Range', tile.tile_options['tw_type'])
Ejemplo n.º 27
0
    def test_tpcreator_as_mod_performance(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()
        tile_config = {
            'tags': ['str:sample_string'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'str:sample_string',
                    'prefix': 'str:'
                }],
            }
        }
        r = reports.Report.insert(owner_id, 'r')
        master_tile = Tile.insert(owner_id, r.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        strs = [random_string() for _ in xrange(199)]
        mods = []
        layout_rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            owner_id, r.report_id, [], 'tpcreator', 100)
        start = time()
        for str in strs:
            res = r.process_input('1',
                                  tags=['str:%s' % str],
                                  handle_tpcreator=False)
            mods.append(
                tpcreator.tpcreator_mod(res.report_instance, layout_rows[0],
                                        200))
        print 'Creating report instances took %.1f' % ((time() - start) * 1000)

        start = time()
        layouts.apply_mods(mods, owner_id, dashboard_id, None)
        print 'Applying tpcreator_mods took %.1f' % ((time() - start) * 1000)

        layout = Layout.select(owner_id, dashboard_id)
        self.assertEqual(200, len(layout.layout_dict))
        tags_set = {tile.tags[0].split(':')[1] for tile in layout.tile_dict}
        self.assertEqual(200, len(tags_set))
        self.assertEqual(tags_set, set(strs + ['sample_string']))
Ejemplo n.º 28
0
    def test_no_repack(self):
        tile_config = {
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'p1:10',
                    'prefix': 'p1:'
                }],
            }
        }
        rd = ReportData('r')
        master_tile = Tile.insert(rd.owner_id, rd.report_id, rd.dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        ri1 = rd.report.process_input('0',
                                      tags=['p1:8'],
                                      handle_tpcreator=False).report_instance
        ri2 = rd.report.process_input('0',
                                      tags=['p1:12'],
                                      handle_tpcreator=False).report_instance
        ri3 = rd.report.process_input('0',
                                      tags=['p1:6'],
                                      handle_tpcreator=False).report_instance

        layout_rows_tpcreator = c.dao.LayoutDAO.select_layout_by_report_multi(
            rd.owner_id, rd.report_id, [], 'tpcreator', 100)
        mods = [
            tpcreator.tpcreator_mod(ri1, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri2, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri3, layout_rows_tpcreator[0]),
        ]
        layouts.apply_mods(mods, rd.owner_id, rd.dashboard_id, None)

        self.assertEqual([['p1:10'], ['p1:8'], ['p1:12'], ['p1:6']],
                         [tile.tags for tile in rd.tiles_sorted_by_vo()])

        return rd
Ejemplo n.º 29
0
    def test_tpcreator_as_mod(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()

        tile_config = {
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'p1:10',
                    'prefix': 'p1:'
                }],
            }
        }
        r = reports.Report.insert(owner_id, 'r')
        master_tile = Tile.insert(owner_id, r.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        ri1 = r.process_input('0', tags=['p1:11'],
                              handle_tpcreator=False).report_instance
        ri2 = r.process_input('0', tags=['p1:12'],
                              handle_tpcreator=False).report_instance
        ri3 = r.process_input('0', tags=['p1:12'],
                              handle_tpcreator=False).report_instance
        layout_rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            owner_id, r.report_id, [], 'tpcreator', 100)
        mods = [
            tpcreator.tpcreator_mod(ri1, layout_rows[0]),
            tpcreator.tpcreator_mod(ri2, layout_rows[0]),
            tpcreator.tpcreator_mod(ri3, layout_rows[0])
        ]
        layouts.apply_mods(mods, owner_id, dashboard_id, None)

        layout = Layout.select(owner_id, dashboard_id)
        self.assertEqual(3, len(layout.layout_dict))
        self.assertEqual([['p1:10'], ['p1:11'], ['p1:12']],
                         sorted(tile.tags for tile in layout.tile_dict))
Ejemplo n.º 30
0
    def test_expire_tiles_without_data_losing_sscreated(self):
        rd = ReportData('r')

        ss = dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0']))
        tile_config1 = {
            'series_spec_list': [ss],
            'tags': ['p1:10'],
            'tile_options': {
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['p1:10']),
                'sscs': ss
            }
        }

        tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config1)
        place_tile(tile1)

        #rd.report.process_input('1', tags=['p1:10'])

        rd.report.process_input('1\n2\n', tags=['p1:11'])
        rd.report.process_input('1\n2\n3\n', tags=['p1:12'])

        self.assertEqual(3, len(rd.layout().layout_dict))
        self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs()))

        tile1_created_ago = datetime.datetime.utcnow(
        ) - util.datetime_from_uuid1(tile1.tile_id)
        tiles.expire_tiles_without_data(
            rd.layout().tile_dict.keys(),
            tile1_created_ago.total_seconds() - 0.00001,
            rd.layout().layout_id)
        self.assertEqual(2, len(rd.layout().layout_dict))
        self.assertTrue(rd.layout_has_tags([['p1:11'], ['p1:12']]))
        master_tile = rd.get_tile_by_tags(['p1:11'])
        self.assertTrue(master_tile.is_master_tile())
        self.assertEqual(master_tile.tile_id,
                         rd.get_tile_by_tags(['p1:12']).get_master_tile_id())
        self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs()))