/** * @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; }
/** * Get additional {@link Tag}s required for any type of reporting. */ private List<? extends Tag<?>> getMetadataTags(String applicationName, String applicationId) { return Tag.fromMap( new ImmutableMap.Builder<String, Object>().put(GobblinClusterMetricTagNames.APPLICATION_NAME, applicationName) .put(GobblinClusterMetricTagNames.APPLICATION_ID, applicationId).build()); }
/** * 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()); }
@Nullable @Override public Tag<String> apply(Tag<?> input) { return input == null ? null : Tag.tagValueToString(input); } });
/** * Parse custom {@link gobblin.metrics.Tag}s from property {@link #METRICS_STATE_CUSTOM_TAGS} * in the input {@link gobblin.configuration.State}. * @param state {@link gobblin.configuration.State} possibly containing custom tags. * @return List of {@link gobblin.metrics.Tag} parsed from input. */ public static List<Tag<?>> getCustomTagsFromState(State state) { List<Tag<?>> tags = Lists.newArrayList(); for (String tagKeyValue : state.getPropAsList(METRICS_STATE_CUSTOM_TAGS, "")) { Tag<?> tag = Tag.fromString(tagKeyValue); if (tag != null) { tags.add(tag); } } return tags; }
@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(); }
/** * Takes a {@link List} of {@link Tag}s and returns a new {@link List} with the original {@link Tag}s as well as any * additional {@link Tag}s returned by {@link ClusterNameTags#getClusterNameTags()}. * * @see ClusterNameTags */ private static List<Tag<?>> addClusterNameTags(List<? extends Tag<?>> tags) { return ImmutableList.<Tag<?>>builder().addAll(tags).addAll(Tag.fromMap(ClusterNameTags.getClusterNameTags())) .build(); }
/** * Converts a {@link List} of {@link Tag}s to a {@link Map} of key, value pairs. * * @param tags a {@link List} of {@link Tag}s that should be converted to key, value pairs * * @return a {@link Map} of key, value pairs */ public static <T> Map<? extends String, T> toMap(List<Tag<T>> tags) { ImmutableMap.Builder<String, T> tagsMapBuilder = ImmutableMap.builder(); for (Tag<T> tag : tags) { tagsMapBuilder.put(tag.getKey(), tag.getValue()); } return tagsMapBuilder.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(); } }
private Compactor getCompactor(CompactorFactory compactorFactory, Optional<CompactorListener> compactorListener) { try { return compactorFactory .createCompactor(this.properties, Tag.fromMap(AzkabanTags.getAzkabanTags()), compactorListener); } catch (CompactorCreationException e) { throw new RuntimeException("Unable to create compactor", e); } }
/** * Converts a {@link Map} of key, value pairs to a {@link List} of {@link Tag}s. Each key, value pair will be used to * create a new {@link Tag}. * * @param tagsMap a {@link Map} of key, value pairs that should be converted into {@link Tag}s * * @return a {@link List} of {@link Tag}s */ public static <T> List<Tag<T>> fromMap(Map<? extends String, T> tagsMap) { ImmutableList.Builder<Tag<T>> tagsBuilder = ImmutableList.builder(); for (Map.Entry<? extends String, T> entry : tagsMap.entrySet()) { tagsBuilder.add(new Tag<>(entry)); } return tagsBuilder.build(); }
public AzkabanGobblinDaemon(String jobId, Properties props) throws Exception { super(jobId, LOG); List<Tag<?>> tags = Lists.newArrayList(); tags.addAll(Tag.fromMap(AzkabanTags.getAzkabanTags())); RootMetricContext.get(tags); this.daemon = new SchedulerDaemon(props); }
/** * 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))); }
private GobblinMetrics initializeMetrics() { ImmutableList.Builder<Tag<?>> tags = ImmutableList.builder(); tags.addAll(this.tags); tags.addAll(Tag.fromMap(ClusterNameTags.getClusterNameTags())); GobblinMetrics gobblinMetrics = GobblinMetrics.get(this.state.getProp(ConfigurationKeys.JOB_NAME_KEY), null, tags.build()); gobblinMetrics.startMetricReporting(this.state.getProperties()); return gobblinMetrics; }
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; }
tags.addAll(Tag.fromMap(AzkabanTags.getAzkabanTags())); RootMetricContext.get(tags); GobblinMetrics.addCustomTagsToProperties(this.props, tags);