def mk_metric_config_data(**overrides): return utils.add_dicts({ 'target': 'a.last', 'bucket_size': '1h', 'null_filter': 'zeroize', 'metadata': {'name': 'max of a'} }, overrides)
def mk_widget_config(self, **overrides): return WidgetConfig(utils.add_dicts({ 'type': 'diamondash.widgets.widget.Widget', 'name': 'toy', 'title': 'Toy', 'width': 2 }, overrides))
def mk_config_data(**overrides): return utils.add_dicts({ 'name': 'test-histogram', 'target': 'some.target', 'time_range': '1d', 'backend': {'type': 'diamondash.tests.utils.ToyBackend'} }, overrides)
def test_add_dicts(self): original = {'a': 1} defaults = {'a': 0, 'b': 2} self.assertEqual( utils.add_dicts(defaults, original), {'a': 1, 'b': 2}) self.assertEqual(original, {'a': 1}) self.assertEqual(defaults, {'a': 0, 'b': 2}) original = {'a': 1} defaults1 = {'a': 0, 'b': 2} defaults2 = {'b': 3, 'c': 4} self.assertEqual( utils.add_dicts(defaults1, defaults2, original), {'a': 1, 'b': 3, 'c': 4}) self.assertEqual(original, {'a': 1}) self.assertEqual(defaults1, {'a': 0, 'b': 2}) self.assertEqual(defaults2, {'b': 3, 'c': 4})
def mk_config_data(**overrides): return utils.add_dicts({ 'name': 'some-widget', 'target': 'some.target', 'title': 'Some LValue Widget', 'width': 2, 'time_range': '5s', 'backend': {'type': 'diamondash.tests.utils.ToyBackend'} }, overrides)
def parse_widget(self, config): type_cls = utils.load_class_by_string(config['type']) if issubclass(type_cls, DynamicWidget): config['backend'] = utils.add_dicts( self.backend_dict, config.get('backend', {})) config_cls = Config.for_type(config['type']) return config_cls(config)
def mk_config_data(**overrides): return utils.add_dicts({ 'name': 'test-chart-widget', 'graphite_url': 'fake_graphite_url', 'metrics': [ {'name': 'random sum', 'target': 'vumi.random.count.sum'}, {'name': 'random avg', 'target': 'vumi.random.timer.avg'}], 'time_range': '1d', 'null_filter': 'zeroize', 'backend': {'type': 'diamondash.tests.utils.ToyBackend'} }, overrides)
def mk_dashboard_config_data(**overrides): return utils.add_dicts({ 'name': 'Some Dashboard', 'request_interval': '2s', 'share_id': 'some-share-id', 'widgets': [{ 'name': 'Widget 1', 'type': 'diamondash.tests.utils.ToyDynamicWidget', }, { 'name': 'Widget 2', 'type': 'diamondash.widgets.widget.Widget', }], }, overrides)
def mk_server_config_data(**overrides): return utils.add_dicts({ 'backend': { 'type': 'diamondash.tests.utils.ToyBackend', 'url': 'http://127.0.0.1:3000', }, 'dashboards': [ mk_dashboard_config_data( name='Dashboard 1', share_id='dashboard-1-share-id'), mk_dashboard_config_data( name='Dashboard 2', share_id='dashboard-2-share-id')] }, overrides)
def parse(cls, config): if 'url' not in config: raise ConfigError("GraphiteBackend needs a 'url' config field.") metric_underrides = dict( (k, config.pop(k)) for k in cls.METRIC_UNDERRIDES if k in config) config['metrics'] = [ utils.add_dicts(metric_underrides, m) for m in config['metrics']] config['metrics'] = [ GraphiteMetricConfig(m) for m in config['metrics']] return config
def mk_backend_config_data(**overrides): return utils.add_dicts({ 'null_filter': 'zeroize', 'bucket_size': '5m', 'time_alignment': 'round', 'url': 'http://some-graphite-url.moc:8080/', 'metrics': [{ 'target': 'a.last', 'null_filter': 'zeroize', 'metadata': {'name': 'max of a'} }, { 'target': 'b.sum', 'null_filter': 'skip', 'metadata': {'name': 'sum of b'} }] }, overrides)
def mk_config_data(**overrides): return utils.add_dicts({ 'name': 'Some Dashboard', 'poll_interval': '2s', 'share_id': 'some-dashboard-share-id', 'widgets': [ { 'name': 'widget1', 'type': 'diamondash.widgets.widget.Widget', }, 'new_row', { 'name': 'widget2', 'type': 'diamondash.tests.utils.ToyDynamicWidget', } ], 'backend': { 'type': 'diamondash.tests.utils.ToyBackend', 'url': 'http://127.0.0.1:3000', } }, overrides)
def _apply_dashboard_defaults(cls, config, dashboard_config): return utils.add_dicts({ 'backend': config['backend'], 'poll_interval': config['poll_interval'], }, dashboard_config)
def from_file(cls, filename, **defaults): items = utils.add_dicts(defaults, yaml.safe_load(open(filename))) return cls(items)
def _parse(cls, items): items = utils.add_dicts(cls.DEFAULTS, items) return cls.parse(items)
def mk_metric_config_data(**overrides): return utils.add_dicts({ 'target': 'a.last', }, overrides)