com.netflix.spectator.api.Tag.key()方法的使用及代码示例

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

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

Tag.key介绍

[英]Key for the tag.
[中]标签的钥匙。

代码示例

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
 public Tag find(Iterable<Tag> tags) {
  for (Tag tag : tags) {
   if (tag.key().equals(tagKey)) {
    return tag;
   }
  }

  return null;
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

protected Sample convertMeasurementToSample(Measurement measurement) {
 String prometheusName = measurement.id().name().replace(".", "_");
 List<String> labelNames = new ArrayList<>();
 List<String> labelValues = new ArrayList<>();
 for (Tag tag : measurement.id().tags()) {
  labelNames.add(tag.key());
  labelValues.add(tag.value());
 }
 return new Sample(prometheusName, labelNames, labelValues, measurement.value());
}

代码示例来源:origin: Netflix/spectator

private String[] toStringArray(Tag[] ts, int length) {
 String[] strs = new String[length * 2];
 for (int i = 0; i < length; ++i) {
  strs[2 * i] = ts[i].key();
  strs[2 * i + 1] = ts[i].value();
 }
 return strs;
}

代码示例来源:origin: Netflix/spectator

private void putTag(Map<String, String> tags, Tag tag) {
 if (tag != null) {
  tags.put(tag.key(), tag.value());
 }
}

代码示例来源:origin: Netflix/spectator

@Override public boolean equals(Object obj) {
 if (obj == this) return true;
 if (!(obj instanceof Tag)) return false;
 Tag tag = (Tag) obj;
 return key.equals(tag.key()) && value.equals(tag.value());
}

代码示例来源:origin: Netflix/spectator

/**
 * Add custom tags to the request metrics. Note, IPC metrics already have many tags and it
 * is not recommended for users to tack on additional context. In particular, any additional
 * tags should have a <b>guaranteed</b> low cardinality. If additional tagging causes these
 * metrics to exceed limits, then you may lose all visibility into requests.
 */
public IpcLogEntry addTag(Tag tag) {
 this.additionalTags.put(tag.key(), tag.value());
 return this;
}

代码示例来源:origin: com.netflix.spectator/spectator-web-spring

@Override public boolean equals(Object obj) {
 if (obj == this) return true;
 if (!(obj instanceof Tag)) return false;
 Tag tag = (Tag) obj;
 return key.equals(tag.key()) && value.equals(tag.value());
}

代码示例来源:origin: Netflix/spectator

/** Create a new instance. */
public MetricsRegistry(Clock clock, com.codahale.metrics.MetricRegistry impl) {
 this(clock, impl, id -> {
  Id normalized = Utils.normalize(id);
  StringBuilder buf = new StringBuilder();
  buf.append(normalized.name());
  for (Tag t : normalized.tags()) {
   buf.append('.').append(t.key()).append('-').append(t.value());
  }
  return buf.toString();
 });
}

代码示例来源:origin: Netflix/spectator

/** Convert {@code id} to a map. */
static Map<String, String> toMap(Id id) {
 Map<String, String> tags = new HashMap<>();
 for (Tag t : id.tags()) {
  tags.put(t.key(), t.value());
 }
 tags.put("name", id.name());
 return tags;
}

代码示例来源:origin: Netflix/spectator

/**
 * Convert an arbitrary implementation of {@link Tag} to BasicTag. When
 * used as part of an id this is needed to ensure correct behavior. Alternative
 * implementations will likely vary the hashCode/equals causing ids that should
 * be equivalent to not match as expected.
 */
static BasicTag convert(Tag t) {
 return (t instanceof BasicTag) ? (BasicTag) t : new BasicTag(t.key(), t.value());
}

代码示例来源:origin: com.netflix.spectator/spectator-reg-stateless

private static int operation(Id id) {
 for (Tag t : id.tags()) {
  if ("statistic".equals(t.key())) {
   return operation(t.value());
  }
 }
 LOGGER.warn("invalid statistic for {}, value will be dropped", id);
 return UNKNOWN;
}

代码示例来源:origin: Netflix/spectator

private static int operation(Id id) {
 for (Tag t : id.tags()) {
  if ("statistic".equals(t.key())) {
   return operation(t.value());
  }
 }
 LOGGER.warn("invalid statistic for {}, value will be dropped", id);
 return UNKNOWN;
}

代码示例来源:origin: org.springframework.metrics/spring-metrics

static List<Measurement> measurements(com.netflix.spectator.api.Meter meter) {
  return stream(meter.measure().spliterator(), false)
      .map(m ->
          new Measurement(
              m.id().name(),
              stream(m.id().tags().spliterator(), false)
                  .map(t -> Tag.of(t.key(), t.value()))
                  .collect(Collectors.toList()),
              m.value())
      )
      .collect(Collectors.toList());
}

代码示例来源:origin: Netflix/spectator

/** Converts a spectator id into a MonitorConfig that can be used by servo. */
MonitorConfig toMonitorConfig(Id id, Tag stat) {
 MonitorConfig.Builder builder = new MonitorConfig.Builder(id.name());
 if (stat != null) {
  builder.withTag(stat.key(), stat.value());
 }
 for (Tag t : id.tags()) {
  builder.withTag(t.key(), t.value());
 }
 return builder.build();
}

代码示例来源:origin: Netflix/spectator

private String get(Id id, String key) {
 for (Tag t : id.tags()) {
  if (key.equals(t.key())) {
   return t.value();
  }
 }
 return null;
}

代码示例来源:origin: Netflix/spectator

@Override public Id withTags(Iterable<Tag> ts) {
 MonitorConfig.Builder builder = new MonitorConfig.Builder(config);
 for (Tag t : ts) {
  builder.withTag(t.key(), t.value());
 }
 return new ServoId(builder.build());
}

代码示例来源:origin: Netflix/spectator

@Test
public void createIdNameAndTags() {
 Id id = registry.createId("foo", "a", "1", "b", "2");
 Assertions.assertEquals("foo", id.name());
 Map<String, String> tags = new HashMap<>();
 tags.put("a", "1");
 tags.put("b", "2");
 for (Tag t : id.tags()) {
  Assertions.assertEquals(tags.remove(t.key()), t.value());
 }
 Assertions.assertTrue(tags.isEmpty());
}

代码示例来源:origin: Netflix/spectator

private TagsValuePair newTagsValuePair(Measurement m) {
 Map<String, String> tags = new HashMap<>();
 for (Tag t : m.id().tags()) {
  tags.put(t.key(), t.value());
 }
 tags.put("name", m.id().name());
 return new TagsValuePair(tags, m.value());
}

代码示例来源:origin: Netflix/spectator

private TagsValuePair newTagsValuePair(Measurement m) {
 Map<String, String> tags = new HashMap<>();
 for (Tag t : m.id().tags()) {
  tags.put(t.key(), t.value());
 }
 tags.put("name", m.id().name());
 return new TagsValuePair(tags, m.value());
}

代码示例来源:origin: Netflix/spectator

@Test
public void testSingle() {
 ArrayTagSet ts = ArrayTagSet.create("k", "v");
 for (Tag t : ts) {
  Assertions.assertEquals(t.key(), "k");
  Assertions.assertEquals(t.value(), "v");
 }
}

相关文章