/** * Add a {@link Tag} to a {@link Properties} with key {@link #METRICS_STATE_CUSTOM_TAGS}. * Also see {@link #addCustomTagToState(State, Tag)} * * <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 tag {@link Tag} to add. */ public static void addCustomTagToProperties(Properties properties, Tag<?> tag) { // Build a state wrapper to add custom tag to property State state = new State(properties); addCustomTagToState(state, tag); }
/** * Add a list of partitions of the same topic to a {@link WorkUnit}. */ private static void populateMultiPartitionWorkUnit(List<KafkaPartition> partitions, WorkUnit workUnit) { Preconditions.checkArgument(!partitions.isEmpty(), "There should be at least one partition"); GobblinMetrics.addCustomTagToState(workUnit, new Tag<>("kafkaTopic", partitions.get(0).getTopicName())); for (int i = 0; i < partitions.size(); i++) { workUnit.setProp(KafkaUtils.getPartitionPropName(KafkaSource.PARTITION_ID, i), partitions.get(i).getId()); workUnit.setProp(KafkaUtils.getPartitionPropName(KafkaSource.LEADER_ID, i), partitions.get(i).getLeader().getId()); workUnit.setProp(KafkaUtils.getPartitionPropName(KafkaSource.LEADER_HOSTANDPORT, i), partitions.get(i).getLeader().getHostAndPort()); } }
GobblinMetrics.addCustomTagToState(this.jobContext.getJobState(), metadataTags);
@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))); }
serializeCopyEntity(workUnit, copyEntity); serializeCopyableDataset(workUnit, metadata); GobblinMetrics.addCustomTagToState(workUnit, new Tag<>(CopyEventSubmitterHelper.DATASET_ROOT_METADATA_NAME, this.copyableDataset.datasetURN())); workUnit.setProp(ConfigurationKeys.DATASET_URN_KEY, datasetAndPartition.toString());
/** * Add a {@link Tag} to a {@link Properties} with key {@link #METRICS_STATE_CUSTOM_TAGS}. * Also see {@link #addCustomTagToState(State, Tag)} * * <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 tag {@link Tag} to add. */ public static void addCustomTagToProperties(Properties properties, Tag<?> tag) { // Build a state wrapper to add custom tag to property State state = new State(properties); addCustomTagToState(state, tag); }
/** * Add a list of partitions of the same topic to a {@link WorkUnit}. */ private static void populateMultiPartitionWorkUnit(List<KafkaPartition> partitions, WorkUnit workUnit) { Preconditions.checkArgument(!partitions.isEmpty(), "There should be at least one partition"); GobblinMetrics.addCustomTagToState(workUnit, new Tag<>("kafkaTopic", partitions.get(0).getTopicName())); for (int i = 0; i < partitions.size(); i++) { workUnit.setProp(KafkaUtils.getPartitionPropName(KafkaSource.PARTITION_ID, i), partitions.get(i).getId()); workUnit.setProp(KafkaUtils.getPartitionPropName(KafkaSource.LEADER_ID, i), partitions.get(i).getLeader().getId()); workUnit.setProp(KafkaUtils.getPartitionPropName(KafkaSource.LEADER_HOSTANDPORT, i), partitions.get(i).getLeader().getHostAndPort()); } }
GobblinMetrics.addCustomTagToState(this.jobContext.getJobState(), metadataTags);
serializeCopyEntity(workUnit, copyEntity); serializeCopyableDataset(workUnit, metadata); GobblinMetrics.addCustomTagToState(workUnit, new Tag<>(CopyEventSubmitterHelper.DATASET_ROOT_METADATA_NAME, this.copyableDataset.datasetURN())); workUnit.setProp(ConfigurationKeys.DATASET_URN_KEY, datasetAndPartition.toString());