本文整理了Java中com.netflix.spectator.api.Utils.getTagValue()
方法的一些代码示例,展示了Utils.getTagValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.getTagValue()
方法的具体详情如下:
包路径:com.netflix.spectator.api.Utils
类名称:Utils
方法名:getTagValue
[英]Returns the value associated with with a given key or null if no such key is present in the set of tags.
[中]返回与给定键关联的值,如果标记集中不存在此类键,则返回null。
代码示例来源:origin: apache/servicecomb-java-chassis
protected void readMeasurement(String name, Setter setter) {
MeasurementNode node = tree.findChild(name);
if (node == null) {
return;
}
for (Measurement measurement : node.getMeasurements()) {
String threadPoolName = Utils.getTagValue(measurement.id(), ThreadPoolMonitor.ID_TAG_NAME);
if (threadPoolName == null) {
continue;
}
ThreadPoolPublishModel model = threadPools.computeIfAbsent(threadPoolName, tpn -> {
return new ThreadPoolPublishModel();
});
setter.set(model, measurement);
}
}
}
代码示例来源:origin: Netflix/spectator
private static boolean isPercentile(Id id) {
final String stat = Utils.getTagValue(id, "statistic");
return "percentile".equals(stat);
}
代码示例来源:origin: com.netflix.spectator/spectator-ext-ipc
private static boolean isPercentile(Id id) {
final String stat = Utils.getTagValue(id, "statistic");
return "percentile".equals(stat);
}
代码示例来源:origin: Netflix/spectator
private void validateValues(Id id, String key, SortedSet<String> allowedValues) {
String value = Utils.getTagValue(id, key);
if (value != null && !allowedValues.contains(value)) {
String values = allowedValues.stream()
.collect(Collectors.joining(", "));
throw new IllegalArgumentException(String.format(
"[%s] invalid value for dimension %s, acceptable values are (%s)",
id, key, values));
}
}
代码示例来源:origin: Netflix/spectator
@SuppressWarnings("PMD.PreserveStackTrace")
private <T extends Enum<T>> void validateValues(Id id, String key, Class<T> cls) {
String value = Utils.getTagValue(id, key);
if (value != null) {
try {
Enum.valueOf(cls, value);
} catch (Exception e) {
String values = Arrays.stream(cls.getEnumConstants())
.map(Enum::name)
.collect(Collectors.joining(", "));
throw new IllegalArgumentException(String.format(
"[%s] invalid value for dimension %s, acceptable values are (%s)",
id, key, values));
}
}
}
代码示例来源:origin: com.netflix.spectator/spectator-ext-ipc
private void validateValues(Id id, String key, SortedSet<String> allowedValues) {
String value = Utils.getTagValue(id, key);
if (value != null && !allowedValues.contains(value)) {
String values = allowedValues.stream()
.collect(Collectors.joining(", "));
throw new IllegalArgumentException(String.format(
"[%s] invalid value for dimension %s, acceptable values are (%s)",
id, key, values));
}
}
代码示例来源:origin: Netflix/spectator
/**
* Returns the first measurement with a given tag value.
*
* @param ms
* A set of measurements.
* @param k
* Key to search for.
* @param v
* Value that should be associated with k on the ids.
* @return
* Measurement or null if no matches are found.
*/
public static Measurement first(final Iterable<Measurement> ms, final String k, final String v) {
return first(ms, value -> v.equals(getTagValue(value.id(), k)));
}
代码示例来源:origin: Netflix/spectator
/**
* Returns a new iterable restricted to measurements that match the predicate.
*
* @param ms
* A set of measurements.
* @param k
* Key to search for.
* @param v
* Value that should be associated with k on the ids.
* @return
* Measurements matching the predicate.
*/
public static Iterable<Measurement> filter(
final Iterable<Measurement> ms, final String k, final String v) {
return filter(ms, value -> v.equals(getTagValue(value.id(), k)));
}
代码示例来源:origin: Netflix/spectator
/**
* Returns the value associated with with a given key or null if no such key is present in the
* set of tags.
*
* @param id
* Identifier with a set of tags to search.
* @param k
* Key to search for.
* @return
* Value for the key or null if the key is not present.
*/
public static String getTagValue(Id id, String k) {
Preconditions.checkNotNull(id, "id");
return getTagValue(id.tags(), k);
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Returns the value associated with with a given key or null if no such key is present in the
* set of tags.
*
* @param id
* Identifier with a set of tags to search.
* @param k
* Key to search for.
* @return
* Value for the key or null if the key is not present.
*/
public static String getTagValue(Id id, String k) {
Preconditions.checkNotNull(id, "id");
return getTagValue(id.tags(), k);
}
代码示例来源:origin: Netflix/spectator
/** Returns a set of all values for a given tag key. */
private Set<String> valueSet(String k) {
return registry.stream()
.map(m -> Utils.getTagValue(m.id(), k))
.filter(v -> v != null)
.collect(Collectors.toSet());
}
代码示例来源:origin: Netflix/spectator
/** Returns a set of all values for a given tag key. */
private Set<String> valueSet(String k) {
return registry.stream()
.map(m -> Utils.getTagValue(m.id(), k))
.filter(v -> v != null)
.collect(Collectors.toSet());
}
代码示例来源:origin: Netflix/spectator
static void checkResult(Id id, String expected) {
String endpoint = Utils.getTagValue(id, IpcTagKey.result.key());
Assertions.assertEquals(expected, endpoint);
}
代码示例来源:origin: Netflix/spectator
static void checkStatus(Id id, String expected) {
String endpoint = Utils.getTagValue(id, IpcTagKey.httpStatus.key());
Assertions.assertEquals(expected, endpoint);
}
代码示例来源:origin: Netflix/spectator
static void checkErrorReason(Id id, String expected) {
String endpoint = Utils.getTagValue(id, IpcTagKey.statusDetail.key());
Assertions.assertEquals(expected, endpoint);
}
代码示例来源:origin: Netflix/spectator
static void checkEndpoint(Id id, String expected) {
String endpoint = Utils.getTagValue(id, IpcTagKey.endpoint.key());
Assertions.assertEquals(expected, endpoint);
}
代码示例来源:origin: Netflix/spectator
static void checkMethod(Id id, String expected) {
String endpoint = Utils.getTagValue(id, IpcTagKey.httpMethod.key());
Assertions.assertEquals(expected, endpoint);
}
代码示例来源:origin: Netflix/spectator
@Test
public void getTagValueId() {
Registry r = new DefaultRegistry();
Id id = r.createId("foo", "bar", "baz", "abc", "def");
Assertions.assertEquals("def", Utils.getTagValue(id, "abc"));
Assertions.assertEquals("baz", Utils.getTagValue(id, "bar"));
}
代码示例来源:origin: Netflix/spectator
@Test
public void getTagValueIdNoTags() {
Registry r = new DefaultRegistry();
Id id = r.createId("foo");
Assertions.assertEquals(null, Utils.getTagValue(id, "abc"));
}
代码示例来源:origin: Netflix/spectator
@Test
public void endpointUnknownIfNotSet() {
Registry registry = new DefaultRegistry();
IpcLogger logger = new IpcLogger(registry, clock, LoggerFactory.getLogger(getClass()));
logger.createServerEntry()
.withOwner("test")
.markStart()
.markEnd()
.log();
registry.counters().forEach(c -> {
Assertions.assertEquals("unknown", Utils.getTagValue(c.id(), "ipc.endpoint"));
});
}
}
内容来源于网络,如有侵权,请联系作者删除!