@Override public List<Tag<?>> getTags() { ImmutableList.Builder<Tag<?>> builder = ImmutableList.builder(); for (Map.Entry<String, Object> entry : this.tags.entrySet()) { builder.add(new Tag<Object>(entry.getKey(), entry.getValue())); } return builder.build(); }
private static List<Tag<?>> tagsForContainer(State containerState, String applicationName, String taskRunnerId) { ImmutableList.Builder<Tag<?>> tags = new ImmutableList.Builder<>(); tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_NAME, applicationName)); tags.add(new Tag<>(GobblinClusterMetricTagNames.TASK_RUNNER_ID, taskRunnerId)); tags.addAll(getCustomTagsFromState(containerState)); return tags.build(); } }
/** * @return Tags to be applied to the {@link MetricContext} in this object. Called once in {@link #startUp()}. * Subclasses should override this method to add additional tags. */ protected List<Tag<?>> getTagsForMetrics() { List<Tag<?>> tags = Lists.newArrayList(); tags.add(new Tag<>(RuntimeMetrics.TOPIC, this.topic)); tags.add(new Tag<>(RuntimeMetrics.GROUP_ID, this.consumerConfig.groupId())); return tags; }
/** * Creates a {@link List} of {@link Tag}s for a {@link Fork} instance. The {@link Tag}s are purely based on the * index and the branch name. */ private static List<Tag<?>> getForkMetricsTags(State state, int index) { return ImmutableList.<Tag<?>>of(new Tag<>(FORK_METRICS_BRANCH_NAME_KEY, getForkMetricsId(state, index))); }
@Override public List<Tag<?>> generateTags(State state) { ImmutableList.Builder<Tag<?>> tags = ImmutableList.<Tag<?>> builder().addAll(super.generateTags(state)); tags.add(new Tag<>(PARTITION, this.partition)); for (Schema.Field field : this.partition.getSchema().getFields()) { tags.add(new Tag<>(field.name(), this.partition.get(field.name()))); } return tags.build(); } }
protected static List<Tag<?>> tagsForTask(TaskState taskState) { List<Tag<?>> tags = Lists.newArrayList(); tags.add(new Tag<>(TaskEvent.METADATA_TASK_ID, taskState.getTaskId())); tags.add(new Tag<>(TaskEvent.METADATA_TASK_ATTEMPT_ID, taskState.getTaskAttemptId().or(""))); tags.add(new Tag<>(ConfigurationKeys.DATASET_URN_KEY, taskState.getProp(ConfigurationKeys.DATASET_URN_KEY, ConfigurationKeys.DEFAULT_DATASET_URN))); tags.addAll(getCustomTagsFromState(taskState)); return tags; }
private GobblinMetrics buildGobblinMetrics() { // Create tags list ImmutableList.Builder<Tag<?>> tags = new ImmutableList.Builder<>(); tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_ID, this.applicationId)); tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_NAME, this.applicationName)); // Intialize Gobblin metrics and start reporters GobblinMetrics gobblinMetrics = GobblinMetrics.get(this.applicationId, null, tags.build()); gobblinMetrics.startMetricReporting(ConfigUtils.configToProperties(config)); return gobblinMetrics; }
private static List<Tag<?>> tagsForJob(JobState jobState) { List<Tag<?>> tags = Lists.newArrayList(); tags.add(new Tag<>(JobEvent.METADATA_JOB_NAME, jobState.getJobName() == null ? "" : jobState.getJobName())); tags.add(new Tag<>(JobEvent.METADATA_JOB_ID, jobState.getJobId())); tags.addAll(getCustomTagsFromState(jobState)); return tags; }
@Override public List<Tag<?>> generateTags(State state) { List<Tag<?>> tags = super.generateTags(state); tags.add(new Tag<>("kafkaTopic", KafkaUtils.getTopicName(state))); return tags; }
@Override protected List<Tag<?>> getTagsForMetrics() { List<Tag<?>> tags = super.getTagsForMetrics(); tags.add(new Tag<>(RuntimeMetrics.SCHEMA, this.schema.getName())); return tags; }
public ReporterExampleBase(ContextAwareScheduledReporter.Builder reporterBuilder, int tasks, long totalRecords) { this.executor = Executors.newFixedThreadPool(10); this.context = MetricContext.builder("Job") .addTag(new Tag<String>(JobEvent.METADATA_JOB_NAME, "ExampleJob")) .addTag(new Tag<String>(JobEvent.METADATA_JOB_ID, JOB_NAME + "_" + System.currentTimeMillis())) .build(); this.reporterBuilder = reporterBuilder; this.tasks = tasks; this.totalRecords = totalRecords; }
/** * Converts a wildcard {@link Tag} to a {@link String} {@link Tag}. This method uses the {@link Object#toString()} * method to convert the wildcard type to a {@link String}. * * @param tag a {@link Tag} that should be converted to a {@link Tag} with value of type {@link String} * * @return a {@link Tag} with a {@link String} value */ public static Tag<String> tagValueToString(Tag<?> tag) { return new Tag<>(tag.getKey(), tag.getValue().toString()); }
@Override public List<Tag<?>> generateTags(State state) { List<Tag<?>> tags = super.generateTags(state); tags.add(new Tag<>("kafkaTopic", state.getProp(KafkaSimpleStreamingSource.TOPIC_WHITELIST))); return tags; }
private void switchMetricContextToCurrentPartition() { if (this.currentPartitionIdx >= this.partitions.size()) { return; } int currentPartitionId = this.getCurrentPartition().getId(); switchMetricContext(Lists.<Tag<?>> newArrayList(new Tag<>("kafka_partition", currentPartitionId))); }
public MetricContext getDefaultMetricContext() { org.apache.gobblin.configuration.State fakeState = new org.apache.gobblin.configuration.State(getSysConfig().getConfigAsProperties()); List<Tag<?>> tags = new ArrayList<>(); tags.add(new Tag<>(StandardMetrics.INSTANCE_NAME_TAG, getInstanceName())); MetricContext res = Instrumented.getMetricContext(fakeState, StandardGobblinInstanceDriver.class, tags); return res; }
private void addTask(int taskIndex, CountDownLatch countDownLatch) { // Build the context of this task, which is a child of the job's context. // Tags of the job (parent) context will be inherited automatically. MetricContext taskContext = this.context.childBuilder("Task" + taskIndex) .addTag(new Tag<String>(TASK_ID_KEY, TASK_ID_PREFIX + taskIndex)) .build(); Task task = new Task(taskContext, taskIndex, this.totalRecords, countDownLatch); this.executor.execute(task); }
@Test public void testTags() { Tag<String> jobIdTag = new Tag<String>(JOB_ID_KEY, JOB_ID); Assert.assertEquals(jobIdTag.getKey(), JOB_ID_KEY); Assert.assertEquals(jobIdTag.getValue(), JOB_ID); Tag<Integer> projectVersionTag = new Tag<Integer>(PROJECT_VERSION_KEY, PROJECT_VERSION); Assert.assertEquals(projectVersionTag.getKey(), PROJECT_VERSION_KEY); Assert.assertEquals(projectVersionTag.getValue().intValue(), PROJECT_VERSION); } }
@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))); }
@BeforeClass public void setUp() { String contextName = CONTEXT_NAME + "_" + UUID.randomUUID().toString(); this.context = MetricContext.builder(contextName) .addTag(new Tag<String>(JOB_ID_KEY, JOB_ID_PREFIX + 0)) .build(); Assert.assertEquals(this.context.getName(), contextName); Assert.assertTrue(this.context.getParent().isPresent()); Assert.assertEquals(this.context.getParent().get(), RootMetricContext.get()); Assert.assertEquals(this.context.getTags().size(), 3); // uuid and name tag gets added automatically Assert.assertEquals(this.context.getTags().get(0).getKey(), JOB_ID_KEY); Assert.assertEquals(this.context.getTags().get(0).getValue(), JOB_ID_PREFIX + 0); // Second tag should be uuid Assert.assertTrue(this.context.getTags().get(1).getValue().toString() .matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")); }