org.apache.gobblin.metrics.Tag.getKey()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.apache.gobblin.metrics.Tag.getKey()方法的一些代码示例,展示了Tag.getKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tag.getKey()方法的具体详情如下:
包路径:org.apache.gobblin.metrics.Tag
类名称:Tag
方法名:getKey

Tag.getKey介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-gobblin

@Override
 public String toString() {
  return getKey() + KEY_VALUE_SEPARATOR + getValue();
 }
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * 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();
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public void addTag(Tag<?> tag) {
 Preconditions.checkNotNull(tag, "Cannot add a null Tag");
 Preconditions.checkNotNull(tag.getValue(), "Cannot add a Tag with a null value. Tag: " + tag);
 this.tags.put(tag.getKey(), tag.getValue());
}

代码示例来源:origin: apache/incubator-gobblin

public static Map<String, String> dumpTags(MetricContext context) {
 Map<String, String> output = new HashMap<>();
 for (Tag<?> tag : context.getTags()) {
  output.put(tag.getKey(), tag.getValue().toString());
 }
 return output;
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * Add tags.
 * @param tags List of {@link org.apache.gobblin.metrics.Tag}
 * @return {@code this}
 */
public T withTags(List<Tag<?>> tags) {
 for(Tag<?> tag : tags) {
  this.tags.put(tag.getKey(), tag.getValue().toString());
 }
 return self();
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * 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());
}

代码示例来源:origin: apache/incubator-gobblin

@Test(dependsOnMethods = "testAddTags")
public void testGetTags() {
 List<Tag<?>> tags = this.tagged.getTags();
 Assert.assertEquals(tags.size(), 2);
 Assert.assertEquals(tags.get(0).getKey(), JOB_ID_KEY);
 Assert.assertEquals(tags.get(0).getValue(), JOB_ID);
 Assert.assertEquals(tags.get(1).getKey(), PROJECT_VERSION_KEY);
 Assert.assertEquals(tags.get(1).getValue(), PROJECT_VERSION);
}

代码示例来源:origin: apache/incubator-gobblin

@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);
 }
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void testChildContext() {
 this.childContext = this.context.childBuilder(CHILD_CONTEXT_NAME)
   .addTag(new Tag<String>(TASK_ID_KEY, TASK_ID_PREFIX + 0))
   .build();
 Assert.assertEquals(this.childContext.getName(), CHILD_CONTEXT_NAME);
 Assert.assertTrue(this.childContext.getParent().isPresent());
 Assert.assertEquals(this.childContext.getParent().get(), this.context);
 Assert.assertEquals(this.childContext.getTags().size(), 4);
 Assert.assertEquals(this.childContext.getTags().get(0).getKey(), JOB_ID_KEY);
 Assert.assertEquals(this.childContext.getTags().get(0).getValue(), JOB_ID_PREFIX + 0);
 Assert.assertEquals(this.childContext.getTags().get(1).getKey(), MetricContext.METRIC_CONTEXT_ID_TAG_NAME);
 Assert.assertEquals(this.childContext.getTags().get(2).getKey(), MetricContext.METRIC_CONTEXT_NAME_TAG_NAME);
 Assert.assertEquals(this.childContext.getTags().get(3).getKey(), TASK_ID_KEY);
 Assert.assertEquals(this.childContext.getTags().get(3).getValue(), TASK_ID_PREFIX + 0);
}

代码示例来源:origin: apache/incubator-gobblin

@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}"));
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void kafkaReporterTagsTest() throws IOException {
 MetricContext metricContext =
   MetricContext.builder(this.getClass().getCanonicalName() + ".kafkaReporterTagsTest").build();
 Counter counter = metricContext.counter("com.linkedin.example.counter");
 Tag<?> tag1 = new Tag<>("tag1", "value1");
 Tag<?> tag2 = new Tag<>("tag2", 2);
 MockKafkaPusher pusher = new MockKafkaPusher();
 KafkaReporter kafkaReporter =
   getBuilder(pusher).withTags(Lists.newArrayList(tag1, tag2)).build("localhost:0000", "topic", new Properties());
 counter.inc();
 kafkaReporter.report(metricContext);
 try {
  Thread.sleep(1000);
 } catch (InterruptedException ex) {
  Thread.currentThread().interrupt();
 }
 MetricReport metricReport = nextReport(pusher.messageIterator());
 Assert.assertEquals(4, metricReport.getTags().size());
 Assert.assertTrue(metricReport.getTags().containsKey(tag1.getKey()));
 Assert.assertEquals(metricReport.getTags().get(tag1.getKey()), tag1.getValue().toString());
 Assert.assertTrue(metricReport.getTags().containsKey(tag2.getKey()));
 Assert.assertEquals(metricReport.getTags().get(tag2.getKey()), tag2.getValue().toString());
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void kafkaReporterContextTest() throws IOException {
 Tag<?> tag1 = new Tag<>("tag1", "value1");
 MetricContext context = MetricContext.builder("context").addTag(tag1).build();
 Counter counter = context.counter("com.linkedin.example.counter");
 MockKafkaPusher pusher = new MockKafkaPusher();
 KafkaReporter kafkaReporter = getBuilderFromContext(pusher).build("localhost:0000", "topic", new Properties());
 counter.inc();
 kafkaReporter.report(context);
 try {
  Thread.sleep(1000);
 } catch (InterruptedException ex) {
  Thread.currentThread().interrupt();
 }
 MetricReport metricReport = nextReport(pusher.messageIterator());
 Assert.assertEquals(3, metricReport.getTags().size());
 Assert.assertTrue(metricReport.getTags().containsKey(tag1.getKey()));
 Assert.assertEquals(metricReport.getTags().get(tag1.getKey()), tag1.getValue().toString());
}

代码示例来源:origin: org.apache.gobblin/gobblin-metrics-base

@Override
 public String toString() {
  return getKey() + KEY_VALUE_SEPARATOR + getValue();
 }
}

代码示例来源:origin: org.apache.gobblin/gobblin-metrics-base

/**
 * 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();
}

代码示例来源:origin: org.apache.gobblin/gobblin-metrics-base

@Override
public void addTag(Tag<?> tag) {
 Preconditions.checkNotNull(tag, "Cannot add a null Tag");
 Preconditions.checkNotNull(tag.getValue(), "Cannot add a Tag with a null value. Tag: " + tag);
 this.tags.put(tag.getKey(), tag.getValue());
}

代码示例来源:origin: org.apache.gobblin/gobblin-metrics

public static Map<String, String> dumpTags(MetricContext context) {
 Map<String, String> output = new HashMap<>();
 for (Tag<?> tag : context.getTags()) {
  output.put(tag.getKey(), tag.getValue().toString());
 }
 return output;
}

代码示例来源:origin: org.apache.gobblin/gobblin-metrics-base

/**
 * Add tags.
 * @param tags List of {@link org.apache.gobblin.metrics.Tag}
 * @return {@code this}
 */
public T withTags(List<Tag<?>> tags) {
 for(Tag<?> tag : tags) {
  this.tags.put(tag.getKey(), tag.getValue().toString());
 }
 return self();
}

代码示例来源:origin: org.apache.gobblin/gobblin-metrics-base

/**
 * 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());
}

相关文章