/** * Build the {@link EventSubmitter} for this class. */ private EventSubmitter buildEventSubmitter(List<? extends Tag<?>> tags) { return new EventSubmitter.Builder(this.runtimeMetricContext, "gobblin.runtime") .addMetadata(Tag.toMap(Tag.tagValuesToString(tags))).build(); }
@Test public void testSubTaggedMetricContext() throws Exception { MetricContextFactory<SimpleScopeType> factory = new MetricContextFactory<>(); Config config = ConfigFactory.parseMap(ImmutableMap.of( BrokerConfigurationKeyGenerator.generateKey(factory, null, null, MetricContextFactory.TAG_KEY + ".tag1"), "value1" )); SharedResourcesBroker<SimpleScopeType> rootBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, SimpleScopeType.GLOBAL.defaultScopeInstance()); MetricContext metricContext = rootBroker.getSharedResource(factory, new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag2", "value2"))); Map<String, String> tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(metricContext.getTags())); Assert.assertEquals(metricContext.getName(), "myMetricContext"); Assert.assertEquals(tagMap.get("tag1"), "value1"); Assert.assertEquals(tagMap.get("tag2"), "value2"); MetricContext metricContext2 = rootBroker.getSharedResource(factory, new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag2", "value2"))); Assert.assertEquals(metricContext, metricContext2); MetricContext metricContext3 = rootBroker.getSharedResource(factory, new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag3", "value3"))); Assert.assertNotEquals(metricContext, metricContext3); MetricContext parent = rootBroker.getSharedResource(factory, new MetricContextKey()); tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(parent.getTags())); Assert.assertEquals(metricContext.getParent().get(), parent); Assert.assertEquals(tagMap.get("tag1"), "value1"); Assert.assertFalse(tagMap.containsKey("tag2")); }
@Test public void test() throws Exception { MetricContextFactory<SimpleScopeType> factory = new MetricContextFactory<>(); Config config = ConfigFactory.parseMap(ImmutableMap.of( BrokerConfigurationKeyGenerator.generateKey(factory, null, null, MetricContextFactory.TAG_KEY + ".tag1"), "value1", BrokerConfigurationKeyGenerator.generateKey(factory, null, SimpleScopeType.GLOBAL, MetricContextFactory.TAG_KEY + ".tag2"), "value2", BrokerConfigurationKeyGenerator.generateKey(factory, null, SimpleScopeType.LOCAL, MetricContextFactory.TAG_KEY + ".tag3"), "value3" )); SharedResourcesBroker<SimpleScopeType> rootBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, SimpleScopeType.GLOBAL.defaultScopeInstance()); SharedResourcesBroker<SimpleScopeType> localBroker = rootBroker.newSubscopedBuilder(SimpleScopeType.LOCAL.defaultScopeInstance()).build(); MetricContext localContext = localBroker.getSharedResource(factory, new MetricContextKey()); Map<String, String> tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(localContext.getTags())); Assert.assertEquals(tagMap.get("tag1"), "value1"); Assert.assertEquals(tagMap.get("tag2"), "value2"); Assert.assertEquals(tagMap.get("tag3"), "value3"); MetricContext globalContext = rootBroker.getSharedResource(factory, new MetricContextKey()); Assert.assertEquals(localContext.getParent().get(), globalContext); tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(globalContext.getTags())); Assert.assertEquals(tagMap.get("tag1"), "value1"); Assert.assertEquals(tagMap.get("tag2"), "value2"); Assert.assertFalse(tagMap.containsKey("tag3")); }
/** * Build the {@link EventSubmitter} for this class. */ private EventSubmitter buildEventSubmitter(List<? extends Tag<?>> tags) { return new EventSubmitter.Builder(this.runtimeMetricContext, "gobblin.runtime") .addMetadata(Tag.toMap(Tag.tagValuesToString(tags))).build(); }