Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 42554d2

Browse files
author
Dino Oliva
committed
Changes constructors to static factory methods for TagKey and TagValue.
1 parent 4f9d113 commit 42554d2

File tree

15 files changed

+95
-74
lines changed

15 files changed

+95
-74
lines changed

core/java/com/google/instrumentation/stats/RpcConstants.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import com.google.instrumentation.stats.MeasurementDescriptor.BasicUnit;
1717
import com.google.instrumentation.stats.MeasurementDescriptor.MeasurementUnit;
18+
import com.google.instrumentation.stats.ViewDescriptor.DistributionViewDescriptor;
19+
import com.google.instrumentation.stats.ViewDescriptor.IntervalViewDescriptor;
1820

1921
import java.util.Arrays;
2022
import java.util.List;
@@ -26,9 +28,9 @@ public final class RpcConstants {
2628
/**
2729
* Census defined tag keys.
2830
*/
29-
public static final TagKey RPC_STATUS = new TagKey("/rpc/status");
30-
public static final TagKey RPC_CLIENT_METHOD = new TagKey("/rpc/client_method");
31-
public static final TagKey RPC_SERVER_METHOD = new TagKey("/rpc/server_method");
31+
public static final TagKey RPC_STATUS = TagKey.create("/rpc/status");
32+
public static final TagKey RPC_CLIENT_METHOD = TagKey.create("/rpc/client_method");
33+
public static final TagKey RPC_SERVER_METHOD = TagKey.create("/rpc/server_method");
3234

3335
// Constants used to define the following MeasurementDescriptors.
3436
private static final List<BasicUnit> bytes = Arrays.asList(new BasicUnit[] { BasicUnit.BYTES });
@@ -58,8 +60,13 @@ public final class RpcConstants {
5860
public static final MeasurementDescriptor RPC_CLIENT_ROUNDTRIP_LATENCY =
5961
MeasurementDescriptor.create(
6062
"/rpc/client/roundtrip_latency",
61-
"RPC roundtrip latency us",
62-
MeasurementUnit.create(-6, scalar));
63+
"RPC roundtrip latency msecs",
64+
MeasurementUnit.create(-3, scalar));
65+
public static final MeasurementDescriptor RPC_CLIENT_SERVER_ELAPSED_TIME =
66+
MeasurementDescriptor.create(
67+
"/rpc/client/server_elapsed_time",
68+
"Server elapsed time in msecs",
69+
MeasurementUnit.create(-3, scalar));
6370
public static final MeasurementDescriptor RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES =
6471
MeasurementDescriptor.create(
6572
"/rpc/client/uncompressed_request_bytes",
@@ -89,6 +96,11 @@ public final class RpcConstants {
8996
"/rpc/server/response_bytes",
9097
"Response MB/s",
9198
MeasurementUnit.create(6, bytes, seconds));
99+
public static final MeasurementDescriptor RPC_SERVER_SERVER_ELAPSED_TIME =
100+
MeasurementDescriptor.create(
101+
"/rpc/server/server_elapsed_time",
102+
"Server elapsed time in msecs",
103+
MeasurementUnit.create(-3, scalar));
92104
public static final MeasurementDescriptor RPC_SERVER_SERVER_LATENCY =
93105
MeasurementDescriptor.create(
94106
"/rpc/server/server_latency",

core/java/com/google/instrumentation/stats/Tag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
public final class Tag {
2020
/**
21-
* Constructs a new {@link Tag} from the give key and value.
21+
* Constructs a new {@link Tag} from the given key and value.
2222
*/
2323
public static Tag create(TagKey key, TagValue value) {
2424
return new Tag(key, value);

core/java/com/google/instrumentation/stats/TagKey.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
public final class TagKey {
2222
public static final int MAX_LENGTH = StringUtil.MAX_LENGTH;
2323

24-
public TagKey(String key) {
25-
this.key = StringUtil.sanitize(key);
24+
/**
25+
* Constructs a new {@link TagKey} from the given string.
26+
*/
27+
public static TagKey create(String key) {
28+
return new TagKey(key);
2629
}
2730

2831
@Override
@@ -41,4 +44,8 @@ public String toString() {
4144
}
4245

4346
private final String key;
47+
48+
private TagKey(String key) {
49+
this.key = StringUtil.sanitize(key);
50+
}
4451
}

core/java/com/google/instrumentation/stats/TagValue.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
public final class TagValue {
2222
public static final int MAX_LENGTH = StringUtil.MAX_LENGTH;
2323

24-
public TagValue(String value) {
25-
this.value = StringUtil.sanitize(value);
24+
/**
25+
* Constructs a new {@link TagKey} from the given string.
26+
*/
27+
public static TagValue create(String value) {
28+
return new TagValue(value);
2629
}
2730

2831
@Override
@@ -41,4 +44,8 @@ public String toString() {
4144
}
4245

4346
private final String value;
47+
48+
private TagValue(String value) {
49+
this.value = StringUtil.sanitize(value);
50+
}
4451
}

core/javatests/com/google/instrumentation/stats/DistributionAggregationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public void testDistributionAggregationWithBuckets() {
6767
}
6868
}
6969

70-
private static final TagKey K1 = new TagKey("k1");
71-
private static final TagKey K2 = new TagKey("k2");
70+
private static final TagKey K1 = TagKey.create("k1");
71+
private static final TagKey K2 = TagKey.create("k2");
7272

73-
private static final TagValue V1 = new TagValue("v1");
74-
private static final TagValue V2 = new TagValue("v2");
73+
private static final TagValue V1 = TagValue.create("v1");
74+
private static final TagValue V2 = TagValue.create("v2");
7575

7676
private static final List<Tag> TAGS = Arrays.asList(Tag.create(K1, V1), Tag.create(K2, V2));
7777
}

core/javatests/com/google/instrumentation/stats/IntervalAggregationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public void testInterval() {
5555
assertThat(interval.getSum()).isWithin(0.00000001).of(1000.0);
5656
}
5757

58-
private static final TagKey K1 = new TagKey("k1");
59-
private static final TagKey K2 = new TagKey("k2");
58+
private static final TagKey K1 = TagKey.create("k1");
59+
private static final TagKey K2 = TagKey.create("k2");
6060

61-
private static final TagValue V1 = new TagValue("v1");
62-
private static final TagValue V2 = new TagValue("v2");
61+
private static final TagValue V1 = TagValue.create("v1");
62+
private static final TagValue V2 = TagValue.create("v2");
6363

6464
private static final List<Tag> TAGS = Arrays.asList(Tag.create(K1, V1), Tag.create(K2, V2));
6565
}

core/javatests/com/google/instrumentation/stats/MeasurementDescriptorTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public void testComponents() {
5050
"Foo",
5151
"The description of Foo",
5252
MeasurementUnit.create(
53-
6,
54-
Arrays.asList(new BasicUnit[] { BasicUnit.BITS }),
55-
Arrays.asList(new BasicUnit[] { BasicUnit.SECONDS })));
53+
6, Arrays.asList(BasicUnit.BITS), Arrays.asList(BasicUnit.SECONDS)));
5654
assertThat(measurement.getName()).isEqualTo("Foo");
5755
assertThat(measurement.getDescription()).isEqualTo("The description of Foo");
5856
assertThat(measurement.getUnit().getPower10()).isEqualTo(6);
@@ -66,6 +64,6 @@ private static final MeasurementDescriptor makeSimpleDescriptor(String name) {
6664
return MeasurementDescriptor.create(
6765
name,
6866
name + " description",
69-
MeasurementUnit.create(1, Arrays.asList(new BasicUnit[] { BasicUnit.SCALAR })));
67+
MeasurementUnit.create(1, Arrays.asList(BasicUnit.SCALAR)));
7068
}
7169
}

