Java Code Examples for io.opencensus.tags.TagKey#create()
The following examples show how to use
io.opencensus.tags.TagKey#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CorrelationContextFormat.java From opencensus-java with Apache License 2.0 | 6 votes |
private static void decodeTag(String stringTag, Map<TagKey, TagValueWithMetadata> tags) { String keyWithValue; int firstPropertyIndex = stringTag.indexOf(TAG_PROPERTIES_DELIMITER); if (firstPropertyIndex != -1) { // Tag with properties. keyWithValue = stringTag.substring(0, firstPropertyIndex); // TODO(songya): support decoding tag properties. } else { // Tag without properties. keyWithValue = stringTag; } List<String> keyValuePair = TAG_KEY_VALUE_SPLITTER.splitToList(keyWithValue); checkArgument(keyValuePair.size() == 2, "Malformed tag " + stringTag); TagKey key = TagKey.create(keyValuePair.get(0).trim()); TagValue value = TagValue.create(keyValuePair.get(1).trim()); TagValueWithMetadata valueWithMetadata = TagValueWithMetadata.create(value, METADATA_UNLIMITED_PROPAGATION); tags.put(key, valueWithMetadata); }
Example 2
Source File: ViewTest.java From opencensus-java with Apache License 2.0 | 5 votes |
@Test public void preventDuplicateColumns() { TagKey key1 = TagKey.create("duplicate"); TagKey key2 = TagKey.create("duplicate"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Columns have duplicate."); View.create(NAME, DESCRIPTION, MEASURE, MEAN, Arrays.asList(key1, key2)); }
Example 3
Source File: TagsBenchmark.java From opencensus-java with Apache License 2.0 | 5 votes |
@Setup public void setup() throws Exception { StringBuilder builder = new StringBuilder(size); // build a string with characters from 'a' to 'z' for (int i = 0; i < size; i++) { builder.append((char) (97 + i % 26)); } input = builder.toString(); tagKey = TagKey.create(input); tagValue = TagValue.create(input); }
Example 4
Source File: TagsBenchmarksUtil.java From opencensus-java with Apache License 2.0 | 5 votes |
/** Creates an array of TagKeys of 'size' with 'name' prefix. */ @VisibleForTesting public static TagKey[] createTagKeys(int size, String name) { TagKey[] keys = new TagKey[size]; for (int i = 0; i < size; i++) { keys[i] = TagKey.create(name + i); } return keys; }
Example 5
Source File: BinarySerializationUtils.java From opencensus-java with Apache License 2.0 | 5 votes |
private static final TagKey createTagKey(String name) throws TagContextDeserializationException { try { return TagKey.create(name); } catch (IllegalArgumentException e) { throw new TagContextDeserializationException("Invalid tag key: " + name, e); } }
Example 6
Source File: TagsBenchmark.java From opencensus-java with Apache License 2.0 | 4 votes |
@Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public TagKey tagKeyCreation(Data data) { return TagKey.create("key"); }
Example 7
Source File: ViewManagerImplTest.java From opencensus-java with Apache License 2.0 | 4 votes |
@Test public void testViewDataWithMultipleTagKeys() { TagKey key1 = TagKey.create("Key-1"); TagKey key2 = TagKey.create("Key-2"); viewManager.registerView( createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(key1, key2))); statsRecorder .newMeasureMap() .put(MEASURE_DOUBLE, 1.1) .record( tagger .emptyBuilder() .put(key1, TagValue.create("v1")) .put(key2, TagValue.create("v10")) .build()); statsRecorder .newMeasureMap() .put(MEASURE_DOUBLE, 2.2) .record( tagger .emptyBuilder() .put(key1, TagValue.create("v1")) .put(key2, TagValue.create("v20")) .build()); statsRecorder .newMeasureMap() .put(MEASURE_DOUBLE, 3.3) .record( tagger .emptyBuilder() .put(key1, TagValue.create("v2")) .put(key2, TagValue.create("v10")) .build()); statsRecorder .newMeasureMap() .put(MEASURE_DOUBLE, 4.4) .record( tagger .emptyBuilder() .put(key1, TagValue.create("v1")) .put(key2, TagValue.create("v10")) .build()); ViewData viewData = viewManager.getView(VIEW_NAME); assertAggregationMapEquals( viewData.getAggregationMap(), ImmutableMap.of( Arrays.asList(TagValue.create("v1"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 1.1, 4.4), Arrays.asList(TagValue.create("v1"), TagValue.create("v20")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 2.2), Arrays.asList(TagValue.create("v2"), TagValue.create("v10")), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 3.3)), EPSILON); }