/** * Add {@link List} of {@link Tag}s to a {@link Properties} with key {@link #METRICS_STATE_CUSTOM_TAGS}. * <p> * Also see {@link #addCustomTagToState(State, Tag)} , {@link #addCustomTagToProperties(Properties, Tag)} * </p> * * <p> * The {@link Properties} passed can be used to build a {@link State}. * {@link org.apache.gobblin.metrics.Tag}s under this key can later be parsed using the method {@link #getCustomTagsFromState}. * </p> * * @param properties {@link Properties} to add the tag to. * @param tags list of {@link Tag}s to add. */ public static void addCustomTagsToProperties(Properties properties, List<Tag<?>> tags) { for (Tag<?> tag : tags) { addCustomTagToProperties(properties, tag); } }
@Test public void testCustomTags() { Properties testProperties = new Properties(); Tag<String> expectedPropertyTag = new Tag<>("key1", "value1"); GobblinMetrics.addCustomTagToProperties(testProperties, expectedPropertyTag); State testState = new State(testProperties); List<Tag<?>> tags = GobblinMetrics.getCustomTagsFromState(testState); Assert.assertEquals(Iterables.getFirst(tags, null), expectedPropertyTag); Tag<String> expectedStateTag = new Tag<>("key2", "value2"); GobblinMetrics.addCustomTagToState(testState, expectedStateTag); tags = GobblinMetrics.getCustomTagsFromState(testState); Assert.assertTrue(tags.containsAll(ImmutableList.of(expectedPropertyTag, expectedStateTag))); }
/** * Add {@link List} of {@link Tag}s to a {@link Properties} with key {@link #METRICS_STATE_CUSTOM_TAGS}. * <p> * Also see {@link #addCustomTagToState(State, Tag)} , {@link #addCustomTagToProperties(Properties, Tag)} * </p> * * <p> * The {@link Properties} passed can be used to build a {@link State}. * {@link org.apache.gobblin.metrics.Tag}s under this key can later be parsed using the method {@link #getCustomTagsFromState}. * </p> * * @param properties {@link Properties} to add the tag to. * @param tags list of {@link Tag}s to add. */ public static void addCustomTagsToProperties(Properties properties, List<Tag<?>> tags) { for (Tag<?> tag : tags) { addCustomTagToProperties(properties, tag); } }