core/javatests/com/google/instrumentation/stats/MeasurementMapTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testSize() {
9393
}
9494

9595
private static final MeasurementUnit simpleMeasurementUnit =
96-
MeasurementUnit.create(1, Arrays.asList(new BasicUnit[] { BasicUnit.SCALAR }));
96+
MeasurementUnit.create(1, Arrays.asList(BasicUnit.SCALAR));
9797
private static final MeasurementDescriptor M1 = makeSimpleMeasurement("m1");
9898
private static final MeasurementDescriptor M2 = makeSimpleMeasurement("m2");
9999
private static final MeasurementDescriptor M3 = makeSimpleMeasurement("m3");

core/javatests/com/google/instrumentation/stats/StatsContextTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ public class StatsContextTest {
3333
RpcConstants.RPC_SERVER_RESPONSE_BYTES, RpcConstants.RPC_SERVER_SERVER_LATENCY
3434
};
3535

36-
private static final TagKey K_EMPTY = new TagKey("");
37-
private static final TagKey K1 = new TagKey("k1");
38-
private static final TagKey K2 = new TagKey("k2");
39-
private static final TagKey K3 = new TagKey("k3");
40-
private static final TagKey K4 = new TagKey("k4");
41-
private static final TagKey K10 = new TagKey("k10");
42-
43-
private static final TagValue V_EMPTY = new TagValue("");
44-
private static final TagValue V1 = new TagValue("v1");
45-
private static final TagValue V2 = new TagValue("v2");
46-
private static final TagValue V3 = new TagValue("v3");
47-
private static final TagValue V4 = new TagValue("v4");
48-
private static final TagValue V10 = new TagValue("v10");
49-
private static final TagValue V20 = new TagValue("v20");
50-
private static final TagValue V30 = new TagValue("v30");
51-
private static final TagValue V100 = new TagValue("v100");
36+
private static final TagKey K_EMPTY = TagKey.create("");
37+
private static final TagKey K1 = TagKey.create("k1");
38+
private static final TagKey K2 = TagKey.create("k2");
39+
private static final TagKey K3 = TagKey.create("k3");
40+
private static final TagKey K4 = TagKey.create("k4");
41+
private static final TagKey K10 = TagKey.create("k10");
42+
43+
private static final TagValue V_EMPTY = TagValue.create("");
44+
private static final TagValue V1 = TagValue.create("v1");
45+
private static final TagValue V2 = TagValue.create("v2");
46+
private static final TagValue V3 = TagValue.create("v3");
47+
private static final TagValue V4 = TagValue.create("v4");
48+
private static final TagValue V10 = TagValue.create("v10");
49+
private static final TagValue V20 = TagValue.create("v20");
50+
private static final TagValue V30 = TagValue.create("v30");
51+
private static final TagValue V100 = TagValue.create("v100");
5252

