Skip to content

Commit 0091f39

Browse files
committed
[FLINK-37426][metrics] Extract AttributeBuilder interface
1 parent 5a91138 commit 0091f39

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.flink;
20+
21+
import org.apache.flink.annotation.Experimental;
22+
23+
/** Common interface to all builders that support key-value attributes. */
24+
@Experimental
25+
public interface AttributeBuilder {
26+
/** Additional attribute to be attached to this builder. */
27+
AttributeBuilder setAttribute(String key, String value);
28+
29+
/** Additional attribute to be attached to this builder. */
30+
AttributeBuilder setAttribute(String key, long value);
31+
32+
/** Additional attribute to be attached to this builder. */
33+
AttributeBuilder setAttribute(String key, double value);
34+
35+
/** Additional attribute to be attached to this builder. */
36+
AttributeBuilder setAttribute(String key, boolean value);
37+
}

flink-metrics/flink-metrics-core/src/main/java/org/apache/flink/events/EventBuilder.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.flink.events;
2020

21+
import org.apache.flink.AttributeBuilder;
2122
import org.apache.flink.annotation.Experimental;
2223

2324
import java.util.Collections;
@@ -26,7 +27,7 @@
2627

2728
/** Builder used to construct {@link Event}. See {@link Event#builder(Class, String)}. */
2829
@Experimental
29-
public class EventBuilder {
30+
public class EventBuilder implements AttributeBuilder {
3031
private long observedTsMillis;
3132
private String name;
3233
private String classScope;
@@ -86,24 +87,28 @@ public EventBuilder setSeverity(String severity) {
8687
}
8788

8889
/** Additional attribute to be attached to this {@link Event}. */
90+
@Override
8991
public EventBuilder setAttribute(String key, String value) {
9092
attributes.put(key, value);
9193
return this;
9294
}
9395

9496
/** Additional attribute to be attached to this {@link Event}. */
97+
@Override
9598
public EventBuilder setAttribute(String key, long value) {
9699
attributes.put(key, value);
97100
return this;
98101
}
99102

100103
/** Additional attribute to be attached to this {@link Event}. */
104+
@Override
101105
public EventBuilder setAttribute(String key, double value) {
102106
attributes.put(key, value);
103107
return this;
104108
}
105109

106110
/** Additional attribute to be attached to this {@link Event}. */
111+
@Override
107112
public EventBuilder setAttribute(String key, boolean value) {
108113
attributes.put(key, value);
109114
return this;

flink-metrics/flink-metrics-core/src/main/java/org/apache/flink/traces/SpanBuilder.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.flink.traces;
2020

21+
import org.apache.flink.AttributeBuilder;
2122
import org.apache.flink.annotation.Experimental;
2223

2324
import java.util.Collections;
@@ -26,7 +27,7 @@
2627

2728
/** Builder used to construct {@link Span}. See {@link Span#builder(Class, String)}. */
2829
@Experimental
29-
public class SpanBuilder {
30+
public class SpanBuilder implements AttributeBuilder {
3031
private final HashMap<String, Object> attributes = new HashMap<>();
3132
private final Class<?> classScope;
3233
private final String name;
@@ -89,23 +90,33 @@ public SpanBuilder setEndTsMillis(long endTsMillis) {
8990
}
9091

9192
/** Additional attribute to be attached to this {@link Span}. */
93+
@Override
9294
public SpanBuilder setAttribute(String key, String value) {
9395
attributes.put(key, value);
9496
return this;
9597
}
9698

9799
/** Additional attribute to be attached to this {@link Span}. */
100+
@Override
98101
public SpanBuilder setAttribute(String key, long value) {
99102
attributes.put(key, value);
100103
return this;
101104
}
102105

103106
/** Additional attribute to be attached to this {@link Span}. */
107+
@Override
104108
public SpanBuilder setAttribute(String key, double value) {
105109
attributes.put(key, value);
106110
return this;
107111
}
108112

113+
/** Additional attribute to be attached to this {@link Span}. */
114+
@Override
115+
public SpanBuilder setAttribute(String key, boolean value) {
116+
attributes.put(key, value);
117+
return this;
118+
}
119+
109120
public String getName() {
110121
return name;
111122
}

0 commit comments

Comments
 (0)