5353
@Test
5454
public void testWith() {

core/javatests/com/google/instrumentation/stats/TagKeyTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ public void testKeyMaxLength() {
3232
char[] truncKey = new char[TagKey.MAX_LENGTH + 10];
3333
Arrays.fill(key, 'k');
3434
Arrays.fill(truncKey, 'k');
35-
assertThat(new TagKey(new String(key)).toString())
36-
.isEqualTo(new TagKey(new String(truncKey)).toString());
35+
assertThat(TagKey.create(new String(key)).toString())
36+
.isEqualTo(TagKey.create(new String(truncKey)).toString());
3737
}
3838

3939
@Test
4040
public void testKeyBadChar() {
4141
String key = "\2ab\3cd";
42-
assertThat(new TagKey(key).toString())
42+
assertThat(TagKey.create(key).toString())
4343
.isEqualTo(StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "ab"
4444
+ StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "cd");
4545
}
4646

4747
@Test
4848
public void testEquals() {
4949
new EqualsTester()
50-
.addEqualityGroup(new TagKey("foo"), new TagKey("foo"))
51-
.addEqualityGroup(new TagKey("bar"))
50+
.addEqualityGroup(TagKey.create("foo"), TagKey.create("foo"))
51+
.addEqualityGroup(TagKey.create("bar"))
5252
.testEquals();
5353
}
5454

5555
@Test
5656
public void testToString() {
57-
assertThat(new TagKey("foo").toString()).isEqualTo("foo");
57+
assertThat(TagKey.create("foo").toString()).isEqualTo("foo");
5858
}
5959
}

0 commit comments

Comments
 (0)